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