Fixed a problem with the autocomplete agent cache

This commit is contained in:
Alejandro Gallardo Escobar 2018-08-17 15:03:24 +02:00
parent 3320bf1fb2
commit 1de746ab69
2 changed files with 14 additions and 8 deletions

View File

@ -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();
}

View File

@ -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);