PartPicker: Multipicker als separate popupklasse
[kivitendo-erp.git] / js / kivi.Part.js
1 namespace('kivi.Part', function(ns) {
2   'use strict';
3
4   ns.open_history_popup = function() {
5     var id = $("#part_id").val();
6     kivi.popup_dialog({
7       url:    'controller.pl?action=Part/history&part.id=' + id,
8       dialog: { title: kivi.t8('History') },
9     });
10   }
11
12   ns.save = function() {
13     var data = $('#ic').serializeArray();
14     data.push({ name: 'action', value: 'Part/save' });
15
16     $.post("controller.pl", data, kivi.eval_json_result);
17   };
18
19   ns.use_as_new = function() {
20     var oldid = $("#part_id").val();
21     $('#ic').attr('action', 'controller.pl?action=Part/use_as_new&old_id=' + oldid);
22     $('#ic').submit();
23   };
24
25   ns.delete = function() {
26     var data = $('#ic').serializeArray();
27     data.push({ name: 'action', value: 'Part/delete' });
28
29     $.post("controller.pl", data, kivi.eval_json_result);
30   };
31
32   ns.reformat_number = function(event) {
33     $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
34   };
35
36   ns.set_tab_active_by_index = function (index) {
37     $("#ic_tabs").tabs({active: index})
38   };
39
40   ns.set_tab_active_by_name= function (name) {
41     var index = $('#ic_tabs a[href=#' + name + ']').parent().index();
42     ns.set_tab_active_by_index(index);
43   };
44
45   ns.reorder_items = function(order_by) {
46     var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
47     var part_type = $("#part_part_type").val();
48
49     var data;
50     if (part_type === 'assortment') {
51       $('#assortment thead a img').remove();
52       data = $('#assortment :input').serializeArray();
53     } else if ( part_type === 'assembly') {
54       $('#assembly thead a img').remove();
55       data = $('#assembly :input').serializeArray();
56     }
57
58     var src;
59     if (dir == "1") {
60       dir = "0";
61       src = "image/up.png";
62     } else {
63       dir = "1";
64       src = "image/down.png";
65     }
66
67     $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');
68
69     data.push({ name: 'action',    value: 'Part/reorder_items' },
70               { name: 'order_by',  value: order_by             },
71               { name: 'part_type', value: part_type            },
72               { name: 'sort_dir',  value: dir                  });
73
74     $.post("controller.pl", data, kivi.eval_json_result);
75   };
76
77   ns.assortment_recalc = function() {
78     var data = $('#assortment :input').serializeArray();
79     data.push({ name: 'action', value: 'Part/update_item_totals' },
80               { name: 'part_type', value: 'assortment'                   });
81
82     $.post("controller.pl", data, kivi.eval_json_result);
83   };
84
85   ns.assembly_recalc = function() {
86     var data = $('#assembly :input').serializeArray();
87     data.push( { name: 'action',    value: 'Part/update_item_totals' },
88                { name: 'part_type', value: 'assembly'                        });
89
90     $.post("controller.pl", data, kivi.eval_json_result);
91   };
92
93   ns.set_assortment_sellprice = function() {
94     $("#part_sellprice_as_number").val($("#items_sellprice_sum").html());
95     // ns.set_tab_active_by_name('basic_data');
96     // $("#part_sellprice_as_number").focus();
97   };
98
99   ns.set_assortment_lsg_sellprice = function() {
100     $("#items_lsg_sellprice_sum_basic").closest('td').find('input').val($("#items_lsg_sellprice_sum").html());
101   };
102
103   ns.set_assortment_douglas_sellprice = function() {
104     $("#items_douglas_sellprice_sum_basic").closest('td').find('input').val($("#items_douglas_sellprice_sum").html());
105   };
106
107   ns.set_assortment_lastcost = function() {
108     $("#part_lastcost_as_number").val($("#items_lastcost_sum").html());
109     // ns.set_tab_active_by_name('basic_data');
110     // $("#part_lastcost_as_number").focus();
111   };
112
113   ns.set_assembly_sellprice = function() {
114     $("#part_sellprice_as_number").val($("#items_sellprice_sum").html());
115     // ns.set_tab_active_by_name('basic_data');
116     // $("#part_sellprice_as_number").focus();
117   };
118
119   ns.renumber_positions = function() {
120     var part_type = $("#part_part_type").val();
121     var rows;
122     if (part_type === 'assortment') {
123       rows = $('.assortment_item_row [name="position"]');
124     } else if ( part_type === 'assembly') {
125       rows = $('.assembly_item_row [name="position"]');
126     }
127     $(rows).each(function(idx, elt) {
128       $(elt).html(idx+1);
129       var row = $(elt).closest('tr');
130       if ( idx % 2 === 0 ) {
131         if ( row.hasClass('listrow1') ) {
132           row.removeClass('listrow1');
133           row.addClass('listrow0');
134         }
135       } else {
136         if ( row.hasClass('listrow0') ) {
137           row.removeClass('listrow0');
138           row.addClass('listrow1');
139         }
140       }
141     });
142   };
143
144   ns.delete_item_row = function(clicked) {
145     var row = $(clicked).closest('tr');
146     $(row).remove();
147     var part_type = $("#part_part_type").val();
148     ns.renumber_positions();
149     if (part_type === 'assortment') {
150       ns.assortment_recalc();
151     } else if ( part_type === 'assembly') {
152       ns.assembly_recalc();
153     }
154   };
155
156   ns.add_assortment_item = function() {
157     if ($('#add_assortment_item_id').val() === '') return;
158
159     $('#row_table_id thead a img').remove();
160
161     var data = $('#assortment :input').serializeArray();
162     data.push({ name: 'action', value: 'Part/add_assortment_item' },
163               { name: 'part.id', value: $('#part_id').val()       },
164               { name: 'part.part_type', value: 'assortment'       });
165
166     $.post("controller.pl", data, kivi.eval_json_result);
167   };
168
169   ns.add_assembly_item = function() {
170     if ($('#add_assembly_item_id').val() === '') return;
171
172     var data = $('#assembly :input').serializeArray();
173     data.push({ name: 'action', value: 'Part/add_assembly_item' },
174               { name: 'part.id', value: $("#part_id").val()     },
175               { name: 'part.part_type', value: 'assortment'     });
176
177     $.post("controller.pl", data, kivi.eval_json_result);
178   };
179
180   ns.set_multi_assembly_items = function(data) {
181     data.push({ name: 'part.id',        value: $('#part_id').val() });
182     data.push({ name: 'part.part_type', value: $('#part_part_type').val() });
183     $.post("controller.pl?action=Part/add_multi_assembly_items", data, kivi.eval_json_result);
184   }
185
186   ns.set_multi_assortment_items = function(data) {
187     data.push({ name: 'part.id', value: $('#part_id').val() });
188     data.push({ name: 'part.part_type', value: $('#part_part_type').val() });
189     $.post("controller.pl?action=Part/add_multi_assortment_items", data, kivi.eval_json_result);
190   }
191
192   ns.close_picker_dialogs = function() {
193     $('.part_autocomplete').each(function(_, e) {
194       var picker = $(e).data('part_picker');
195       if (picker) picker.close_dialog();
196     });
197   }
198
199   ns.redisplay_items = function(data) {
200     var old_rows;
201     var part_type = $("#part_part_type").val();
202     if (part_type === 'assortment') {
203       old_rows = $('.assortment_item_row').detach();
204     } else if ( part_type === 'assembly') {
205       old_rows = $('.assembly_item_row').detach();
206     }
207     var new_rows = [];
208     $(data).each(function(idx, elt) {
209       new_rows.push(old_rows[elt.old_pos - 1]);
210     });
211     if (part_type === 'assortment') {
212       $(new_rows).appendTo($('#assortment_items'));
213     } else if ( part_type === 'assembly') {
214       $(new_rows).appendTo($('#assembly_items'));
215     }
216     ns.renumber_positions();
217   };
218
219   ns.focus_last_assortment_input = function () {
220     $("#assortment_items tr:last").find('input[type=text]').filter(':visible:first').focus();
221   };
222
223   ns.focus_last_assembly_input = function () {
224     $("#assembly_rows tr:last").find('input[type=text]').filter(':visible:first').focus();
225   };
226
227   // makemodel
228   ns.makemodel_renumber_positions = function() {
229     $('.makemodel_row [name="position"]').each(function(idx, elt) {
230       $(elt).html(idx+1);
231     });
232   };
233
234   ns.delete_makemodel_row = function(clicked) {
235     var row = $(clicked).closest('tr');
236     $(row).remove();
237
238     ns.makemodel_renumber_positions();
239   };
240
241   ns.add_makemodel_row = function() {
242     if ($('#add_makemodelid').val() === '') return;
243
244     var data = $('#makemodel_table :input').serializeArray();
245     data.push({ name: 'action', value: 'Part/add_makemodel_row' });
246
247     $.post("controller.pl", data, kivi.eval_json_result);
248   };
249
250   ns.focus_last_makemodel_input = function () {
251     $("#makemodel_rows tr:last").find('input[type=text]').filter(':visible:first').focus();
252   };
253
254   ns.reload_bin_selection = function() {
255     $.post("controller.pl", { action: 'Part/warehouse_changed', warehouse_id: function(){ return $('#part_warehouse_id').val() } },   kivi.eval_json_result);
256   }
257
258   var KEY = {
259     TAB:       9,
260     ENTER:     13,
261     SHIFT:     16,
262     CTRL:      17,
263     ALT:       18,
264     ESCAPE:    27,
265     PAGE_UP:   33,
266     PAGE_DOWN: 34,
267     LEFT:      37,
268     UP:        38,
269     RIGHT:     39,
270     DOWN:      40,
271   };
272
273   ns.Picker = function($real, options) {
274     var self = this;
275     this.o = $.extend({
276       limit: 20,
277       delay: 50,
278       action: {
279         on_enter_match_none: function(){ },
280         on_enter_match_one:  function(){ $('#update_button').click(); },
281         on_enter_match_many: function(){ self.open_dialog(); }
282       }
283     }, $real.data('part-picker-data'), options);
284     this.$real              = $real;
285     this.real_id            = $real.attr('id');
286     this.last_real          = $real.val();
287     this.$dummy             = $($real.siblings()[0]);
288     this.autocomplete_open  = false;
289     this.state              = this.STATES.PICKED;
290     this.last_dummy         = this.$dummy.val();
291     this.timer              = undefined;
292     this.dialog             = undefined;
293
294     this.init();
295   };
296
297   ns.Picker.prototype = {
298     CLASSES: {
299       PICKED:       'partpicker-picked',
300       UNDEFINED:    'partpicker-undefined',
301     },
302     ajax_data: function(term) {
303       var data = {
304         'filter.all:substr:multi::ilike': term,
305         'filter.obsolete': 0,
306         current:  this.$real.val(),
307       };
308
309       if (this.o.part_type)
310         data['filter.part_type'] = this.o.part_type.split(',');
311
312       if (this.o.classification_id)
313         data['filter.classification_id'] = this.o.classification_id.split(',');
314
315       if (this.o.unit)
316         data['filter.unit'] = this.o.unit.split(',');
317
318       if (this.o.convertible_unit)
319         data['filter.unit_obj.convertible_to'] = this.o.convertible_unit;
320
321       return data;
322     },
323     set_item: function(item) {
324       var self = this;
325       if (item.id) {
326         this.$real.val(item.id);
327         // autocomplete ui has name, use the value for ajax items, which contains displayable_name
328         this.$dummy.val(item.name ? item.name : item.value);
329       } else {
330         this.$real.val('');
331         this.$dummy.val('');
332       }
333       this.state      = this.STATES.PICKED;
334       this.last_real  = this.$real.val();
335       this.last_dummy = this.$dummy.val();
336       this.$real.trigger('change');
337
338       if (this.o.fat_set_item && item.id) {
339         $.ajax({
340           url: 'controller.pl?action=Part/show.json',
341           data: { 'part.id': item.id },
342           success: function(rsp) {
343             self.$real.trigger('set_item:PartPicker', rsp);
344           },
345         });
346       } else {
347         this.$real.trigger('set_item:PartPicker', item);
348       }
349       this.annotate_state();
350     },
351     set_multi_items: function(data) {
352       this.run_action(this.o.action.set_multi_items, [ data ]);
353     },
354     make_defined_state: function() {
355       if (this.state == this.STATES.PICKED) {
356         this.annotate_state();
357         return true
358       } else if (this.state == this.STATES.UNDEFINED && this.$dummy.val() === '')
359         this.set_item({})
360       else {
361         this.set_item({ id: this.last_real, name: this.last_dummy })
362       }
363       this.annotate_state();
364     },
365     annotate_state: function() {
366       if (this.state == this.STATES.PICKED)
367         this.$dummy.removeClass(this.STATES.UNDEFINED).addClass(this.STATES.PICKED);
368       else if (this.state == this.STATES.UNDEFINED && this.$dummy.val() === '')
369         this.$dummy.removeClass(this.STATES.UNDEFINED).addClass(this.STATES.PICKED);
370       else {
371         this.$dummy.addClass(this.STATES.UNDEFINED).removeClass(this.STATES.PICKED);
372       }
373     },
374     handle_changed_text: function(callbacks) {
375       var self = this;
376       $.ajax({
377         url: 'controller.pl?action=Part/ajax_autocomplete',
378         dataType: "json",
379         data: $.extend( self.ajax_data(self.$dummy.val()), { prefer_exact: 1 } ),
380         success: function (data) {
381           if (data.length == 1) {
382             self.set_item(data[0]);
383             if (callbacks && callbacks.match_one) self.run_action(callbacks.match_one, [ data[0] ]);
384           } else if (data.length > 1) {
385             self.state = self.STATES.UNDEFINED;
386             if (callbacks && callbacks.match_many) self.run_action(callbacks.match_many, [ data ]);
387           } else {
388             self.state = self.STATES.UNDEFINED;
389             if (callbacks && callbacks.match_none) self.run_action(callbacks.match_none);
390           }
391           self.annotate_state();
392         }
393       });
394     },
395     /*  In case users are impatient and want to skip ahead:
396      *  Capture <enter> key events and check if it's a unique hit.
397      *  If it is, go ahead and assume it was selected. If it wasn't don't do
398      *  anything so that autocompletion kicks in.  For <tab> don't prevent
399      *  propagation. It would be nice to catch it, but javascript is too stupid
400      *  to fire a tab event later on, so we'd have to reimplement the "find
401      *  next active element in tabindex order and focus it".
402      */
403     /* note:
404      *  event.which does not contain tab events in keypressed in firefox but will report 0
405      *  chrome does not fire keypressed at all on tab or escape
406      */
407     handle_keydown: function(event) {
408       var self = this;
409       if (event.which == KEY.ENTER || event.which == KEY.TAB) {
410         // if string is empty assume they want to delete
411         if (self.$dummy.val() === '') {
412           self.set_item({});
413           return true;
414         } else if (self.state == self.STATES.PICKED) {
415           return true;
416         }
417         if (event.which == KEY.TAB) {
418           event.preventDefault();
419           self.handle_changed_text();
420         }
421         if (event.which == KEY.ENTER) {
422           self.handle_changed_text({
423             match_one:  self.o.action.on_enter_match_one,
424             match_many: self.o.action.on_enter_match_many
425           });
426           return false;
427         }
428       } else if (event.which == KEY.DOWN && !self.autocomplete_open) {
429         var old_options = self.$dummy.autocomplete('option');
430         self.$dummy.autocomplete('option', 'minLength', 0);
431         self.$dummy.autocomplete('search', self.$dummy.val());
432         self.$dummy.autocomplete('option', 'minLength', old_options.minLength);
433       } else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) {
434         self.state = self.STATES.UNDEFINED;
435       }
436     },
437     open_dialog: function() {
438       if (this.o.multiple) {
439         this.dialog = new ns.PickerMultiPopup(this);
440       } else {
441         this.dialog = new ns.PickerPopup(this);
442       }
443     },
444     close_dialog: function() {
445       this.dialog.close_dialog();
446       this.dialog = undefined;
447     },
448     init: function() {
449       var self = this;
450       this.$dummy.autocomplete({
451         source: function(req, rsp) {
452           $.ajax($.extend(self.o, {
453             url:      'controller.pl?action=Part/ajax_autocomplete',
454             dataType: "json",
455             data:     self.ajax_data(req.term),
456             success:  function (data){ rsp(data) }
457           }));
458         },
459         select: function(event, ui) {
460           self.set_item(ui.item);
461         },
462         search: function(event, ui) {
463           if ((event.which == KEY.SHIFT) || (event.which == KEY.CTRL) || (event.which == KEY.ALT))
464             event.preventDefault();
465         },
466         open: function() {
467           self.autocomplete_open = true;
468         },
469         close: function() {
470           self.autocomplete_open = false;
471         }
472       });
473       this.$dummy.keydown(function(event){ self.handle_keydown(event) });
474       this.$dummy.on('paste', function(){
475         setTimeout(function() {
476           self.handle_changed_text();
477         }, 1);
478       });
479       this.$dummy.blur(function(){
480         window.clearTimeout(self.timer);
481         self.timer = window.setTimeout(function() { self.annotate_state() }, 100);
482       });
483
484       var popup_button = $('<span>').addClass('ppp_popup_button');
485       this.$dummy.after(popup_button);
486       popup_button.click(function() { self.open_dialog() });
487     },
488     run_action: function(code, args) {
489       if (typeof code === 'function')
490         code.apply(this, args)
491       else
492         kivi.run(code, args);
493     }
494   };
495   ns.Picker.prototype.STATES = {
496     PICKED:    ns.Picker.prototype.CLASSES.PICKED,
497     UNDEFINED: ns.Picker.prototype.CLASSES.UNDEFINED
498   };
499
500   ns.PickerPopup = function(pp) {
501     this.timer = undefined;
502     this.pp    = pp;
503     this.open_dialog();
504   };
505
506   ns.PickerPopup.prototype = {
507     open_dialog: function() {
508       var self = this;
509       kivi.popup_dialog({
510         url: 'controller.pl?action=Part/part_picker_search',
511         data: self.pp.ajax_data(this.pp.$dummy.val()),
512         id: 'part_selection',
513         dialog: {
514           title: kivi.t8('Part picker'),
515           width: 800,
516           height: 800,
517         },
518         load: function() { self.init_search(); }
519       });
520       window.clearTimeout(this.timer);
521       return true;
522     },
523     init_search: function() {
524       var self = this;
525       $('#part_picker_filter').keypress(function(e) { self.result_timer(e) }).focus();
526       $('#no_paginate').change(function() { self.update_results() });
527       this.update_results();
528     },
529     update_results: function() {
530       var self = this;
531       $.ajax({
532         url: 'controller.pl?action=Part/part_picker_result',
533         data: $.extend({
534           no_paginate: $('#no_paginate').prop('checked') ? 1 : 0,
535         }, self.pp.ajax_data(function(){
536           var val = $('#part_picker_filter').val();
537           return val === undefined ? '' : val
538         })),
539         success: function(data){
540           $('#part_picker_result').html(data);
541           self.init_results();
542         }
543       });
544     },
545     init_results: function() {
546       var self = this;
547       $('div.part_picker_part').each(function(){
548         $(this).click(function(){
549           self.pp.set_item({
550             id:   $(this).children('input.part_picker_id').val(),
551             name: $(this).children('input.part_picker_description').val(),
552             classification_id: $(this).children('input.part_picker_classification_id').val(),
553             unit: $(this).children('input.part_picker_unit').val(),
554             partnumber:  $(this).children('input.part_picker_partnumber').val(),
555             description: $(this).children('input.part_picker_description').val(),
556           });
557           self.close_dialog();
558           self.pp.$dummy.focus();
559           return true;
560         });
561       });
562       $('#part_selection').keydown(function(e){
563          if (e.which == KEY.ESCAPE) {
564            self.close_dialog();
565            self.pp.$dummy.focus();
566          }
567       });
568     },
569     result_timer: function(event) {
570       var self = this;
571       if (!$('no_paginate').prop('checked')) {
572         if (event.keyCode == KEY.PAGE_UP) {
573           $('#part_picker_result a.paginate-prev').click();
574           return;
575         }
576         if (event.keyCode == KEY.PAGE_DOWN) {
577           $('#part_picker_result a.paginate-next').click();
578           return;
579         }
580       }
581       window.clearTimeout(this.timer);
582       if (event.which == KEY.ENTER) {
583         self.update_results();
584       } else {
585         this.timer = window.setTimeout(function() { self.update_results() }, 100);
586       }
587     },
588     close_dialog: function() {
589       $('#part_selection').dialog('close');
590     }
591   };
592
593   ns.PickerMultiPopup = function(pp) {
594     this.pp       = pp;
595     this.callback = 'Part/add_multi_' + this.pp.o.part_type + '_items';
596     this.open_dialog();
597   };
598
599   ns.PickerMultiPopup.prototype = {
600     open_dialog: function() {
601       var self = this;
602       $('#row_table_id thead a img').remove();
603
604       kivi.popup_dialog({
605         url: 'controller.pl?action=Part/show_multi_items_dialog',
606         data: $.extend({
607           real_id: self.pp.real_id,
608         }, self.pp.ajax_data(this.pp.$dummy.val())),
609         id: 'jq_multi_items_dialog',
610         dialog: {
611           title: kivi.t8('Add multiple items'),
612           width:  800,
613           height: 800
614         },
615         load: function() {
616           self.init_search();
617         }
618       });
619       return true;
620     },
621     init_search: function() {
622       var self = this;
623       $('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) {
624         if(event.which == KEY.ENTER) {
625           event.preventDefault();
626           self.update_results();
627           return false;
628         }
629       });
630
631       $('#multi_items_filter_all_substr_multi_ilike').focus();
632       $('#multi_items_filter_button').click(function(){ self.update_results() });
633       $('#multi_items_filter_reset').click(function(){ $("#multi_items_form").resetForm() });
634       $('#continue_button').click(function(){ self.add_multi_items() });
635     },
636     update_results: function() {
637       var self = this;
638       var data = $('#multi_items_form').serializeArray();
639       data.push({ name: 'type', value: self.pp.type });
640       $.ajax({
641         url: 'controller.pl?action=Part/multi_items_update_result',
642         data: data,
643         method: 'post',
644         success: function(data){
645           $('#multi_items_result').html(data);
646           self.init_results();
647           self.enable_continue();
648         }
649       });
650     },
651     set_qty_to_one: function(clicked) {
652       if ($(clicked).val() === '') {
653         $(clicked).val(kivi.format_amount(1.00, -2));
654       }
655       $(clicked).select();
656     },
657     init_results: function() {
658       var self = this;
659       $('#multi_items_all_qty').change(function(event){
660         $('.multi_items_qty').val($(event.target).val());
661       });
662       $('.multi_items_qty').click(function(){ self.set_qty_to_one(this) });
663     },
664     result_timer: function(event) {
665     },
666     close_dialog: function() {
667       $('#jq_multi_items_dialog').dialog('close');
668     },
669     disable_continue: function() {
670       $('#multi_items_result input').off("keydown");
671       $('#continue_button').prop('disabled', true);
672     },
673     enable_continue: function() {
674       var self = this;
675       $('#multi_items_result input').keydown(function(event) {
676         if(event.keyCode == KEY.ENTER) {
677           event.preventDefault();
678           self.add_multi_items();
679           return false;
680         }
681       });
682       $('#continue_button').prop('disabled', false);
683     },
684     add_multi_items: function() {
685       // rows at all
686       var n_rows = $('.multi_items_qty').length;
687       if ( n_rows === 0) { return; }
688
689       // filled rows
690       n_rows = $('.multi_items_qty').filter(function() {
691         return $(this).val().length > 0;
692       }).length;
693       if (n_rows === 0) { return; }
694
695       this.disable_continue();
696
697       var data = $('#multi_items_form').serializeArray();
698       this.pp.set_multi_items(data);
699     }
700   };
701
702   ns.reinit_widgets = function() {
703     kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
704       if (!$(elt).data('part_picker'))
705         $(elt).data('part_picker', new kivi.Part.Picker($(elt)));
706     });
707   }
708
709   ns.init = function() {
710     ns.reinit_widgets();
711   }
712
713   $(function(){
714     $('#ic').on('focusout', '.reformat_number', function(event) {
715        ns.reformat_number(event);
716     });
717
718     $('.add_makemodel_input').keydown(function(event) {
719       if(event.keyCode == 13) {
720         event.preventDefault();
721         ns.add_makemodel_row();
722         return false;
723       }
724     });
725
726     $('#part_warehouse_id').change(kivi.Part.reload_bin_selection);
727
728     ns.init();
729   });
730 });