Add OK and Cancel button for grid editing
[phpmyadmin/arisferyanto.git] / js / db_search.js
blobd78729088d52510147f01db5a65e5f85b6c96092
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * JavaScript functions used on Database Search page
5 * @requires jQuery
6 * @requires js/functions.js
8 * @package PhpMyAdmin
9 */
11 /**
12 * AJAX script for the Database Search page.
14 * Actions ajaxified here:
15 * Retrieve result of SQL query
18 /**
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
25 * @return nothing
27 function loadResult(result_path, table_name, link, ajaxEnable)
29 $(document).ready(function() {
30 if(ajaxEnable) {
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() {
40 $('html, body')
41 .animate({
42 scrollTop: $("#browse-results").offset().top
43 }, 1000);
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);
49 }).show();
50 } else {
51 event.preventDefault();
53 });
56 /**
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
63 * @return nothing
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 */
74 if(confirm(msg)) {
75 if(ajaxEnable) {
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();
89 });
90 } else {
91 event.preventDefault();
94 });
97 $(document).ready(function() {
98 /**
99 * Set a parameter for all Ajax queries made on this page.
100 * Don't let the web server serve cached pages
102 $.ajaxSetup({
103 cache: 'false'
106 /** Hide the table link in the initial search result */
107 var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString();
108 $("#table-info").prepend(icon).hide();
110 /** Hide the browse and deleted results in the new search criteria */
111 $('#buttonGo').click(function(){
112 $("#table-info").hide();
113 $('#browse-results').hide();
114 $('#sqlqueryform').hide();
115 $('#togglequerybox').hide();
118 * Prepare a div containing a link for toggle the search results
120 $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
121 .insertAfter('#searchresults')
122 /** don't show it until we have results on-screen */
123 .hide();
125 $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
127 * Changing the displayed text according to
128 * the hide/show criteria in search result forms
130 $('#togglesearchresultlink')
131 .html(PMA_messages['strHideSearchResults'])
132 .bind('click', function() {
133 var $link = $(this);
134 $('#searchresults').slideToggle();
135 if ($link.text() == PMA_messages['strHideSearchResults']) {
136 $link.text(PMA_messages['strShowSearchResults']);
137 } else {
138 $link.text(PMA_messages['strHideSearchResults']);
140 /** avoid default click action */
141 return false;
145 * Prepare a div containing a link for toggle the search form,
146 * otherwise it's incorrectly displayed after a couple of clicks
148 $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
149 .insertAfter('#db_search_form')
150 .hide(); // don't show it until we have results on-screen
153 * Changing the displayed text according to
154 * the hide/show criteria in search form
156 $("#togglequerybox").hide();
157 $("#togglequerybox").bind('click', function() {
158 var $link = $(this);
159 $('#sqlqueryform').slideToggle("medium");
160 if ($link.text() == PMA_messages['strHideQueryBox']) {
161 $link.text(PMA_messages['strShowQueryBox']);
162 } else {
163 $link.text(PMA_messages['strHideQueryBox']);
165 /** avoid default click action */
166 return false;
169 /** don't show it until we have results on-screen */
172 * Changing the displayed text according to
173 * the hide/show criteria in search criteria form
175 $('#togglesearchformlink')
176 .html(PMA_messages['strShowSearchCriteria'])
177 .bind('click', function() {
178 var $link = $(this);
179 $('#db_search_form').slideToggle();
180 if ($link.text() == PMA_messages['strHideSearchCriteria']) {
181 $link.text(PMA_messages['strShowSearchCriteria']);
182 } else {
183 $link.text(PMA_messages['strHideSearchCriteria']);
185 /** avoid default click action */
186 return false;
189 * Ajax Event handler for retrieving the result of an SQL Query
190 * (see $GLOBALS['cfg']['AjaxEnable'])
192 * @see $GLOBALS['cfg']['AjaxEnable']
194 $("#db_search_form.ajax").live('submit', function(event) {
195 event.preventDefault();
197 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
198 // jQuery object to reuse
199 $form = $(this);
201 PMA_prepareForAjaxRequest($form);
203 var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
204 $.post($form.attr('action'), url, function(response) {
205 if (typeof response == 'string') {
206 // found results
207 $("#searchresults").html(response);
209 $('#togglesearchresultlink')
210 // always start with the Show message
211 .text(PMA_messages['strHideSearchResults'])
212 $('#togglesearchresultsdiv')
213 // now it's time to show the div containing the link
214 .show();
215 $('#searchresults').show();
218 $('#db_search_form')
219 // workaround for Chrome problem (bug #3168569)
220 .slideToggle()
221 .hide();
222 $('#togglesearchformlink')
223 // always start with the Show message
224 .text(PMA_messages['strShowSearchCriteria'])
225 $('#togglesearchformdiv')
226 // now it's time to show the div containing the link
227 .show();
228 } else {
229 // error message (zero rows)
230 $("#sqlqueryresults").html(response['message']);
233 PMA_ajaxRemoveMessage($msgbox);
236 }, 'top.frame_content'); // end $(document).ready()