From 2cf7a2cd78d812d917fb4c92f8ee57f6a32f3685 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 30 May 2016 16:53:24 +0200 Subject: [PATCH] PartPicker: Auch auf Paste-Events reagieren. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Damit wird bei eindeutigem eingefügtem Text der entsprechende Artikel ausgewählt. Ansonsten wird der Text rot (undefined) dargestellt. Vorher war es möglich, z.B. eine eindeutige Artikelnummer einzufügen, aber intern war dennoch kein Artikel ausgewählt. In der Anzeige sah es aber so aus, als sei alles in Ordnung. --- js/autocomplete_part.js | 56 +++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/js/autocomplete_part.js b/js/autocomplete_part.js index f271b8da4..0366ed270 100644 --- a/js/autocomplete_part.js +++ b/js/autocomplete_part.js @@ -154,6 +154,27 @@ namespace('kivi', function(k){ $('#part_selection').dialog('close'); }; + function handle_changed_text(callbacks) { + $.ajax({ + url: 'controller.pl?action=Part/ajax_autocomplete', + dataType: "json", + data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), + success: function (data) { + if (data.length == 1) { + set_item(data[0]); + if (callbacks && callbacks.match_one) callbacks.match_one(data[0]); + } else if (data.length > 1) { + state = STATES.UNDEFINED; + if (callbacks && callbacks.match_many) callbacks.match_many(data); + } else { + state = STATES.UNDEFINED; + if (callbacks &&callbacks.match_none) callbacks.match_none(); + } + annotate_state(); + } + }); + }; + $dummy.autocomplete({ source: function(req, rsp) { $.ajax($.extend(o, { @@ -188,31 +209,28 @@ namespace('kivi', function(k){ } else if (state == STATES.PICKED) { return true; } - if (event.which == KEY.TAB) event.preventDefault(); - $.ajax({ - url: 'controller.pl?action=Part/ajax_autocomplete', - dataType: "json", - data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), - success: function (data) { - if (data.length == 1) { - set_item(data[0]); - if (event.which == KEY.ENTER) - $('#update_button').click(); - } else if (data.length > 1) { - if (event.which == KEY.ENTER) - open_dialog(); - } else { - } - annotate_state(); - } - }); - if (event.which == KEY.ENTER) + if (event.which == KEY.TAB) { + event.preventDefault(); + handle_changed_text(); + } + if (event.which == KEY.ENTER) { + handle_changed_text({ + match_one: function(){$('#update_button').click();}, + match_many: function(){open_dialog();} + }); return false; + } } else { state = STATES.UNDEFINED; } }); + $dummy.on('paste', function(){ + setTimeout(function() { + handle_changed_text(); + }, 1); + }); + $dummy.blur(function(){ window.clearTimeout(timer); timer = window.setTimeout(annotate_state, 100); -- 2.20.1