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 * Loads the database search results
21 * @param result_path Url of the page to load
22 * @param table_name Name of table to browse
23 * @param ajaxEnable Whether to use ajax or not
27 function loadResult(result_path, table_name, link, ajaxEnable)
29 $(document).ready(function() {
31 /** Hides the results shown by the delete criteria */
32 var $msg = PMA_ajaxShowMessage();
33 $('#sqlqueryform').hide();
34 $('#togglequerybox').hide();
35 /** Load the browse results to the page */
36 $("#table-info").show();
37 $('#table-link').attr({"href" : 'sql.php?'+link }).text(table_name);
38 var url = result_path + " #sqlqueryresults";
39 $('#browse-results').load(url, null, function() {
42 scrollTop: $("#browse-results").offset().top
44 PMA_ajaxRemoveMessage($msg);
45 // because under db_search, window.parent.table is not defined yet,
46 // we assign it manually from #table-link
47 window.parent.table = $('#table-link').text().trim();
48 PMA_makegrid($('#table_results')[0], true, true, true, true);
51 event.preventDefault();
57 * Delete the selected search results
59 * @param result_path Url of the page to load
60 * @param msg Text for the confirmation dialog
61 * @param ajaxEnable Whether to use ajax or not
65 function deleteResult(result_path, msg, ajaxEnable)
67 $(document).ready(function() {
68 /** Hides the results shown by the browse criteria */
69 $("#table-info").hide();
70 $('#browse-results').hide();
71 $('#sqlqueryform').hide();
72 $('#togglequerybox').hide();
73 /** Conformation message for deletion */
76 var $msg = PMA_ajaxShowMessage(PMA_messages['strDeleting'], false);
77 /** Load the deleted option to the page*/
78 $('#sqlqueryform').html('');
79 var url = result_path + " #result_query, #sqlqueryform";
80 $('#browse-results').load(url, function () {
81 /** Refresh the search results after the deletion */
82 document.getElementById('buttonGo').click();
83 $('#togglequerybox').html(PMA_messages['strHideQueryBox']);
84 PMA_ajaxRemoveMessage($msg);
85 /** Show the results of the deletion option */
86 $('#browse-results').show();
87 $('#sqlqueryform').show();
88 $('#togglequerybox').show();
91 event.preventDefault();
97 $(document).ready(function() {
98 /** Hide the table link in the initial search result */
99 var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString();
100 $("#table-info").prepend(icon).hide();
102 /** Hide the browse and deleted results in the new search criteria */
103 $('#buttonGo').click(function(){
104 $("#table-info").hide();
105 $('#browse-results').hide();
106 $('#sqlqueryform').hide();
107 $('#togglequerybox').hide();
110 * Prepare a div containing a link for toggle the search results
112 $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
113 .insertAfter('#searchresults')
114 /** don't show it until we have results on-screen */
117 $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
119 * Changing the displayed text according to
120 * the hide/show criteria in search result forms
122 $('#togglesearchresultlink')
123 .html(PMA_messages['strHideSearchResults'])
124 .bind('click', function() {
126 $('#searchresults').slideToggle();
127 if ($link.text() == PMA_messages['strHideSearchResults']) {
128 $link.text(PMA_messages['strShowSearchResults']);
130 $link.text(PMA_messages['strHideSearchResults']);
132 /** avoid default click action */
137 * Prepare a div containing a link for toggle the search form,
138 * otherwise it's incorrectly displayed after a couple of clicks
140 $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
141 .insertAfter('#db_search_form')
142 .hide(); // don't show it until we have results on-screen
145 * Changing the displayed text according to
146 * the hide/show criteria in search form
148 $("#togglequerybox").hide();
149 $("#togglequerybox").bind('click', function() {
151 $('#sqlqueryform').slideToggle("medium");
152 if ($link.text() == PMA_messages['strHideQueryBox']) {
153 $link.text(PMA_messages['strShowQueryBox']);
155 $link.text(PMA_messages['strHideQueryBox']);
157 /** avoid default click action */
161 /** don't show it until we have results on-screen */
164 * Changing the displayed text according to
165 * the hide/show criteria in search criteria form
167 $('#togglesearchformlink')
168 .html(PMA_messages['strShowSearchCriteria'])
169 .bind('click', function() {
171 $('#db_search_form').slideToggle();
172 if ($link.text() == PMA_messages['strHideSearchCriteria']) {
173 $link.text(PMA_messages['strShowSearchCriteria']);
175 $link.text(PMA_messages['strHideSearchCriteria']);
177 /** avoid default click action */
181 * Ajax Event handler for retrieving the result of an SQL Query
182 * (see $GLOBALS['cfg']['AjaxEnable'])
184 * @see $GLOBALS['cfg']['AjaxEnable']
186 $("#db_search_form.ajax").live('submit', function(event) {
187 event.preventDefault();
189 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
190 // jQuery object to reuse
193 PMA_prepareForAjaxRequest($form);
195 var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
196 $.post($form.attr('action'), url, function(response) {
197 if (typeof response == 'string') {
199 $("#searchresults").html(response);
201 $('#togglesearchresultlink')
202 // always start with the Show message
203 .text(PMA_messages['strHideSearchResults'])
204 $('#togglesearchresultsdiv')
205 // now it's time to show the div containing the link
207 $('#searchresults').show();
211 // workaround for Chrome problem (bug #3168569)
214 $('#togglesearchformlink')
215 // always start with the Show message
216 .text(PMA_messages['strShowSearchCriteria'])
217 $('#togglesearchformdiv')
218 // now it's time to show the div containing the link
221 // error message (zero rows)
222 $("#sqlqueryresults").html(response['message']);
225 PMA_ajaxRemoveMessage($msgbox);
228 }, 'top.frame_content'); // end $(document).ready()