mehr code nach js/ verlagert
authorSven Schöling <s.schoeling@linet-services.de>
Wed, 3 Jul 2013 17:55:26 +0000 (19:55 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 11 Jul 2013 09:08:13 +0000 (11:08 +0200)
js/autocomplete_part.js
templates/webpages/part/_part_picker_result.html

index 66123e8..61280fd 100644 (file)
@@ -78,6 +78,10 @@ namespace('kivi', function(k){
       });
     };
 
+    function close_popup() {
+      $('#part_selection').jqmClose()
+    };
+
     $dummy.autocomplete({
       source: function(req, rsp) {
         $.ajax($.extend(o, {
@@ -145,13 +149,31 @@ namespace('kivi', function(k){
     picker.addClass('icon16 CRM--Schnellsuche').click(open_dialog);
 
     return {
-      real:     function() { return $real },
-      dummy:    function() { return $dummy },
-      type:     function() { return $type },
-      column:   function() { return $column },
+      real:           function() { return $real },
+      dummy:          function() { return $dummy },
+      type:           function() { return $type },
+      column:         function() { return $column },
       update_results: update_results,
-      set_item: set_item,
-      reset:    make_defined_state,
+      set_item:       set_item,
+      reset:          make_defined_state,
+      init_results:    function () {
+        $('div.part_picker_part').each(function(){
+          $(this).click(function(){
+            set_item({
+              name: $(this).children('input.part_picker_description').val(),
+              id:   $(this).children('input.part_picker_id').val(),
+            });
+            close_popup();
+            return true;
+          });
+        });
+        $('#part_selection').keypress(function(e){
+           if (e.keyCode == 27) { // escape
+             close_popup();
+             $dummy.focus();
+           }
+        });
+      }
     }
   }
 });
index c6a8143..0512b49 100644 (file)
 
 <script type='text/javascript'>
   var pp = kivi.PartPickerCache[$('#part_picker_real_id').val()];
-  $('div.part_picker_part').each(function(){
-    $(this).click(function(){
-      pp.set_item({
-        name: $(this).children('input.part_picker_description').val(),
-        id:   $(this).children('input.part_picker_id').val(),
-      });
-      $('#part_selection').jqmClose();
-      return true;
-    });
-  });
+  pp.init_results();
 </script>