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