kivi.Part.js: clear Methode für Partpicker
[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     clear: function() {
498       this.set_item({});
499     }
500   };
501   ns.Picker.prototype.STATES = {
502     PICKED:    ns.Picker.prototype.CLASSES.PICKED,
503     UNDEFINED: ns.Picker.prototype.CLASSES.UNDEFINED
504   };
505
506   ns.PickerPopup = function(pp) {
507     this.timer = undefined;
508     this.pp    = pp;
509     this.open_dialog();
510   };
511
512   ns.PickerPopup.prototype = {
513     open_dialog: function() {
514       var self = this;
515       kivi.popup_dialog({
516         url: 'controller.pl?action=Part/part_picker_search',
517         data: self.pp.ajax_data(this.pp.$dummy.val()),
518         id: 'part_selection',
519         dialog: {
520           title: kivi.t8('Part picker'),
521           width: 800,
522           height: 800,
523         },
524         load: function() { self.init_search(); }
525       });
526       window.clearTimeout(this.timer);
527       return true;
528     },
529     init_search: function() {
530       var self = this;
531       $('#part_picker_filter').keypress(function(e) { self.result_timer(e) }).focus();
532       $('#no_paginate').change(function() { self.update_results() });
533       this.update_results();
534     },
535     update_results: function() {
536       var self = this;
537       $.ajax({
538         url: 'controller.pl?action=Part/part_picker_result',
539         data: $.extend({
540           no_paginate: $('#no_paginate').prop('checked') ? 1 : 0,
541         }, self.pp.ajax_data(function(){
542           var val = $('#part_picker_filter').val();
543           return val === undefined ? '' : val
544         })),
545         success: function(data){
546           $('#part_picker_result').html(data);
547           self.init_results();
548         }
549       });
550     },
551     init_results: function() {
552       var self = this;
553       $('div.part_picker_part').each(function(){
554         $(this).click(function(){
555           self.pp.set_item({
556             id:   $(this).children('input.part_picker_id').val(),
557             name: $(this).children('input.part_picker_description').val(),
558             classification_id: $(this).children('input.part_picker_classification_id').val(),
559             unit: $(this).children('input.part_picker_unit').val(),
560             partnumber:  $(this).children('input.part_picker_partnumber').val(),
561             description: $(this).children('input.part_picker_description').val(),
562           });
563           self.close_dialog();
564           self.pp.$dummy.focus();
565           return true;
566         });
567       });
568       $('#part_selection').keydown(function(e){
569          if (e.which == KEY.ESCAPE) {
570            self.close_dialog();
571            self.pp.$dummy.focus();
572          }
573       });
574     },
575     result_timer: function(event) {
576       var self = this;
577       if (!$('no_paginate').prop('checked')) {
578         if (event.keyCode == KEY.PAGE_UP) {
579           $('#part_picker_result a.paginate-prev').click();
580           return;
581         }
582         if (event.keyCode == KEY.PAGE_DOWN) {
583           $('#part_picker_result a.paginate-next').click();
584           return;
585         }
586       }
587       window.clearTimeout(this.timer);
588       if (event.which == KEY.ENTER) {
589         self.update_results();
590       } else {
591         this.timer = window.setTimeout(function() { self.update_results() }, 100);
592       }
593     },
594     close_dialog: function() {
595       $('#part_selection').dialog('close');
596     }
597   };
598
599   ns.PickerMultiPopup = function(pp) {
600     this.pp       = pp;
601     this.callback = 'Part/add_multi_' + this.pp.o.part_type + '_items';
602     this.open_dialog();
603   };
604
605   ns.PickerMultiPopup.prototype = {
606     open_dialog: function() {
607       var self = this;
608       $('#row_table_id thead a img').remove();
609
610       kivi.popup_dialog({
611         url: 'controller.pl?action=Part/show_multi_items_dialog',
612         data: $.extend({
613           real_id: self.pp.real_id,
614         }, self.pp.ajax_data(this.pp.$dummy.val())),
615         id: 'jq_multi_items_dialog',
616         dialog: {
617           title: kivi.t8('Add multiple items'),
618           width:  800,
619           height: 800
620         },
621         load: function() {
622           self.init_search();
623         }
624       });
625       return true;
626     },
627     init_search: function() {
628       var self = this;
629       $('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) {
630         if(event.which == KEY.ENTER) {
631           event.preventDefault();
632           self.update_results();
633           return false;
634         }
635       });
636
637       $('#multi_items_filter_all_substr_multi_ilike').focus();
638       $('#multi_items_filter_button').click(function(){ self.update_results() });
639       $('#multi_items_filter_reset').click(function(){ $("#multi_items_form").resetForm() });
640       $('#continue_button').click(function(){ self.add_multi_items() });
641     },
642     update_results: function() {
643       var self = this;
644       var data = $('#multi_items_form').serializeArray();
645       data.push({ name: 'type', value: self.pp.type });
646       $.ajax({
647         url: 'controller.pl?action=Part/multi_items_update_result',
648         data: data,
649         method: 'post',
650         success: function(data){
651           $('#multi_items_result').html(data);
652           self.init_results();
653           self.enable_continue();
654         }
655       });
656     },
657     set_qty_to_one: function(clicked) {
658       if ($(clicked).val() === '') {
659         $(clicked).val(kivi.format_amount(1.00, -2));
660       }
661       $(clicked).select();
662     },
663     init_results: function() {
664       var self = this;
665       $('#multi_items_all_qty').change(function(event){
666         $('.multi_items_qty').val($(event.target).val());
667       });
668       $('.multi_items_qty').click(function(){ self.set_qty_to_one(this) });
669     },
670     result_timer: function(event) {
671     },
672     close_dialog: function() {
673       $('#jq_multi_items_dialog').dialog('close');
674     },
675     disable_continue: function() {
676       $('#multi_items_result input').off("keydown");
677       $('#continue_button').prop('disabled', true);
678     },
679     enable_continue: function() {
680       var self = this;
681       $('#multi_items_result input').keydown(function(event) {
682         if(event.keyCode == KEY.ENTER) {
683           event.preventDefault();
684           self.add_multi_items();
685           return false;
686         }
687       });
688       $('#continue_button').prop('disabled', false);
689     },
690     add_multi_items: function() {
691       // rows at all
692       var n_rows = $('.multi_items_qty').length;
693       if ( n_rows === 0) { return; }
694
695       // filled rows
696       n_rows = $('.multi_items_qty').filter(function() {
697         return $(this).val().length > 0;
698       }).length;
699       if (n_rows === 0) { return; }
700
701       this.disable_continue();
702
703       var data = $('#multi_items_form').serializeArray();
704       this.pp.set_multi_items(data);
705     }
706   };
707
708   ns.reinit_widgets = function() {
709     kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
710       if (!$(elt).data('part_picker'))
711         $(elt).data('part_picker', new kivi.Part.Picker($(elt)));
712     });
713   }
714
715   ns.init = function() {
716     ns.reinit_widgets();
717   }
718
719   $(function(){
720     $('#ic').on('focusout', '.reformat_number', function(event) {
721        ns.reformat_number(event);
722     });
723
724     $('.add_makemodel_input').keydown(function(event) {
725       if(event.keyCode == 13) {
726         event.preventDefault();
727         ns.add_makemodel_row();
728         return false;
729       }
730     });
731
732     $('#part_warehouse_id').change(kivi.Part.reload_bin_selection);
733
734     ns.init();
735   });
736 });