added japanese language
[openemr.git] / phpmyadmin / js / db_search.js
blobd5eb449dc5a9dda6421f79d5af0dfcdf42b7be83
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     $("#db_search_form.ajax").die('submit');
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 + "#sqlqueryresults";
48         $.get(url, {'ajax_request': true, 'is_js_confirmed': true}, function (data) {
49             if (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                 PMA_makegrid($('#table_results')[0], true, true, true, true);
57                 $('#browse-results').show();
58             } else {
59                 PMA_ajaxShowMessage(data.error, false);
60             }
61         });
62     });
65 /**
66  *  Delete the selected search results
67  *
68  * @param result_path Url of the page to load
69  * @param msg         Text for the confirmation dialog
70  *
71  * @return nothing
72  */
73 function deleteResult(result_path, msg)
75     $(function () {
76         /**  Hides the results shown by the browse criteria */
77         $("#table-info").hide();
78         $('#sqlqueryform').hide();
79         $('#togglequerybox').hide();
80         /** Conformation message for deletion */
81         if (confirm(msg)) {
82             var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false);
83             /** Load the deleted option to the page*/
84             $('#sqlqueryform').html('');
85             var url = result_path + "#result_query, #sqlqueryform";
86             $.get(url, {'ajax_request': true, 'is_js_confirmed': true},
87                 function (data) {
88             if (data.success) {
89                 $('#sqlqueryform').html(data.sql_query);
90                 /** Refresh the search results after the deletion */
91                 document.getElementById('buttonGo').click();
92                 $('#togglequerybox').html(PMA_messages.strHideQueryBox);
93                 /** Show the results of the deletion option */
94                 $('#browse-results').hide();
95                 $('#sqlqueryform').show();
96                 $('#togglequerybox').show();
97                 $('html, body')
98                     .animate({
99                         scrollTop: $("#browse-results").offset().top
100                     }, 1000);
101                 PMA_ajaxRemoveMessage($msg);
102             } else {
103                 PMA_ajaxShowMessage(data.error, false);
104             }
105          });
106         }
107     });
110 AJAX.registerOnload('db_search.js', function () {
111     /** Hide the table link in the initial search result */
112     var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString();
113     $("#table-info").prepend(icon).hide();
115     /** Hide the browse and deleted results in the new search criteria */
116     $('#buttonGo').click(function () {
117         $("#table-info").hide();
118         $('#browse-results').hide();
119         $('#sqlqueryform').hide();
120         $('#togglequerybox').hide();
121     });
122     /**
123      * Prepare a div containing a link for toggle the search results
124      */
125     $('#togglesearchresultsdiv')
126     /** don't show it until we have results on-screen */
127     .hide();
129     /**
130      * Changing the displayed text according to
131      * the hide/show criteria in search result forms
132      */
133     $('#togglesearchresultlink')
134     .html(PMA_messages.strHideSearchResults)
135     .bind('click', function () {
136         var $link = $(this);
137         $('#searchresults').slideToggle();
138         if ($link.text() == PMA_messages.strHideSearchResults) {
139             $link.text(PMA_messages.strShowSearchResults);
140         } else {
141             $link.text(PMA_messages.strHideSearchResults);
142         }
143         /** avoid default click action */
144         return false;
145     });
147     /**
148      * Prepare a div containing a link for toggle the search form,
149      * otherwise it's incorrectly displayed after a couple of clicks
150      */
151     $('#togglesearchformdiv')
152     .hide(); // don't show it until we have results on-screen
154     /**
155      * Changing the displayed text according to
156      * the hide/show criteria in search form
157      */
158     $("#togglequerybox")
159     .hide()
160     .bind('click', function () {
161         var $link = $(this);
162         $('#sqlqueryform').slideToggle("medium");
163         if ($link.text() == PMA_messages.strHideQueryBox) {
164             $link.text(PMA_messages.strShowQueryBox);
165         } else {
166             $link.text(PMA_messages.strHideQueryBox);
167         }
168         /** avoid default click action */
169         return false;
170     });
172     /** don't show it until we have results on-screen */
174     /**
175      * Changing the displayed text according to
176      * the hide/show criteria in search criteria form
177      */
178     $('#togglesearchformlink')
179        .html(PMA_messages.strShowSearchCriteria)
180        .bind('click', function () {
181             var $link = $(this);
182             $('#db_search_form').slideToggle();
183             if ($link.text() == PMA_messages.strHideSearchCriteria) {
184                 $link.text(PMA_messages.strShowSearchCriteria);
185             } else {
186                 $link.text(PMA_messages.strHideSearchCriteria);
187             }
188             /** avoid default click action */
189             return false;
190         });
191     /**
192      * Ajax Event handler for retrieving the result of an SQL Query
193      */
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         var $form = $(this);
201         PMA_prepareForAjaxRequest($form);
203         var url = $form.serialize() + "&submit_search=" + $("#buttonGo").val();
204         $.post($form.attr('action'), url, function (data) {
205             if (data.success === true) {
206                 // found results
207                 $("#searchresults").html(data.message);
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(data.error);
231             }
233             PMA_ajaxRemoveMessage($msgbox);
234         });
235     });
236 }); // end $()