1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview JavaScript functions used on Database Search page
4 * @name Database Search
7 * @requires js/functions.js
11 * AJAX script for the Database Search page.
13 * Actions ajaxified here:
14 * Retrieve result of SQL query
17 /** Loads the database search results */
18 function loadResult(result_path , table_name , link , ajaxEnable)
20 $(document).ready(function() {
23 /** Hides the results shown by the delete criteria */
24 PMA_ajaxShowMessage(PMA_messages['strBrowsing']);
25 $('#sqlqueryform').hide();
26 $('#togglequerybox').hide();
27 /** Load the browse results to the page */
28 $("#table-info").show();
29 $('#table-link').attr({"href" : 'sql.php?'+link }).text(table_name);
30 $('#browse-results').load(result_path + " '"+'#sqlqueryresults' + "'", null, function() {
31 // because under db_search, window.parent.table is not defined yet,
32 // we assign it manually from #table-link
33 window.parent.table = $('#table-link').text().trim();
35 $('#table_results').makegrid();
40 event.preventDefault();
45 /** Delete the selected search results */
46 function deleteResult(result_path , msg , ajaxEnable)
48 $(document).ready(function() {
49 /** Hides the results shown by the browse criteria */
50 $("#table-info").hide();
51 $('#browse-results').hide();
52 $('#sqlqueryform').hide();
53 $('#togglequerybox').hide();
54 /** Conformation message for deletion */
59 /** Load the deleted option to the page*/
60 $('#browse-results').load(result_path + " '"+'#result_query' + "'");
61 $('#sqlqueryform').load(result_path + " '"+'#sqlqueryform' + "'");
62 $('#togglequerybox').html(PMA_messages['strShowQueryBox']);
64 /** Refresh the search results after the deletion */
65 document.getElementById('buttonGo'). click();
66 PMA_ajaxShowMessage(PMA_messages['strDeleting']);
67 /** Show the results of the deletion option */
68 $('#browse-results').show();
69 $('#sqlqueryform').hide();
70 $('#togglequerybox').show();
74 event.preventDefault();
80 $(document).ready(function() {
83 * Set a parameter for all Ajax queries made on this page. Don't let the
84 * web server serve cached pagesshow
90 /** Hide the table link in the initial search result */
91 $("#table-info").prepend('<img id="table-image" class="icon ic_s_tbl" src="./themes/dot.gif" />').hide();
93 /** Hide the browse and deleted results in the new search criteria */
94 $('#buttonGo').click(function(){
95 $("#table-info").hide();
96 $('#browse-results').hide();
97 $('#sqlqueryform').hide();
98 $('#togglequerybox').hide();
101 *Prepare a div containing a link for toggle the search results
103 $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
104 .insertAfter('#searchresults')
105 /** don't show it until we have results on-screen */
108 $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
109 /** Changing the displayed text according to the hide/show criteria in search result forms*/
111 $('#togglesearchresultlink')
112 .html(PMA_messages['strHideSearchResults'])
113 .bind('click', function() {
115 $('#searchresults').slideToggle();
116 if ($link.text() == PMA_messages['strHideSearchResults']) {
117 $link.text(PMA_messages['strShowSearchResults']);
119 $link.text(PMA_messages['strHideSearchResults']);
121 /** avoid default click action */
126 * Prepare a div containing a link for toggle the search form, otherwise it's incorrectly displayed
127 * after a couple of clicks
129 $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
130 .insertAfter('#db_search_form')
131 /** don't show it until we have results on-screen */
134 /** Changing the displayed text according to the hide/show criteria in search form*/
135 $("#togglequerybox").hide();
136 $("#togglequerybox").bind('click', function() {
138 $('#sqlqueryform').slideToggle("medium");
139 if ($link.text() == PMA_messages['strHideQueryBox']) {
140 $link.text(PMA_messages['strShowQueryBox']);
142 $link.text(PMA_messages['strHideQueryBox']);
144 /** avoid default click action */
148 /** don't show it until we have results on-screen */
150 /** Changing the displayed text according to the hide/show criteria in search criteria form*/
151 $('#togglesearchformlink')
152 .html(PMA_messages['strShowSearchCriteria'])
153 .bind('click', function() {
155 $('#db_search_form').slideToggle();
156 if ($link.text() == PMA_messages['strHideSearchCriteria']) {
157 $link.text(PMA_messages['strShowSearchCriteria']);
159 $link.text(PMA_messages['strHideSearchCriteria']);
161 /** avoid default click action */
165 * Ajax Event handler for retrieving the result of an SQL Query
166 * (see $GLOBALS['cfg']['AjaxEnable'])
168 * @uses PMA_ajaxShowMessage()
169 * @see $GLOBALS['cfg']['AjaxEnable']
171 $("#db_search_form.ajax").live('submit', function(event) {
172 event.preventDefault();
174 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
175 // jQuery object to reuse
178 PMA_prepareForAjaxRequest($form);
180 $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(), function(response) {
181 if (typeof response == 'string') {
183 $("#searchresults").html(response);
185 $('#togglesearchresultlink')
186 // always start with the Show message
187 .text(PMA_messages['strHideSearchResults'])
188 $('#togglesearchresultsdiv')
189 // now it's time to show the div containing the link
191 $('#searchresults').show();
195 // workaround for Chrome problem (bug #3168569)
198 $('#togglesearchformlink')
199 // always start with the Show message
200 .text(PMA_messages['strShowSearchCriteria'])
201 $('#togglesearchformdiv')
202 // now it's time to show the div containing the link
205 // error message (zero rows)
206 $("#sqlqueryresults").html(response['message']);
209 PMA_ajaxRemoveMessage($msgbox);
212 }, 'top.frame_content'); // end $(document).ready()