From: Bernd Bleßmann Date: Mon, 30 May 2016 14:57:14 +0000 (+0200) Subject: ProjectPicker: Auch auf Paste-Events reagieren. X-Git-Tag: release-3.4.1~122 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=48e32abf9b0af914d6bad46ce7a45f37a65d9946;p=kivitendo-erp.git ProjectPicker: Auch auf Paste-Events reagieren. Siehe auch commit 2cf7a2cd78d812d917fb4c92f8ee57f6a32f3685 (PartPicker: Auch auf Paste-Events reagieren.) --- diff --git a/js/autocomplete_project.js b/js/autocomplete_project.js index c55450463..fb2285fb6 100644 --- a/js/autocomplete_project.js +++ b/js/autocomplete_project.js @@ -116,6 +116,27 @@ namespace('kivi', function(k){ timer = window.setTimeout(update_results, 100); } + function handle_changed_text(callbacks) { + $.ajax({ + url: 'controller.pl?action=Project/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, { @@ -150,28 +171,27 @@ namespace('kivi', function(k){ } else if (state == STATES.PICKED) { return true; } - if (event.which == KEY.TAB) event.preventDefault(); - $.ajax({ - url: 'controller.pl?action=Project/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 { - } - 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();}, + }); 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);