db_search.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * JavaScript functions used on Database Search page
  4. *
  5. * @requires jQuery
  6. * @requires js/functions.js
  7. *
  8. * @package PhpMyAdmin
  9. */
  10. /**
  11. * AJAX script for the Database Search page.
  12. *
  13. * Actions ajaxified here:
  14. * Retrieve result of SQL query
  15. */
  16. /**
  17. * Unbind all event handlers before tearing down a page
  18. */
  19. AJAX.registerTeardown('db_search.js', function() {
  20. $('#buttonGo').unbind('click');
  21. $('#togglesearchresultlink').unbind('click');
  22. $("#togglequerybox").unbind('click');
  23. $('#togglesearchformlink').unbind('click');
  24. $("#db_search_form.ajax").die('submit');
  25. });
  26. /**
  27. * Loads the database search results
  28. *
  29. * @param result_path Url of the page to load
  30. * @param table_name Name of table to browse
  31. *
  32. * @return nothing
  33. */
  34. function loadResult(result_path, table_name, link)
  35. {
  36. $(function() {
  37. /** Hides the results shown by the delete criteria */
  38. var $msg = PMA_ajaxShowMessage(PMA_messages['strBrowsing'], false);
  39. $('#sqlqueryform').hide();
  40. $('#togglequerybox').hide();
  41. /** Load the browse results to the page */
  42. $("#table-info").show();
  43. $('#table-link').attr({"href" : 'sql.php?'+link }).text(table_name);
  44. var url = result_path + " #sqlqueryresults";
  45. $('#browse-results').load(url, null, function() {
  46. $('html, body')
  47. .animate({
  48. scrollTop: $("#browse-results").offset().top
  49. }, 1000);
  50. PMA_ajaxRemoveMessage($msg);
  51. PMA_makegrid($('#table_results')[0], true, true, true, true);
  52. }).show();
  53. });
  54. }
  55. /**
  56. * Delete the selected search results
  57. *
  58. * @param result_path Url of the page to load
  59. * @param msg Text for the confirmation dialog
  60. *
  61. * @return nothing
  62. */
  63. function deleteResult(result_path, msg)
  64. {
  65. $(function() {
  66. /** Hides the results shown by the browse criteria */
  67. $("#table-info").hide();
  68. $('#browse-results').hide();
  69. $('#sqlqueryform').hide();
  70. $('#togglequerybox').hide();
  71. /** Conformation message for deletion */
  72. if (confirm(msg)) {
  73. var $msg = PMA_ajaxShowMessage(PMA_messages['strDeleting'], false);
  74. /** Load the deleted option to the page*/
  75. $('#sqlqueryform').html('');
  76. var url = result_path + " #result_query, #sqlqueryform";
  77. $('#browse-results').load(url, function () {
  78. /** Refresh the search results after the deletion */
  79. document.getElementById('buttonGo').click();
  80. $('#togglequerybox').html(PMA_messages['strHideQueryBox']);
  81. /** Show the results of the deletion option */
  82. $('#browse-results').show();
  83. $('#sqlqueryform').show();
  84. $('#togglequerybox').show();
  85. $('html, body')
  86. .animate({
  87. scrollTop: $("#browse-results").offset().top
  88. }, 1000);
  89. PMA_ajaxRemoveMessage($msg);
  90. });
  91. }
  92. });
  93. }
  94. AJAX.registerOnload('db_search.js', function() {
  95. /** Hide the table link in the initial search result */
  96. var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString();
  97. $("#table-info").prepend(icon).hide();
  98. /** Hide the browse and deleted results in the new search criteria */
  99. $('#buttonGo').click(function(){
  100. $("#table-info").hide();
  101. $('#browse-results').hide();
  102. $('#sqlqueryform').hide();
  103. $('#togglequerybox').hide();
  104. });
  105. /**
  106. * Prepare a div containing a link for toggle the search results
  107. */
  108. $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
  109. .insertAfter('#searchresults')
  110. /** don't show it until we have results on-screen */
  111. .hide();
  112. $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
  113. /**
  114. * Changing the displayed text according to
  115. * the hide/show criteria in search result forms
  116. */
  117. $('#togglesearchresultlink')
  118. .html(PMA_messages['strHideSearchResults'])
  119. .bind('click', function() {
  120. var $link = $(this);
  121. $('#searchresults').slideToggle();
  122. if ($link.text() == PMA_messages['strHideSearchResults']) {
  123. $link.text(PMA_messages['strShowSearchResults']);
  124. } else {
  125. $link.text(PMA_messages['strHideSearchResults']);
  126. }
  127. /** avoid default click action */
  128. return false;
  129. });
  130. /**
  131. * Prepare a div containing a link for toggle the search form,
  132. * otherwise it's incorrectly displayed after a couple of clicks
  133. */
  134. $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
  135. .insertAfter('#db_search_form')
  136. .hide(); // don't show it until we have results on-screen
  137. /**
  138. * Changing the displayed text according to
  139. * the hide/show criteria in search form
  140. */
  141. $("#togglequerybox")
  142. .hide()
  143. .bind('click', function() {
  144. var $link = $(this);
  145. $('#sqlqueryform').slideToggle("medium");
  146. if ($link.text() == PMA_messages['strHideQueryBox']) {
  147. $link.text(PMA_messages['strShowQueryBox']);
  148. } else {
  149. $link.text(PMA_messages['strHideQueryBox']);
  150. }
  151. /** avoid default click action */
  152. return false;
  153. });
  154. /** don't show it until we have results on-screen */
  155. /**
  156. * Changing the displayed text according to
  157. * the hide/show criteria in search criteria form
  158. */
  159. $('#togglesearchformlink')
  160. .html(PMA_messages['strShowSearchCriteria'])
  161. .bind('click', function() {
  162. var $link = $(this);
  163. $('#db_search_form').slideToggle();
  164. if ($link.text() == PMA_messages['strHideSearchCriteria']) {
  165. $link.text(PMA_messages['strShowSearchCriteria']);
  166. } else {
  167. $link.text(PMA_messages['strHideSearchCriteria']);
  168. }
  169. /** avoid default click action */
  170. return false;
  171. });
  172. /**
  173. * Ajax Event handler for retrieving the result of an SQL Query
  174. */
  175. $("#db_search_form.ajax").live('submit', function(event) {
  176. event.preventDefault();
  177. var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
  178. // jQuery object to reuse
  179. var $form = $(this);
  180. PMA_prepareForAjaxRequest($form);
  181. var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
  182. $.post($form.attr('action'), url, function(data) {
  183. if (data.success == true) {
  184. // found results
  185. $("#searchresults").html(data.message);
  186. $('#togglesearchresultlink')
  187. // always start with the Show message
  188. .text(PMA_messages['strHideSearchResults']);
  189. $('#togglesearchresultsdiv')
  190. // now it's time to show the div containing the link
  191. .show();
  192. $('#searchresults').show();
  193. $('#db_search_form')
  194. // workaround for Chrome problem (bug #3168569)
  195. .slideToggle()
  196. .hide();
  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
  202. .show();
  203. } else {
  204. // error message (zero rows)
  205. $("#sqlqueryresults").html(data.error);
  206. }
  207. PMA_ajaxRemoveMessage($msgbox);
  208. })
  209. })
  210. }); // end $()