Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / js / db_search.js
blob72b30463d44ec11a5e05a71063b1d96b3abe30df
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    JavaScript functions used on Database Search page
4  * @name            Database Search
5  *
6  * @requires    jQuery
7  * @requires    js/functions.js
8  */
10 /**
11  * AJAX script for the Database Search page.
12  *
13  * Actions ajaxified here:
14  * Retrieve result of SQL query
15  */
17 /** Loads the database search results */
18 function loadResult(result_path , table_name , link , ajaxEnable){
19     $(document).ready(function() {
20         if(ajaxEnable)
21         {
22             /**   Hides the results shown by the delete criteria */
23             PMA_ajaxShowMessage(PMA_messages['strBrowsing']);
24             $('#sqlqueryform').hide();
25             $('#togglequerybox').hide();
26             /**  Load the browse results to the page */
27             $("#table-info").show();
28             $('#table-link').attr({"href" : 'sql.php?'+link }).text(table_name);
29             $('#browse-results').load(result_path + " '"+'#sqlqueryresults' + "'", null, function() {
30                 // because under db_search, window.parent.table is not defined yet,
31                 // we assign it manually from #table-link
32                 window.parent.table = $('#table-link').text().trim();
34                 appendInlineAnchor();
35                 $('#table_results').makegrid();
36             }).show();
37         }
38         else
39         {
40             event.preventDefault();
41         }
42     });
45 /**  Delete the selected search results */
46 function deleteResult(result_path , msg , ajaxEnable){
47     $(document).ready(function() {
48         /**  Hides the results shown by the browse criteria */
49         $("#table-info").hide();
50         $('#browse-results').hide();
51         $('#sqlqueryform').hide();
52         $('#togglequerybox').hide();
53         /** Conformation message for deletion */
54         if(confirm(msg))
55         {
56             if(ajaxEnable)
57             {
58                 /** Load the deleted option to the page*/
59                 $('#browse-results').load(result_path + " '"+'#result_query' + "'");
60                 $('#sqlqueryform').load(result_path + " '"+'#sqlqueryform' + "'");
61                 $('#togglequerybox').html(PMA_messages['strShowQueryBox']);
63                 /** Refresh the search results after the deletion */
64                 document.getElementById('buttonGo'). click();
65                 PMA_ajaxShowMessage(PMA_messages['strDeleting']);
66                 /** Show the results of the deletion option */
67                 $('#browse-results').show();
68                 $('#sqlqueryform').hide();
69                 $('#togglequerybox').show();
70             }
71             else
72             {
73                 event.preventDefault();
74             }
75        }
76     });
79 $(document).ready(function() {
81     /**
82      * Set a parameter for all Ajax queries made on this page.  Don't let the
83      * web server serve cached pagesshow
84      */
85     $.ajaxSetup({
86         cache: 'false'
87     });
89     /** Hide the table link in the initial search result */
90     $("#table-info").prepend('<img id="table-image" class="icon ic_s_tbl" src="./themes/dot.gif" />').hide();
92     /** Hide the browse and deleted results in the new search criteria */
93     $('#buttonGo').click(function(){
94         $("#table-info").hide();
95         $('#browse-results').hide();
96         $('#sqlqueryform').hide();
97         $('#togglequerybox').hide();
98     });
99     /**
100      *Prepare a div containing a link for toggle the search results
101      */
102     $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
103     .insertAfter('#searchresults')
104     /** don't show it until we have results on-screen */
105     .hide();
107     $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
108     /** Changing the displayed text according to the hide/show criteria in search result forms*/
110     $('#togglesearchresultlink')
111     .html(PMA_messages['strHideSearchResults'])
112     .bind('click', function() {
113          var $link = $(this);
114          $('#searchresults').slideToggle();
115          if ($link.text() == PMA_messages['strHideSearchResults']) {
116              $link.text(PMA_messages['strShowSearchResults']);
117          } else {
118              $link.text(PMA_messages['strHideSearchResults']);
119          }
120          /** avoid default click action */
121          return false;
122     });
124     /**
125      * Prepare a div containing a link for toggle the search form, otherwise it's incorrectly displayed
126      * after a couple of clicks
127      */
128     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
129     .insertAfter('#db_search_form')
130     /** don't show it until we have results on-screen */
131     .hide();
133     /** Changing the displayed text according to the hide/show criteria in search form*/
134     $("#togglequerybox").hide();
135     $("#togglequerybox").bind('click', function() {
136         var $link = $(this);
137         $('#sqlqueryform').slideToggle("medium");
138         if ($link.text() == PMA_messages['strHideQueryBox']) {
139             $link.text(PMA_messages['strShowQueryBox']);
140         } else {
141             $link.text(PMA_messages['strHideQueryBox']);
142         }
143         /** avoid default click action */
144         return false;
145     });
147     /** don't show it until we have results on-screen */
149    /** Changing the displayed text according to the hide/show criteria in search criteria form*/
150    $('#togglesearchformlink')
151        .html(PMA_messages['strShowSearchCriteria'])
152        .bind('click', function() {
153             var $link = $(this);
154             $('#db_search_form').slideToggle();
155             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
156                 $link.text(PMA_messages['strShowSearchCriteria']);
157             } else {
158                 $link.text(PMA_messages['strHideSearchCriteria']);
159             }
160             /** avoid default click action */
161             return false;
162        });
163     /**
164      * Ajax Event handler for retrieving the result of an SQL Query
165      * (see $GLOBALS['cfg']['AjaxEnable'])
166      *
167      * @uses    PMA_ajaxShowMessage()
168      * @see     $GLOBALS['cfg']['AjaxEnable']
169      */
170     $("#db_search_form.ajax").live('submit', function(event) {
171         event.preventDefault();
173         var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
174         // jQuery object to reuse
175         $form = $(this);
177         PMA_prepareForAjaxRequest($form);
179         $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(),  function(response) {
180             if (typeof response == 'string') {
181                 // found results
182                 $("#searchresults").html(response);
184                 $('#togglesearchresultlink')
185                 // always start with the Show message
186                 .text(PMA_messages['strHideSearchResults'])
187                 $('#togglesearchresultsdiv')
188                 // now it's time to show the div containing the link
189                 .show();
190                 $('#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(response['message']);
206             }
208             PMA_ajaxRemoveMessage($msgbox);
209         })
210     })
211 }, 'top.frame_content'); // end $(document).ready()