Merge branch 'QA_3_4'
[phpmyadmin-regexreplace.git] / js / db_search.js
blob79c444e856840b63942b89a59d8fdf75774777aa
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * @fileoverview JavaScript functions used on Database Search page
4 * @name Database Search
6 * @requires jQuery
7 * @requires js/functions.js
8 */
10 /**
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() {
20 if(ajaxEnable)
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' + "'").show();
31 else
33 event.preventDefault();
35 });
38 /** Delete the selected search results */
39 function deleteResult(result_path , msg , ajaxEnable){
40 $(document).ready(function() {
41 /** Hides the results shown by the browse criteria */
42 $("#table-info").hide();
43 $('#browse-results').hide();
44 $('#sqlqueryform').hide();
45 $('#togglequerybox').hide();
46 /** Conformation message for deletion */
47 if(confirm(msg))
49 if(ajaxEnable)
51 /** Load the deleted option to the page*/
52 $('#browse-results').load(result_path + " '"+'#result_query' + "'");
53 $('#sqlqueryform').load(result_path + " '"+'#sqlqueryform' + "'");
54 $('#togglequerybox').html(PMA_messages['strHideQueryBox']);
56 /** Refresh the search results after the deletion */
57 document.getElementById('buttonGo'). click();
58 //PMA_ajaxShowMessage(PMA_messages['strDeleting']);
59 /** Show the results of the deletion option */
60 $('#browse-results').show();
61 $('#sqlqueryform').show();
62 $('#togglequerybox').show();
64 else
66 event.preventDefault();
69 });
72 $(document).ready(function() {
74 /**
75 * Set a parameter for all Ajax queries made on this page. Don't let the
76 * web server serve cached pagesshow
78 $.ajaxSetup({
79 cache: 'false'
80 });
82 /** Hide the table link in the initial search result */
83 $("#table-info").prepend('<img id="table-image" src="./themes/original/img/s_tbl.png" />').hide();
85 /** Hide the browse and deleted results in the new search criteria */
86 $('#buttonGo').click(function(){
87 $("#table-info").hide();
88 $('#browse-results').hide();
89 $('#sqlqueryform').hide();
90 $('#togglequerybox').hide();
91 });
92 /**
93 * Prepare a div containing a link for toggle the search form, otherwise it's incorrectly displayed
94 * after a couple of clicks
96 $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
97 .insertAfter('#db_search_form')
98 /** don't show it until we have results on-screen */
99 .hide();
101 /** Changing the displayed text according to the hide/show criteria in search form*/
102 $("#togglequerybox").hide();
103 $("#togglequerybox").bind('click', function() {
104 var $link = $(this)
105 $('#sqlqueryform').slideToggle("medium");
106 if ($link.text() == PMA_messages['strHideQueryBox']) {
107 $link.text(PMA_messages['strShowQueryBox']);
108 } else {
109 $link.text(PMA_messages['strHideQueryBox']);
111 /** avoid default click action */
112 return false;
115 /** don't show it until we have results on-screen */
117 /** Changing the displayed text according to the hide/show criteria in search criteria form*/
118 $('#togglesearchformlink')
119 .html(PMA_messages['strShowSearchCriteria'])
120 .bind('click', function() {
121 var $link = $(this);
122 $('#db_search_form').slideToggle();
123 if ($link.text() == PMA_messages['strHideSearchCriteria']) {
124 $link.text(PMA_messages['strShowSearchCriteria']);
125 } else {
126 $link.text(PMA_messages['strHideSearchCriteria']);
128 /** avoid default click action */
129 return false;
132 * Ajax Event handler for retrieving the result of an SQL Query
133 * (see $GLOBALS['cfg']['AjaxEnable'])
135 * @uses PMA_ajaxShowMessage()
136 * @see $GLOBALS['cfg']['AjaxEnable']
138 $("#db_search_form.ajax").live('submit', function(event) {
139 event.preventDefault();
141 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
142 // jQuery object to reuse
143 $form = $(this);
145 PMA_prepareForAjaxRequest($form);
147 $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(), function(response) {
148 if (typeof response == 'string') {
149 // found results
150 $("#searchresults").html(response);
151 $("#sqlqueryresults").trigger('appendAnchor');
152 $('#db_search_form')
153 // workaround for Chrome problem (bug #3168569)
154 .slideToggle()
155 .hide();
156 $('#togglesearchformlink')
157 // always start with the Show message
158 .text(PMA_messages['strShowSearchCriteria'])
159 $('#togglesearchformdiv')
160 // now it's time to show the div containing the link
161 .show();
162 } else {
163 // error message (zero rows)
164 $("#sqlqueryresults").html(response['message']);
167 PMA_ajaxRemoveMessage($msgbox);
170 }, 'top.frame_content'); // end $(document).ready()