+ ns.PickerPopup = function(pp) {
+ this.timer = undefined;
+ this.pp = pp;
+
+ this.open_dialog = function() {
+ var self = this;
+ kivi.popup_dialog({
+ url: 'controller.pl?action=Part/part_picker_search',
+ data: $.extend({
+ real_id: self.pp.real_id,
+ }, self.pp.ajax_data(this.pp.dummy.val())),
+ id: 'part_selection',
+ dialog: {
+ title: kivi.t8('Part picker'),
+ width: 800,
+ height: 800,
+ },
+ load: function() { self.init_search(); }
+ });
+ window.clearTimeout(this.timer);
+ return true;
+ };
+
+ this.init_search = function() {
+ var self = this;
+ $('#part_picker_filter').keypress(function(e) { self.result_timer(e) }).focus();
+ $('#no_paginate').change(function() { self.update_results() });
+ this.update_results();
+ }
+
+ this.update_results = function() {
+ var self = this;
+ $.ajax({
+ url: 'controller.pl?action=Part/part_picker_result',
+ data: $.extend({
+ 'real_id': self.pp.real.val(),
+ }, self.pp.ajax_data(function(){
+ var val = $('#part_picker_filter').val();
+ return val === undefined ? '' : val
+ })),
+ success: function(data){
+ $('#part_picker_result').html(data);
+ self.init_results();
+ }
+ });
+ };
+
+ this.init_results = function() {
+ var self = this;
+ $('div.part_picker_part').each(function(){
+ $(this).click(function(){
+ self.pp.set_item({
+ id: $(this).children('input.part_picker_id').val(),
+ name: $(this).children('input.part_picker_description').val(),
+ classification_id: $(this).children('input.part_picker_classification_id').val(),
+ unit: $(this).children('input.part_picker_unit').val(),
+ partnumber: $(this).children('input.part_picker_partnumber').val(),
+ description: $(this).children('input.part_picker_description').val(),
+ });
+ self.close_popup();
+ self.pp.dummy.focus();
+ return true;
+ });
+ });
+ $('#part_selection').keydown(function(e){
+ if (e.which == KEY.ESCAPE) {
+ self.close_popup();
+ self.pp.dummy.focus();
+ }
+ });
+ }
+
+ this.result_timer = function(event) {
+ var self = this;
+ if (!$('no_paginate').prop('checked')) {
+ if (event.keyCode == KEY.PAGE_UP) {
+ $('#part_picker_result a.paginate-prev').click();
+ return;
+ }
+ if (event.keyCode == KEY.PAGE_DOWN) {
+ $('#part_picker_result a.paginate-next').click();
+ return;
+ }
+ }
+ window.clearTimeout(this.timer);
+ this.timer = window.setTimeout(function() { self.update_results() }, 100);
+ };
+
+ this.close_popup = function() {
+ $('#part_selection').dialog('close');
+ };
+
+ this.open_dialog();
+ }
+