kivi.Part.js: im PICKED state auf enter/tab den commit hook auslösen
[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           if (self.o.action.on_enter_match_one) {
416             self.run_action(self.o.action.on_enter_match_one);
417           }
418           return true;
419         }
420         if (event.which == KEY.TAB) {
421           event.preventDefault();
422           self.handle_changed_text();
423         }
424         if (event.which == KEY.ENTER) {
425           self.handle_changed_text({
426             match_one:  self.o.action.on_enter_match_one,
427             match_many: self.o.action.on_enter_match_many
428           });
429           return false;
430         }
431       } else if (event.which == KEY.DOWN && !self.autocomplete_open) {
432         var old_options = self.$dummy.autocomplete('option');
433         self.$dummy.autocomplete('option', 'minLength', 0);
434         self.$dummy.autocomplete('search', self.$dummy.val());
435         self.$dummy.autocomplete('option', 'minLength', old_options.minLength);
436       } else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) {
437         self.state = self.STATES.UNDEFINED;
438       }
439     },
440     open_dialog: function() {
441       if (this.o.multiple) {
442         this.dialog = new ns.PickerMultiPopup(this);
443       } else {
444         this.dialog = new ns.PickerPopup(this);
445       }
446     },
447     close_dialog: function() {
448       this.dialog.close_dialog();
449       this.dialog = undefined;
450     },
451     init: function() {
452       var self = this;
453       this.$dummy.autocomplete({
454         source: function(req, rsp) {
455           $.ajax($.extend(self.o, {
456             url:      'controller.pl?action=Part/ajax_autocomplete',
457             dataType: "json",
458             data:     self.ajax_data(req.term),
459             success:  function (data){ rsp(data) }
460           }));
461         },
462         select: function(event, ui) {
463           self.set_item(ui.item);
464         },
465         search: function(event, ui) {
466           if ((event.which == KEY.SHIFT) || (event.which == KEY.CTRL) || (event.which == KEY.ALT))
467             event.preventDefault();
468         },
469         open: function() {
470           self.autocomplete_open = true;
471         },
472         close: function() {
473           self.autocomplete_open = false;
474         }
475       });
476       this.$dummy.keydown(function(event){ self.handle_keydown(event) });
477       this.$dummy.on('paste', function(){
478         setTimeout(function() {
479           self.handle_changed_text();
480         }, 1);
481       });
482       this.$dummy.blur(function(){
483         window.clearTimeout(self.timer);
484         self.timer = window.setTimeout(function() { self.annotate_state() }, 100);
485       });
486
487       var popup_button = $('<span>').addClass('ppp_popup_button');
488       this.$dummy.after(popup_button);
489       popup_button.click(function() { self.open_dialog() });
490     },
491     run_action: function(code, args) {
492       if (typeof code === 'function')
493         code.apply(this, args)
494       else
495         kivi.run(code, args);
496     }
497   };
498   ns.Picker.prototype.STATES = {
499     PICKED:    ns.Picker.prototype.CLASSES.PICKED,
500     UNDEFINED: ns.Picker.prototype.CLASSES.UNDEFINED
501   };
502
503   ns.PickerPopup = function(pp) {
504     this.timer = undefined;
505     this.pp    = pp;
506     this.open_dialog();
507   };
508
509   ns.PickerPopup.prototype = {
510     open_dialog: function() {
511       var self = this;
512       kivi.popup_dialog({
513         url: 'controller.pl?action=Part/part_picker_search',
514         data: self.pp.ajax_data(this.pp.$dummy.val()),
515         id: 'part_selection',
516         dialog: {
517           title: kivi.t8('Part picker'),
518           width: 800,
519           height: 800,
520         },
521         load: function() { self.init_search(); }
522       });
523       window.clearTimeout(this.timer);
524       return true;
525     },
526     init_search: function() {
527       var self = this;
528       $('#part_picker_filter').keypress(function(e) { self.result_timer(e) }).focus();
529       $('#no_paginate').change(function() { self.update_results() });
530       this.update_results();
531     },
532     update_results: function() {
533       var self = this;
534       $.ajax({
535         url: 'controller.pl?action=Part/part_picker_result',
536         data: $.extend({
537           no_paginate: $('#no_paginate').prop('checked') ? 1 : 0,
538         }, self.pp.ajax_data(function(){
539           var val = $('#part_picker_filter').val();
540           return val === undefined ? '' : val
541         })),
542         success: function(data){
543           $('#part_picker_result').html(data);
544           self.init_results();
545         }
546       });
547     },
548     init_results: function() {
549       var self = this;
550       $('div.part_picker_part').each(function(){
551         $(this).click(function(){
552           self.pp.set_item({
553             id:   $(this).children('input.part_picker_id').val(),
554             name: $(this).children('input.part_picker_description').val(),
555             classification_id: $(this).children('input.part_picker_classification_id').val(),
556             unit: $(this).children('input.part_picker_unit').val(),
557             partnumber:  $(this).children('input.part_picker_partnumber').val(),
558             description: $(this).children('input.part_picker_description').val(),
559           });
560           self.close_dialog();
561           self.pp.$dummy.focus();
562           return true;
563         });
564       });
565       $('#part_selection').keydown(function(e){
566          if (e.which == KEY.ESCAPE) {
567            self.close_dialog();
568            self.pp.$dummy.focus();
569          }
570       });
571     },
572     result_timer: function(event) {
573       var self = this;
574       if (!$('no_paginate').prop('checked')) {
575         if (event.keyCode == KEY.PAGE_UP) {
576           $('#part_picker_result a.paginate-prev').click();
577           return;
578         }
579         if (event.keyCode == KEY.PAGE_DOWN) {
580           $('#part_picker_result a.paginate-next').click();
581           return;
582         }
583       }
584       window.clearTimeout(this.timer);
585       if (event.which == KEY.ENTER) {
586         self.update_results();
587       } else {
588         this.timer = window.setTimeout(function() { self.update_results() }, 100);
589       }
590     },
591     close_dialog: function() {
592       $('#part_selection').dialog('close');
593     }
594   };
595
596   ns.PickerMultiPopup = function(pp) {
597     this.pp       = pp;
598     this.callback = 'Part/add_multi_' + this.pp.o.part_type + '_items';
599     this.open_dialog();
600   };
601
602   ns.PickerMultiPopup.prototype = {
603     open_dialog: function() {
604       var self = this;
605       $('#row_table_id thead a img').remove();
606
607       kivi.popup_dialog({
608         url: 'controller.pl?action=Part/show_multi_items_dialog',
609         data: $.extend({
610           real_id: self.pp.real_id,
611         }, self.pp.ajax_data(this.pp.$dummy.val())),
612         id: 'jq_multi_items_dialog',
613         dialog: {
614           title: kivi.t8('Add multiple items'),
615           width:  800,
616           height: 800
617         },
618         load: function() {
619           self.init_search();
620         }
621       });
622       return true;
623     },
624     init_search: function() {
625       var self = this;
626       $('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) {
627         if(event.which == KEY.ENTER) {
628           event.preventDefault();
629           self.update_results();
630           return false;
631         }
632       });
633
634       $('#multi_items_filter_all_substr_multi_ilike').focus();
635       $('#multi_items_filter_button').click(function(){ self.update_results() });
636       $('#multi_items_filter_reset').click(function(){ $("#multi_items_form").resetForm() });
637       $('#continue_button').click(function(){ self.add_multi_items() });
638     },
639     update_results: function() {
640       var self = this;
641       var data = $('#multi_items_form').serializeArray();
642       data.push({ name: 'type', value: self.pp.type });
643       $.ajax({
644         url: 'controller.pl?action=Part/multi_items_update_result',
645         data: data,
646         method: 'post',
647         success: function(data){
648           $('#multi_items_result').html(data);
649           self.init_results();
650           self.enable_continue();
651         }
652       });
653     },
654     set_qty_to_one: function(clicked) {
655       if ($(clicked).val() === '') {
656         $(clicked).val(kivi.format_amount(1.00, -2));
657       }
658       $(clicked).select();
659     },
660     init_results: function() {
661       var self = this;
662       $('#multi_items_all_qty').change(function(event){
663         $('.multi_items_qty').val($(event.target).val());
664       });
665       $('.multi_items_qty').click(function(){ self.set_qty_to_one(this) });
666     },
667     result_timer: function(event) {
668     },
669     close_dialog: function() {
670       $('#jq_multi_items_dialog').dialog('close');
671     },
672     disable_continue: function() {
673       $('#multi_items_result input').off("keydown");
674       $('#continue_button').prop('disabled', true);
675     },
676     enable_continue: function() {
677       var self = this;
678       $('#multi_items_result input').keydown(function(event) {
679         if(event.keyCode == KEY.ENTER) {
680           event.preventDefault();
681           self.add_multi_items();
682           return false;
683         }
684       });
685       $('#continue_button').prop('disabled', false);
686     },
687     add_multi_items: function() {
688       // rows at all
689       var n_rows = $('.multi_items_qty').length;
690       if ( n_rows === 0) { return; }
691
692       // filled rows
693       n_rows = $('.multi_items_qty').filter(function() {
694         return $(this).val().length > 0;
695       }).length;
696       if (n_rows === 0) { return; }
697
698       this.disable_continue();
699
700       var data = $('#multi_items_form').serializeArray();
701       this.pp.set_multi_items(data);
702     }
703   };
704
705   ns.reinit_widgets = function() {
706     kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
707       if (!$(elt).data('part_picker'))
708         $(elt).data('part_picker', new kivi.Part.Picker($(elt)));
709     });
710   }
711
712   ns.init = function() {
713     ns.reinit_widgets();
714   }
715
716   $(function(){
717     $('#ic').on('focusout', '.reformat_number', function(event) {
718        ns.reformat_number(event);
719     });
720
721     $('.add_makemodel_input').keydown(function(event) {
722       if(event.keyCode == 13) {
723         event.preventDefault();
724         ns.add_makemodel_row();
725         return false;
726       }
727     });
728
729     $('#part_warehouse_id').change(kivi.Part.reload_bin_selection);
730
731     ns.init();
732   });
733 });