1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * JavaScript functions used on Database Search page
6 * @requires js/functions.js
12 * AJAX script for the Database Search page.
14 * Actions ajaxified here:
15 * Retrieve result of SQL query
19 * Unbind all event handlers before tearing down a page
21 AJAX.registerTeardown('db_search.js', function () {
22 $('#buttonGo').unbind('click');
23 $('#togglesearchresultlink').unbind('click');
24 $("#togglequerybox").unbind('click');
25 $('#togglesearchformlink').unbind('click');
26 $(document).off('submit', "#db_search_form.ajax");
30 * Loads the database search results
32 * @param result_path Url of the page to load
33 * @param table_name Name of table to browse
37 function loadResult(result_path, table_name, link)
40 /** Hides the results shown by the delete criteria */
41 var $msg = PMA_ajaxShowMessage(PMA_messages.strBrowsing, false);
42 $('#sqlqueryform').hide();
43 $('#togglequerybox').hide();
44 /** Load the browse results to the page */
45 $("#table-info").show();
46 $('#table-link').attr({"href" : 'sql.php' + link }).text(table_name);
47 var url = result_path + "#searchresults";
48 $.get(url, {'ajax_request': true, 'is_js_confirmed': true}, function (data) {
49 if (typeof data !== 'undefined' && data.success) {
50 $('#browse-results').html(data.message);
51 PMA_ajaxRemoveMessage($msg);
52 $('.table_results').each(function () {
53 PMA_makegrid(this, true, true, true, true);
55 $('#browse-results').show();
56 PMA_highlightSQL($('#browse-results'));
59 scrollTop: $("#browse-results").offset().top
62 PMA_ajaxShowMessage(data.error, false);
69 * Delete the selected search results
71 * @param result_path Url of the page to load
72 * @param msg Text for the confirmation dialog
76 function deleteResult(result_path, msg)
79 /** Hides the results shown by the browse criteria */
80 $("#table-info").hide();
81 $('#sqlqueryform').hide();
82 $('#togglequerybox').hide();
83 /** Conformation message for deletion */
85 var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false);
86 /** Load the deleted option to the page*/
87 $('#sqlqueryform').html('');
88 $.post(result_path, {'ajax_request': true, 'is_js_confirmed': true},
90 if (typeof data === 'undefined' || !data.success) {
91 PMA_ajaxShowMessage(data.error, false);
95 $('#sqlqueryform').html(data.sql_query);
96 /** Refresh the search results after the deletion */
97 document.getElementById('buttonGo').click();
98 $('#togglequerybox').html(PMA_messages.strHideQueryBox);
99 /** Show the results of the deletion option */
100 $('#browse-results').hide();
101 $('#sqlqueryform').show();
102 $('#togglequerybox').show();
105 scrollTop: $("#browse-results").offset().top
107 PMA_ajaxRemoveMessage($msg);
114 AJAX.registerOnload('db_search.js', function () {
115 /** Hide the table link in the initial search result */
116 var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString();
117 $("#table-info").prepend(icon).hide();
119 /** Hide the browse and deleted results in the new search criteria */
120 $('#buttonGo').click(function () {
121 $("#table-info").hide();
122 $('#browse-results').hide();
123 $('#sqlqueryform').hide();
124 $('#togglequerybox').hide();
127 * Prepare a div containing a link for toggle the search results
129 $('#togglesearchresultsdiv')
130 /** don't show it until we have results on-screen */
134 * Changing the displayed text according to
135 * the hide/show criteria in search result forms
137 $('#togglesearchresultlink')
138 .html(PMA_messages.strHideSearchResults)
139 .bind('click', function () {
141 $('#searchresults').slideToggle();
142 if ($link.text() == PMA_messages.strHideSearchResults) {
143 $link.text(PMA_messages.strShowSearchResults);
145 $link.text(PMA_messages.strHideSearchResults);
147 /** avoid default click action */
152 * Prepare a div containing a link for toggle the search form,
153 * otherwise it's incorrectly displayed after a couple of clicks
155 $('#togglesearchformdiv')
156 .hide(); // don't show it until we have results on-screen
159 * Changing the displayed text according to
160 * the hide/show criteria in search form
164 .bind('click', function () {
166 $('#sqlqueryform').slideToggle("medium");
167 if ($link.text() == PMA_messages.strHideQueryBox) {
168 $link.text(PMA_messages.strShowQueryBox);
170 $link.text(PMA_messages.strHideQueryBox);
172 /** avoid default click action */
176 /** don't show it until we have results on-screen */
179 * Changing the displayed text according to
180 * the hide/show criteria in search criteria form
182 $('#togglesearchformlink')
183 .html(PMA_messages.strShowSearchCriteria)
184 .bind('click', function () {
186 $('#db_search_form').slideToggle();
187 if ($link.text() == PMA_messages.strHideSearchCriteria) {
188 $link.text(PMA_messages.strShowSearchCriteria);
190 $link.text(PMA_messages.strHideSearchCriteria);
192 /** avoid default click action */
196 * Ajax Event handler for retrieving the result of an SQL Query
198 $(document).on('submit', "#db_search_form.ajax", function (event) {
199 event.preventDefault();
201 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strSearching, false);
202 // jQuery object to reuse
205 PMA_prepareForAjaxRequest($form);
207 var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
208 $.post($form.attr('action'), url, function (data) {
209 if (typeof data !== 'undefined' && data.success === true) {
211 $("#searchresults").html(data.message);
213 $('#togglesearchresultlink')
214 // always start with the Show message
215 .text(PMA_messages.strHideSearchResults);
216 $('#togglesearchresultsdiv')
217 // now it's time to show the div containing the link
219 $('#searchresults').show();
223 // workaround for Chrome problem (bug #3168569)
226 $('#togglesearchformlink')
227 // always start with the Show message
228 .text(PMA_messages.strShowSearchCriteria);
229 $('#togglesearchformdiv')
230 // now it's time to show the div containing the link
233 // error message (zero rows)
234 $("#searchresults").html(data.error).show();
237 PMA_ajaxRemoveMessage($msgbox);