db_search.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. $.get(url, {'ajax_request': true, 'is_js_confirmed': true}, function (data) {
  46. if (data.success) {
  47. $('#browse-results').html(data.message);
  48. $('html, body')
  49. .animate({
  50. scrollTop: $("#browse-results").offset().top
  51. }, 1000);
  52. PMA_ajaxRemoveMessage($msg);
  53. PMA_makegrid($('#table_results')[0], true, true, true, true);
  54. $('#browse-results').show();
  55. } else {
  56. PMA_ajaxShowMessage(data.error, false);
  57. }
  58. });
  59. });
  60. }
  61. /**
  62. * Delete the selected search results
  63. *
  64. * @param result_path Url of the page to load
  65. * @param msg Text for the confirmation dialog
  66. *
  67. * @return nothing
  68. */
  69. function deleteResult(result_path, msg)
  70. {
  71. $(function () {
  72. /** Hides the results shown by the browse criteria */
  73. $("#table-info").hide();
  74. $('#sqlqueryform').hide();
  75. $('#togglequerybox').hide();
  76. /** Conformation message for deletion */
  77. if (confirm(msg)) {
  78. var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false);
  79. /** Load the deleted option to the page*/
  80. $('#sqlqueryform').html('');
  81. var url = result_path + "#result_query, #sqlqueryform";
  82. $.get(url, {'ajax_request': true, 'is_js_confirmed': true},
  83. function (data) {
  84. if (data.success) {
  85. $('#sqlqueryform').html(data.sql_query);
  86. /** Refresh the search results after the deletion */
  87. document.getElementById('buttonGo').click();
  88. $('#togglequerybox').html(PMA_messages.strHideQueryBox);
  89. /** Show the results of the deletion option */
  90. $('#browse-results').hide();
  91. $('#sqlqueryform').show();
  92. $('#togglequerybox').show();
  93. $('html, body')
  94. .animate({
  95. scrollTop: $("#browse-results").offset().top
  96. }, 1000);
  97. PMA_ajaxRemoveMessage($msg);
  98. } else {
  99. PMA_ajaxShowMessage(data.error, false);
  100. }
  101. });
  102. }
  103. });
  104. }
  105. AJAX.registerOnload('db_search.js', function () {
  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();
  109. /** Hide the browse and deleted results in the new search criteria */
  110. $('#buttonGo').click(function () {
  111. $("#table-info").hide();
  112. $('#browse-results').hide();
  113. $('#sqlqueryform').hide();
  114. $('#togglequerybox').hide();
  115. });
  116. /**
  117. * Prepare a div containing a link for toggle the search results
  118. */
  119. $('#togglesearchresultsdiv')
  120. /** don't show it until we have results on-screen */
  121. .hide();
  122. /**
  123. * Changing the displayed text according to
  124. * the hide/show criteria in search result forms
  125. */
  126. $('#togglesearchresultlink')
  127. .html(PMA_messages.strHideSearchResults)
  128. .bind('click', function () {
  129. var $link = $(this);
  130. $('#searchresults').slideToggle();
  131. if ($link.text() == PMA_messages.strHideSearchResults) {
  132. $link.text(PMA_messages.strShowSearchResults);
  133. } else {
  134. $link.text(PMA_messages.strHideSearchResults);
  135. }
  136. /** avoid default click action */
  137. return false;
  138. });
  139. /**
  140. * Prepare a div containing a link for toggle the search form,
  141. * otherwise it's incorrectly displayed after a couple of clicks
  142. */
  143. $('#togglesearchformdiv')
  144. .hide(); // don't show it until we have results on-screen
  145. /**
  146. * Changing the displayed text according to
  147. * the hide/show criteria in search form
  148. */
  149. $("#togglequerybox")
  150. .hide()
  151. .bind('click', function () {
  152. var $link = $(this);
  153. $('#sqlqueryform').slideToggle("medium");
  154. if ($link.text() == PMA_messages.strHideQueryBox) {
  155. $link.text(PMA_messages.strShowQueryBox);
  156. } else {
  157. $link.text(PMA_messages.strHideQueryBox);
  158. }
  159. /** avoid default click action */
  160. return false;
  161. });
  162. /** don't show it until we have results on-screen */
  163. /**
  164. * Changing the displayed text according to
  165. * the hide/show criteria in search criteria form
  166. */
  167. $('#togglesearchformlink')
  168. .html(PMA_messages.strShowSearchCriteria)
  169. .bind('click', function () {
  170. var $link = $(this);
  171. $('#db_search_form').slideToggle();
  172. if ($link.text() == PMA_messages.strHideSearchCriteria) {
  173. $link.text(PMA_messages.strShowSearchCriteria);
  174. } else {
  175. $link.text(PMA_messages.strHideSearchCriteria);
  176. }
  177. /** avoid default click action */
  178. return false;
  179. });
  180. /**
  181. * Ajax Event handler for retrieving the result of an SQL Query
  182. */
  183. $("#db_search_form.ajax").live('submit', function (event) {
  184. event.preventDefault();
  185. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strSearching, false);
  186. // jQuery object to reuse
  187. var $form = $(this);
  188. PMA_prepareForAjaxRequest($form);
  189. var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
  190. $.post($form.attr('action'), url, function (data) {
  191. if (data.success === true) {
  192. // found results
  193. $("#searchresults").html(data.message);
  194. $('#togglesearchresultlink')
  195. // always start with the Show message
  196. .text(PMA_messages.strHideSearchResults);
  197. $('#togglesearchresultsdiv')
  198. // now it's time to show the div containing the link
  199. .show();
  200. $('#searchresults').show();
  201. $('#db_search_form')
  202. // workaround for Chrome problem (bug #3168569)
  203. .slideToggle()
  204. .hide();
  205. $('#togglesearchformlink')
  206. // always start with the Show message
  207. .text(PMA_messages.strShowSearchCriteria);
  208. $('#togglesearchformdiv')
  209. // now it's time to show the div containing the link
  210. .show();
  211. } else {
  212. // error message (zero rows)
  213. $("#sqlqueryresults").html(data.error);
  214. }
  215. PMA_ajaxRemoveMessage($msgbox);
  216. });
  217. });
  218. }); // end $()