diff --git a/js/db_search.js b/js/db_search.js index 2bde7cd9f2..157cfc8015 100644 --- a/js/db_search.js +++ b/js/db_search.js @@ -19,6 +19,8 @@ * Unbind all event handlers before tearing down a page */ AJAX.registerTeardown('db_search.js', function () { + $('a.browse_results').unbind('click'); + $('a.delete_results').unbind('click'); $('#buttonGo').unbind('click'); $('#togglesearchresultlink').unbind('click'); $("#togglequerybox").unbind('click'); @@ -26,91 +28,6 @@ AJAX.registerTeardown('db_search.js', function () { $(document).off('submit', "#db_search_form.ajax"); }); -/** - * Loads the database search results - * - * @param result_path Url of the page to load - * @param table_name Name of table to browse - * - * @return nothing - */ -function loadResult(result_path, table_name, link) -{ - $(function () { - /** Hides the results shown by the delete criteria */ - var $msg = PMA_ajaxShowMessage(PMA_messages.strBrowsing, false); - $('#sqlqueryform').hide(); - $('#togglequerybox').hide(); - /** Load the browse results to the page */ - $("#table-info").show(); - $('#table-link').attr({"href" : 'sql.php' + link }).text(table_name); - var url = result_path + "#searchresults"; - $.get(url, {'ajax_request': true, 'is_js_confirmed': true}, function (data) { - if (typeof data !== 'undefined' && data.success) { - $('#browse-results').html(data.message); - PMA_ajaxRemoveMessage($msg); - $('.table_results').each(function () { - PMA_makegrid(this, true, true, true, true); - }); - $('#browse-results').show(); - PMA_highlightSQL($('#browse-results')); - $('html, body') - .animate({ - scrollTop: $("#browse-results").offset().top - }, 1000); - } else { - PMA_ajaxShowMessage(data.error, false); - } - }); - }); -} - -/** - * Delete the selected search results - * - * @param result_path Url of the page to load - * @param msg Text for the confirmation dialog - * - * @return nothing - */ -function deleteResult(result_path, msg) -{ - $(function () { - /** Hides the results shown by the browse criteria */ - $("#table-info").hide(); - $('#sqlqueryform').hide(); - $('#togglequerybox').hide(); - /** Conformation message for deletion */ - if (confirm(msg)) { - var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false); - /** Load the deleted option to the page*/ - $('#sqlqueryform').html(''); - $.post(result_path, {'ajax_request': true, 'is_js_confirmed': true}, - function (data) { - if (typeof data === 'undefined' || !data.success) { - PMA_ajaxShowMessage(data.error, false); - return; - } - - $('#sqlqueryform').html(data.sql_query); - /** Refresh the search results after the deletion */ - document.getElementById('buttonGo').click(); - $('#togglequerybox').html(PMA_messages.strHideQueryBox); - /** Show the results of the deletion option */ - $('#browse-results').hide(); - $('#sqlqueryform').show(); - $('#togglequerybox').show(); - $('html, body') - .animate({ - scrollTop: $("#browse-results").offset().top - }, 1000); - PMA_ajaxRemoveMessage($msg); - } - ); - } - }); -} - AJAX.registerOnload('db_search.js', function () { /** Hide the table link in the initial search result */ var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString(); @@ -192,6 +109,95 @@ AJAX.registerOnload('db_search.js', function () { /** avoid default click action */ return false; }); + + /* + * Ajax Event handler for retrieving the results from a table + */ + $(document).on('click', 'a.browse_results', function(e){ + e.preventDefault(); + /** Hides the results shown by the delete criteria */ + var $msg = PMA_ajaxShowMessage(PMA_messages.strBrowsing, false); + $('#sqlqueryform').hide(); + $('#togglequerybox').hide(); + /** Load the browse results to the page */ + $("#table-info").show(); + var table_name = $(this).data('table-name'); + $('#table-link').attr({"href" : $(this).attr('href')}).text(table_name); + + var url = $(this).attr('href') + "#searchresults"; + var browse_sql = $(this).data('browse-sql'); + var params = { + 'ajax_request': true, + 'is_js_confirmed': true, + 'sql_query' : browse_sql + }; + $.post(url, params, function (data) { + if (typeof data !== 'undefined' && data.success) { + $('#browse-results').html(data.message); + PMA_ajaxRemoveMessage($msg); + $('.table_results').each(function () { + PMA_makegrid(this, true, true, true, true); + }); + $('#browse-results').show(); + PMA_highlightSQL($('#browse-results')); + $('html, body') + .animate({ + scrollTop: $("#browse-results").offset().top + }, 1000); + } else { + PMA_ajaxShowMessage(data.error, false); + } + }); + }); + + /* + * Ajax Event handler for deleting the results from a table + */ + $(document).on('click', 'a.delete_results', function(e){ + e.preventDefault(); + /** Hides the results shown by the browse criteria */ + $("#table-info").hide(); + $('#sqlqueryform').hide(); + $('#togglequerybox').hide(); + /** Conformation message for deletion */ + var msg = PMA_sprintf( + PMA_messages.strConfirmDeleteResults, + $(this).data('table-name') + ); + if (confirm(msg)) { + var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false); + /** Load the deleted option to the page*/ + $('#sqlqueryform').html(''); + var params = { + 'ajax_request': true, + 'is_js_confirmed': true, + 'sql_query': $(this).data('delete-sql') + }; + var url = $(this).attr('href'); + + $.post(url, params, function (data) { + if (typeof data === 'undefined' || !data.success) { + PMA_ajaxShowMessage(data.error, false); + return; + } + + $('#sqlqueryform').html(data.sql_query); + /** Refresh the search results after the deletion */ + document.getElementById('buttonGo').click(); + $('#togglequerybox').html(PMA_messages.strHideQueryBox); + /** Show the results of the deletion option */ + $('#browse-results').hide(); + $('#sqlqueryform').show(); + $('#togglequerybox').show(); + $('html, body') + .animate({ + scrollTop: $("#browse-results").offset().top + }, 1000); + PMA_ajaxRemoveMessage($msg); + }); + } + }); + /** * Ajax Event handler for retrieving the result of an SQL Query */ diff --git a/js/messages.php b/js/messages.php index 5475bbdbc6..365d0da19e 100644 --- a/js/messages.php +++ b/js/messages.php @@ -380,6 +380,7 @@ $js_messages['strHideSearchResults'] = __('Hide search results'); $js_messages['strShowSearchResults'] = __('Show search results'); $js_messages['strBrowsing'] = __('Browsing'); $js_messages['strDeleting'] = __('Deleting'); +$js_messages['strConfirmDeleteResults'] = __('Delete the matches for the %s table?'); /* For db_routines.js */ $js_messages['MissingReturn'] diff --git a/libraries/DbSearch.php b/libraries/DbSearch.php index 9299bf2800..23f227f6e1 100644 --- a/libraries/DbSearch.php +++ b/libraries/DbSearch.php @@ -334,30 +334,23 @@ class DbSearch $html_output .= ''; // Displays browse/delete link if result count > 0 if ($res_cnt > 0) { - $this_url_params['sql_query'] = $newsearchsqls['select_columns']; + $this_url_params['db'] = htmlspecialchars($GLOBALS['db']); + $this_url_params['table'] = htmlspecialchars($each_table); $browse_result_path = 'sql.php' . PMA_URL_getCommon($this_url_params); - $html_output .= '' + $html_output .= '' . __('Browse') . ''; - $this_url_params['sql_query'] = $newsearchsqls['delete']; - $delete_result_path = 'sql.php' . PMA_URL_getCommon($this_url_params); - $html_output .= '' - . __('Delete') . ''; + + $delete_result_path = $browse_result_path; + $html_output .= '' . __('Delete') . ''; } else { $html_output .= ' ' . ' '; diff --git a/test/classes/DbSearchTest.php b/test/classes/DbSearchTest.php index 31ca9b2404..9bb6038109 100644 --- a/test/classes/DbSearchTest.php +++ b/test/classes/DbSearchTest.php @@ -41,6 +41,7 @@ class DbSearchTest extends PMATestCase $this->object = new DbSearch('pma_test'); $GLOBALS['server'] = 0; $GLOBALS['db'] = 'pma'; + $GLOBALS['collation_connection'] = 'utf-8'; //mock DBI $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') @@ -166,28 +167,19 @@ class DbSearchTest extends PMATestCase ), true, '2 matches in table1' - . 'Browse' - . 'Browse' + . 'Delete' + . '&is_js_confirmed=0&server=0&' + . 'lang=en&collation_connection=utf-8&token=token" ' + . 'table_name="table1" delete_sql="column2" ' + . '>Delete' ) ); }