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);
53 scrollTop: $("#browse-results").offset().top
55 PMA_ajaxRemoveMessage($msg);
56 $('.table_results').each(function () {
57 PMA_makegrid(this, true, true, true, true);
59 $('#browse-results').show();
61 PMA_ajaxShowMessage(data.error, false);
68 * Delete the selected search results
70 * @param result_path Url of the page to load
71 * @param msg Text for the confirmation dialog
75 function deleteResult(result_path, msg)
78 /** Hides the results shown by the browse criteria */
79 $("#table-info").hide();
80 $('#sqlqueryform').hide();
81 $('#togglequerybox').hide();
82 /** Conformation message for deletion */
84 var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false);
85 /** Load the deleted option to the page*/
86 $('#sqlqueryform').html('');
87 var url = result_path;
88 $.get(url, {'ajax_request': true, 'is_js_confirmed': true},
90 if (typeof data !== 'undefined' && data.success) {
91 $('#sqlqueryform').html(data.sql_query);
92 /** Refresh the search results after the deletion */
93 document.getElementById('buttonGo').click();
94 $('#togglequerybox').html(PMA_messages.strHideQueryBox);
95 /** Show the results of the deletion option */
96 $('#browse-results').hide();
97 $('#sqlqueryform').show();
98 $('#togglequerybox').show();
101 scrollTop: $("#browse-results").offset().top
103 PMA_ajaxRemoveMessage($msg);
105 PMA_ajaxShowMessage(data.error, false);
113 AJAX.registerOnload('db_search.js', function () {
114 /** Hide the table link in the initial search result */
115 var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString();
116 $("#table-info").prepend(icon).hide();
118 /** Hide the browse and deleted results in the new search criteria */
119 $('#buttonGo').click(function () {
120 $("#table-info").hide();
121 $('#browse-results').hide();
122 $('#sqlqueryform').hide();
123 $('#togglequerybox').hide();
126 * Prepare a div containing a link for toggle the search results
128 $('#togglesearchresultsdiv')
129 /** don't show it until we have results on-screen */
133 * Changing the displayed text according to
134 * the hide/show criteria in search result forms
136 $('#togglesearchresultlink')
137 .html(PMA_messages.strHideSearchResults)
138 .bind('click', function () {
140 $('#searchresults').slideToggle();
141 if ($link.text() == PMA_messages.strHideSearchResults) {
142 $link.text(PMA_messages.strShowSearchResults);
144 $link.text(PMA_messages.strHideSearchResults);
146 /** avoid default click action */
151 * Prepare a div containing a link for toggle the search form,
152 * otherwise it's incorrectly displayed after a couple of clicks
154 $('#togglesearchformdiv')
155 .hide(); // don't show it until we have results on-screen
158 * Changing the displayed text according to
159 * the hide/show criteria in search form
163 .bind('click', function () {
165 $('#sqlqueryform').slideToggle("medium");
166 if ($link.text() == PMA_messages.strHideQueryBox) {
167 $link.text(PMA_messages.strShowQueryBox);
169 $link.text(PMA_messages.strHideQueryBox);
171 /** avoid default click action */
175 /** don't show it until we have results on-screen */
178 * Changing the displayed text according to
179 * the hide/show criteria in search criteria form
181 $('#togglesearchformlink')
182 .html(PMA_messages.strShowSearchCriteria)
183 .bind('click', function () {
185 $('#db_search_form').slideToggle();
186 if ($link.text() == PMA_messages.strHideSearchCriteria) {
187 $link.text(PMA_messages.strShowSearchCriteria);
189 $link.text(PMA_messages.strHideSearchCriteria);
191 /** avoid default click action */
195 * Ajax Event handler for retrieving the result of an SQL Query
197 $(document).on('submit', "#db_search_form.ajax", function (event) {
198 event.preventDefault();
200 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strSearching, false);
201 // jQuery object to reuse
204 PMA_prepareForAjaxRequest($form);
206 var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
207 $.post($form.attr('action'), url, function (data) {
208 if (typeof data !== 'undefined' && data.success === true) {
210 $("#searchresults").html(data.message);
212 $('#togglesearchresultlink')
213 // always start with the Show message
214 .text(PMA_messages.strHideSearchResults);
215 $('#togglesearchresultsdiv')
216 // now it's time to show the div containing the link
218 $('#searchresults').show();
222 // workaround for Chrome problem (bug #3168569)
225 $('#togglesearchformlink')
226 // always start with the Show message
227 .text(PMA_messages.strShowSearchCriteria);
228 $('#togglesearchformdiv')
229 // now it's time to show the div containing the link
232 // error message (zero rows)
233 $("#searchresults").html(data.error).show();
236 PMA_ajaxRemoveMessage($msgbox);