From 380bf8087bf0ea1f625873f49a82e35147edaef7 Mon Sep 17 00:00:00 2001 From: Casiva Agustin Date: Wed, 2 May 2012 19:35:46 -0300 Subject: [PATCH] Add Ajax suport to Fast filter in order to search the term in all database tables --- js/navigation.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/js/navigation.js b/js/navigation.js index 9800d1d407..843a998675 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -160,6 +160,9 @@ function PMA_setCookie(name, value, expires, path, domain, secure) function fast_filter(value) { var lowercase_value = value.toLowerCase(); + var matches = 0; + var db = $('#lightm_db').val(); + $('li.ajax_table').hide(); $("#subel0 a[class!='tableicon']").each(function(idx, elem) { var $elem = $(elem); // .indexOf is case sensitive so convert to lowercase to compare @@ -167,10 +170,28 @@ function fast_filter(value) $elem.parent().hide(); } else { $elem.parents('li').show(); + matches = matches + 1; } }); + + if (matches === 0) { //If no local matches search in all tables + if (fast_filter.ajax_semaphore) { //If is true another request is running + return; + } + fast_filter.ajax_semaphore = true; + $.get('db_tables_search.php?db=' + db +'&table=' + lowercase_value, function(data) { + var tables = data.tables; + var l = tables.length; + for(var i = 0; i < l; i++) { + $('#subel0').append(tables[i].line); + } + fast_filter.ajax_semaphore = false; + }); + } } +fast_filter.ajax_semaphore = false; //If is true an Ajax request is running + /** * Clears fast filter. */ @@ -223,8 +244,11 @@ $(function(){ $('#fast_filter').focus(); }); - $('#fast_filter').keyup(function(evt) { + $('#fast_filter').keyup(function(evt) { fast_filter($(this).val()); + if ($(this).val() == '') { //Hides added tables by search + $('li.ajax_table').hide(); + } }); /* Jump to recent table */