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){
19 $(document).ready(function() {
22 /** Hides the results shown by the delete criteria */
23 PMA_ajaxShowMessage(PMA_messages['strBrowsing']);
24 $('#sqlqueryform').hide();
25 $('#togglequerybox').hide();
26 /** Load the browse results to the page */
27 $("#table-info").show();
28 $('#table-link').attr({"href" : 'sql.php?'+link }).text(table_name);
29 $('#browse-results').load(result_path + " '"+'#sqlqueryresults' + "'", null, function() {
30 // because under db_search, window.parent.table is not defined yet,
31 // we assign it manually from #table-link
32 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){
47 $(document).ready(function() {
48 /** Hides the results shown by the browse criteria */
49 $("#table-info").hide();
50 $('#browse-results').hide();
51 $('#sqlqueryform').hide();
52 $('#togglequerybox').hide();
53 /** Conformation message for deletion */
58 /** Load the deleted option to the page*/
59 $('#browse-results').load(result_path + " '"+'#result_query' + "'");
60 $('#sqlqueryform').load(result_path + " '"+'#sqlqueryform' + "'");
61 $('#togglequerybox').html(PMA_messages['strShowQueryBox']);
63 /** Refresh the search results after the deletion */
64 document.getElementById('buttonGo'). click();
65 PMA_ajaxShowMessage(PMA_messages['strDeleting']);
66 /** Show the results of the deletion option */
67 $('#browse-results').show();
68 $('#sqlqueryform').hide();
69 $('#togglequerybox').show();
73 event.preventDefault();
79 $(document).ready(function() {
82 * Set a parameter for all Ajax queries made on this page. Don't let the
83 * web server serve cached pagesshow
89 /** Hide the table link in the initial search result */
90 $("#table-info").prepend('<img id="table-image" src="./themes/original/img/s_tbl.png" />').hide();
92 /** Hide the browse and deleted results in the new search criteria */
93 $('#buttonGo').click(function(){
94 $("#table-info").hide();
95 $('#browse-results').hide();
96 $('#sqlqueryform').hide();
97 $('#togglequerybox').hide();
100 *Prepare a div containing a link for toggle the search results
102 $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
103 .insertAfter('#searchresults')
104 /** don't show it until we have results on-screen */
107 $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
108 /** Changing the displayed text according to the hide/show criteria in search result forms*/
110 $('#togglesearchresultlink')
111 .html(PMA_messages['strHideSearchResults'])
112 .bind('click', function() {
114 $('#searchresults').slideToggle();
115 if ($link.text() == PMA_messages['strHideSearchResults']) {
116 $link.text(PMA_messages['strShowSearchResults']);
118 $link.text(PMA_messages['strHideSearchResults']);
120 /** avoid default click action */
125 * Prepare a div containing a link for toggle the search form, otherwise it's incorrectly displayed
126 * after a couple of clicks
128 $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
129 .insertAfter('#db_search_form')
130 /** don't show it until we have results on-screen */
133 /** Changing the displayed text according to the hide/show criteria in search form*/
134 $("#togglequerybox").hide();
135 $("#togglequerybox").bind('click', function() {
137 $('#sqlqueryform').slideToggle("medium");
138 if ($link.text() == PMA_messages['strHideQueryBox']) {
139 $link.text(PMA_messages['strShowQueryBox']);
141 $link.text(PMA_messages['strHideQueryBox']);
143 /** avoid default click action */
147 /** don't show it until we have results on-screen */
149 /** Changing the displayed text according to the hide/show criteria in search criteria form*/
150 $('#togglesearchformlink')
151 .html(PMA_messages['strShowSearchCriteria'])
152 .bind('click', function() {
154 $('#db_search_form').slideToggle();
155 if ($link.text() == PMA_messages['strHideSearchCriteria']) {
156 $link.text(PMA_messages['strShowSearchCriteria']);
158 $link.text(PMA_messages['strHideSearchCriteria']);
160 /** avoid default click action */
164 * Ajax Event handler for retrieving the result of an SQL Query
165 * (see $GLOBALS['cfg']['AjaxEnable'])
167 * @uses PMA_ajaxShowMessage()
168 * @see $GLOBALS['cfg']['AjaxEnable']
170 $("#db_search_form.ajax").live('submit', function(event) {
171 event.preventDefault();
173 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
174 // jQuery object to reuse
177 PMA_prepareForAjaxRequest($form);
179 $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(), function(response) {
180 if (typeof response == 'string') {
182 $("#searchresults").html(response);
184 $('#togglesearchresultlink')
185 // always start with the Show message
186 .text(PMA_messages['strHideSearchResults'])
187 $('#togglesearchresultsdiv')
188 // now it's time to show the div containing the link
190 $('#searchresults').show();
194 // workaround for Chrome problem (bug #3168569)
197 $('#togglesearchformlink')
198 // always start with the Show message
199 .text(PMA_messages['strShowSearchCriteria'])
200 $('#togglesearchformdiv')
201 // now it's time to show the div containing the link
204 // error message (zero rows)
205 $("#sqlqueryresults").html(response['message']);
208 PMA_ajaxRemoveMessage($msgbox);
211 }, 'top.frame_content'); // end $(document).ready()