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