From 1de746ab696aea36e774ba97d5678a81935b636e Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Fri, 17 Aug 2018 15:03:24 +0200 Subject: [PATCH] Fixed a problem with the autocomplete agent cache --- .../godmode/gis_maps/configure_gis_map.php | 3 ++- pandora_console/include/functions_ui.php | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/gis_maps/configure_gis_map.php b/pandora_console/godmode/gis_maps/configure_gis_map.php index 79d3466351..b731c7b6d9 100644 --- a/pandora_console/godmode/gis_maps/configure_gis_map.php +++ b/pandora_console/godmode/gis_maps/configure_gis_map.php @@ -484,6 +484,7 @@ $params['input_name'] = 'agent_alias_for_data'; $params['value'] = ''; $params['javascript_function_action_after_select'] = 'toggleAddGroupBtn'; $params['selectbox_group'] = 'layer_group_id'; // Filter by group +$params['disabled_javascript_on_blur_function'] = true; $agent_for_group_input = ui_print_agent_autocomplete_input($params); $add_group_btn = html_print_button(__('Add'), 'add_group', true, '', 'class="sub add"', true); @@ -1066,7 +1067,7 @@ function onFormSubmit (event) { function onLayerGroupIdChange (event) { // Clear agent inputs - $("input#hidden-agent_id_for_data").val(""); + $("input#hidden-agent_id_for_data").val(0); $("input#text-agent_alias_for_data").val(""); toggleAddGroupBtn(); } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 279542edca..54334e4ecf 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3316,6 +3316,13 @@ function ui_print_agent_autocomplete_input($parameters) { minLength: 2, source: function( request, response ) { var term = request.term; //Word to search + ' . $javascript_change_ajax_params_text . ' + var groupId = data_params.id_group(); + + // Index cache by group Id + if (cache_' . $input_name . '[groupId] == null) { + cache_' . $input_name . '[groupId] = {}; + } //Set loading $("#' . $input_id . '") @@ -3329,8 +3336,8 @@ function ui_print_agent_autocomplete_input($parameters) { //==== CACHE CODE ================================== //Check the cache var found = false; - if (term in cache_' . $input_name . ') { - response(cache_' . $input_name . '[term]); + if (term in cache_' . $input_name . '[groupId]) { + response(cache_' . $input_name . '[groupId][term]); //Set icon $("#' . $input_id . '") @@ -3345,11 +3352,11 @@ function ui_print_agent_autocomplete_input($parameters) { for (i = 1; i < term.length; i++) { var term_match = term.substr(0, term.length - i); - $.each(cache_' . $input_name . ', function (oldterm, olddata) { + $.each(cache_' . $input_name . '[groupId], function (oldterm, olddata) { var pattern = new RegExp("^" + term_match + ".*","gi"); if (oldterm.match(pattern)) { - response(cache_' . $input_name . '[oldterm]); + response(cache_' . $input_name . '[groupId][oldterm]); found = true; @@ -3376,15 +3383,13 @@ function ui_print_agent_autocomplete_input($parameters) { return; } - ' . $javascript_change_ajax_params_text . ' - jQuery.ajax ({ data: data_params, type: "POST", url: action="' . $javascript_ajax_page . '", dataType: "json", success: function (data) { - cache_' . $input_name . '[term] = data; //Save the cache + cache_' . $input_name . '[groupId][term] = data; //Save the cache response(data);