Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / js / db_search.js
blobaef5047be2ea7cd2b3549822e160bc6d99453d95
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)
20     $(document).ready(function() {
21         if(ajaxEnable)
22         {
23             /**   Hides the results shown by the delete criteria */
24             PMA_ajaxShowMessage(PMA_messages['strBrowsing']);
25             $('#sqlqueryform').hide();
26             $('#togglequerybox').hide();
27             /**  Load the browse results to the page */
28             $("#table-info").show();
29             $('#table-link').attr({"href" : 'sql.php?'+link }).text(table_name);
30             $('#browse-results').load(result_path + " '"+'#sqlqueryresults' + "'", null, function() {
31                 // because under db_search, window.parent.table is not defined yet,
32                 // we assign it manually from #table-link
33                 window.parent.table = $('#table-link').text().trim();
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)
48     $(document).ready(function() {
49         /**  Hides the results shown by the browse criteria */
50         $("#table-info").hide();
51         $('#browse-results').hide();
52         $('#sqlqueryform').hide();
53         $('#togglequerybox').hide();
54         /** Conformation message for deletion */
55         if(confirm(msg))
56         {
57             if(ajaxEnable)
58             {
59                 /** Load the deleted option to the page*/
60                 $('#browse-results').load(result_path + " '"+'#result_query' + "'");
61                 $('#sqlqueryform').load(result_path + " '"+'#sqlqueryform' + "'");
62                 $('#togglequerybox').html(PMA_messages['strShowQueryBox']);
64                 /** Refresh the search results after the deletion */
65                 document.getElementById('buttonGo'). click();
66                 PMA_ajaxShowMessage(PMA_messages['strDeleting']);
67                 /** Show the results of the deletion option */
68                 $('#browse-results').show();
69                 $('#sqlqueryform').hide();
70                 $('#togglequerybox').show();
71             }
72             else
73             {
74                 event.preventDefault();
75             }
76        }
77     });
80 $(document).ready(function() {
82     /**
83      * Set a parameter for all Ajax queries made on this page.  Don't let the
84      * web server serve cached pagesshow
85      */
86     $.ajaxSetup({
87         cache: 'false'
88     });
90     /** Hide the table link in the initial search result */
91     $("#table-info").prepend('<img id="table-image" class="icon ic_s_tbl" src="./themes/dot.gif" />').hide();
93     /** Hide the browse and deleted results in the new search criteria */
94     $('#buttonGo').click(function(){
95         $("#table-info").hide();
96         $('#browse-results').hide();
97         $('#sqlqueryform').hide();
98         $('#togglequerybox').hide();
99     });
100     /**
101      *Prepare a div containing a link for toggle the search results
102      */
103     $('<div id="togglesearchresultsdiv"><a id="togglesearchresultlink"></a></div>')
104     .insertAfter('#searchresults')
105     /** don't show it until we have results on-screen */
106     .hide();
108     $('<br class="clearfloat" />').insertAfter("#togglesearchresultsdiv").show();
109     /** Changing the displayed text according to the hide/show criteria in search result forms*/
111     $('#togglesearchresultlink')
112     .html(PMA_messages['strHideSearchResults'])
113     .bind('click', function() {
114          var $link = $(this);
115          $('#searchresults').slideToggle();
116          if ($link.text() == PMA_messages['strHideSearchResults']) {
117              $link.text(PMA_messages['strShowSearchResults']);
118          } else {
119              $link.text(PMA_messages['strHideSearchResults']);
120          }
121          /** avoid default click action */
122          return false;
123     });
125     /**
126      * Prepare a div containing a link for toggle the search form, otherwise it's incorrectly displayed
127      * after a couple of clicks
128      */
129     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
130     .insertAfter('#db_search_form')
131     /** don't show it until we have results on-screen */
132     .hide();
134     /** Changing the displayed text according to the hide/show criteria in search form*/
135     $("#togglequerybox").hide();
136     $("#togglequerybox").bind('click', function() {
137         var $link = $(this);
138         $('#sqlqueryform').slideToggle("medium");
139         if ($link.text() == PMA_messages['strHideQueryBox']) {
140             $link.text(PMA_messages['strShowQueryBox']);
141         } else {
142             $link.text(PMA_messages['strHideQueryBox']);
143         }
144         /** avoid default click action */
145         return false;
146     });
148     /** don't show it until we have results on-screen */
150    /** Changing the displayed text according to the hide/show criteria in search criteria form*/
151    $('#togglesearchformlink')
152        .html(PMA_messages['strShowSearchCriteria'])
153        .bind('click', function() {
154             var $link = $(this);
155             $('#db_search_form').slideToggle();
156             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
157                 $link.text(PMA_messages['strShowSearchCriteria']);
158             } else {
159                 $link.text(PMA_messages['strHideSearchCriteria']);
160             }
161             /** avoid default click action */
162             return false;
163        });
164     /**
165      * Ajax Event handler for retrieving the result of an SQL Query
166      * (see $GLOBALS['cfg']['AjaxEnable'])
167      *
168      * @uses    PMA_ajaxShowMessage()
169      * @see     $GLOBALS['cfg']['AjaxEnable']
170      */
171     $("#db_search_form.ajax").live('submit', function(event) {
172         event.preventDefault();
174         var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
175         // jQuery object to reuse
176         $form = $(this);
178         PMA_prepareForAjaxRequest($form);
180         $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(),  function(response) {
181             if (typeof response == 'string') {
182                 // found results
183                 $("#searchresults").html(response);
185                 $('#togglesearchresultlink')
186                 // always start with the Show message
187                 .text(PMA_messages['strHideSearchResults'])
188                 $('#togglesearchresultsdiv')
189                 // now it's time to show the div containing the link
190                 .show();
191                 $('#searchresults').show();
194                 $('#db_search_form')
195                     // workaround for Chrome problem (bug #3168569)
196                     .slideToggle()
197                     .hide();
198                 $('#togglesearchformlink')
199                     // always start with the Show message
200                     .text(PMA_messages['strShowSearchCriteria'])
201                 $('#togglesearchformdiv')
202                     // now it's time to show the div containing the link
203                     .show();
204             } else {
205                 // error message (zero rows)
206                 $("#sqlqueryresults").html(response['message']);
207             }
209             PMA_ajaxRemoveMessage($msgbox);
210         })
211     })
212 }, 'top.frame_content'); // end $(document).ready()