SimpleSystemSetting: Umstellung von »Bankkonten«
[kivitendo-erp.git] / js / autocomplete_part.js
index cc9354a..cae7f01 100644 (file)
@@ -1,4 +1,6 @@
 namespace('kivi', function(k){
+  "use strict";
+
   k.PartPicker = function($real, options) {
     // short circuit in case someone double inits us
     if ($real.data("part_picker"))
@@ -12,6 +14,9 @@ namespace('kivi', function(k){
       RIGHT:  39,
       PAGE_UP: 33,
       PAGE_DOWN: 34,
+      SHIFT:     16,
+      CTRL:      17,
+      ALT:       18,
     };
     var CLASSES = {
       PICKED:       'partpicker-picked',
@@ -28,10 +33,11 @@ namespace('kivi', function(k){
       UNDEFINED: CLASSES.UNDEFINED
     }
     var real_id = $real.attr('id');
-    var $dummy  = $('#' + real_id + '_name');
-    var $type   = $('#' + real_id + '_type');
-    var $unit   = $('#' + real_id + '_unit');
-    var $convertible_unit = $('#' + real_id + '_convertible_unit');
+    var $dummy             = $('#' + real_id + '_name');
+    var $part_type         = $('#' + real_id + '_part_type');
+    var $classification_id = $('#' + real_id + '_classification_id');
+    var $unit              = $('#' + real_id + '_unit');
+    var $convertible_unit  = $('#' + real_id + '_convertible_unit');
     var state   = STATES.PICKED;
     var last_real = $real.val();
     var last_dummy = $dummy.val();
@@ -63,8 +69,11 @@ namespace('kivi', function(k){
         current:  $real.val(),
       };
 
-      if ($type && $type.val())
-        data['filter.type'] = $type.val().split(',');
+      if ($part_type && $part_type.val())
+        data['filter.part_type'] = $part_type.val().split(',');
+
+      if ($classification_id && $classification_id.val())
+        data['filter.classification_id'] = $classification_id.val().split(',');
 
       if ($unit && $unit.val())
         data['filter.unit'] = $unit.val().split(',');
@@ -84,7 +93,6 @@ namespace('kivi', function(k){
       state = STATES.PICKED;
       last_real = $real.val();
       last_dummy = $dummy.val();
-      last_unverified_dummy = $dummy.val();
       $real.trigger('change');
 
       if (o.fat_set_item && item.id) {
@@ -105,10 +113,9 @@ namespace('kivi', function(k){
       if (state == STATES.PICKED) {
         annotate_state();
         return true
-      } else if (state == STATES.UNDEFINED && $dummy.val() == '')
+      } else if (state == STATES.UNDEFINED && $dummy.val() === '')
         set_item({})
       else {
-        last_unverified_dummy = $dummy.val();
         set_item({ id: last_real, name: last_dummy })
       }
       annotate_state();
@@ -117,10 +124,9 @@ namespace('kivi', function(k){
     function annotate_state () {
       if (state == STATES.PICKED)
         $dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED);
-      else if (state == STATES.UNDEFINED && $dummy.val() == '')
+      else if (state == STATES.UNDEFINED && $dummy.val() === '')
         $dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED);
       else {
-        last_unverified_dummy = $dummy.val();
         $dummy.addClass(STATES.UNDEFINED).removeClass(STATES.PICKED);
       }
     }
@@ -133,7 +139,7 @@ namespace('kivi', function(k){
         }, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })),
         success: function(data){ $('#part_picker_result').html(data) }
       });
-    };
+    }
 
     function result_timer (event) {
       if (!$('no_paginate').prop('checked')) {
@@ -152,7 +158,7 @@ namespace('kivi', function(k){
 
     function close_popup() {
       $('#part_selection').dialog('close');
-    };
+    }
 
     function handle_changed_text(callbacks) {
       $.ajax({
@@ -173,7 +179,7 @@ namespace('kivi', function(k){
           annotate_state();
         }
       });
-    };
+    }
 
     $dummy.autocomplete({
       source: function(req, rsp) {
@@ -187,6 +193,10 @@ namespace('kivi', function(k){
       select: function(event, ui) {
         set_item(ui.item);
       },
+      search: function(event, ui) {
+        if ((event.which == KEY.SHIFT) || (event.which == KEY.CTRL) || (event.which == KEY.ALT))
+          event.preventDefault();
+      }
     });
     /*  In case users are impatient and want to skip ahead:
      *  Capture <enter> key events and check if it's a unique hit.
@@ -203,7 +213,7 @@ namespace('kivi', function(k){
     $dummy.keydown(function(event){
       if (event.which == KEY.ENTER || event.which == KEY.TAB) {
         // if string is empty assume they want to delete
-        if ($dummy.val() == '') {
+        if ($dummy.val() === '') {
           set_item({});
           return true;
         } else if (state == STATES.PICKED) {
@@ -220,7 +230,7 @@ namespace('kivi', function(k){
           });
           return false;
         }
-      } else {
+      } else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) {
         state = STATES.UNDEFINED;
       }
     });
@@ -242,11 +252,12 @@ namespace('kivi', function(k){
     popup_button.click(open_dialog);
 
     var pp = {
-      real:           function() { return $real },
-      dummy:          function() { return $dummy },
-      type:           function() { return $type },
-      unit:           function() { return $unit },
-      convertible_unit: function() { return $convertible_unit },
+      real:              function() { return $real },
+      dummy:             function() { return $dummy },
+      part_type:         function() { return $part_type },
+      classification_id: function() { return $classification_id },
+      unit:              function() { return $unit },
+      convertible_unit:  function() { return $convertible_unit },
       update_results: update_results,
       result_timer:   result_timer,
       set_item:       set_item,
@@ -258,6 +269,7 @@ namespace('kivi', function(k){
             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(),