patch for Copy set of tables to new name pattern.
[phpmyadmin/dennischen.git] / js / db_search.js
blob84a3dd868fd43865701f875e60ea28717ead9960
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' + "'").show();
30         }
31         else
32         {
33             event.preventDefault();
34         }
35     });
38 /**  Delete the selected search results */
39 function deleteResult(result_path , msg , ajaxEnable){
40     $(document).ready(function() {
41         /**  Hides the results shown by the browse criteria */
42         $("#table-info").hide();
43         $('#browse-results').hide();
44         $('#sqlqueryform').hide();
45         $('#togglequerybox').hide();
46         /** Conformation message for deletion */
47         if(confirm(msg))
48         {
49             if(ajaxEnable)
50             {
51                 /** Load the deleted option to the page*/
52                 $('#browse-results').load(result_path + " '"+'#result_query' + "'");
53                 $('#sqlqueryform').load(result_path + " '"+'#sqlqueryform' + "'");
54                 $('#togglequerybox').html(PMA_messages['strHideQueryBox']);
56                 /** Refresh the search results after the deletion */
57                 document.getElementById('buttonGo'). click();
58                 //PMA_ajaxShowMessage(PMA_messages['strDeleting']);
59                 /** Show the results of the deletion option */
60                 $('#browse-results').show();
61                 $('#sqlqueryform').show();
62                 $('#togglequerybox').show();
63             }
64             else
65             {
66                 event.preventDefault();
67             }
68        }
69     });
72 $(document).ready(function() {
74     /**
75      * Set a parameter for all Ajax queries made on this page.  Don't let the
76      * web server serve cached pagesshow
77      */
78     $.ajaxSetup({
79         cache: 'false'
80     });
82     /** Hide the table link in the initial search result */
83     $("#table-info").prepend('<img id="table-image" src="./themes/original/img/s_tbl.png" />').hide();
85     /** Hide the browse and deleted results in the new search criteria */
86     $('#buttonGo').click(function(){
87         $("#table-info").hide();
88         $('#browse-results').hide();
89         $('#sqlqueryform').hide();
90         $('#togglequerybox').hide();
91     });
92     /**
93      * Prepare a div containing a link for toggle the search form, otherwise it's incorrectly displayed
94      * after a couple of clicks
95      */
96     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
97     .insertAfter('#db_search_form')
98     /** don't show it until we have results on-screen */
99     .hide();
101     /** Changing the displayed text according to the hide/show criteria in search form*/
102     $("#togglequerybox").hide();
103     $("#togglequerybox").bind('click', function() {
104         var $link = $(this)
105         $('#sqlqueryform').slideToggle("medium");
106         if ($link.text() == PMA_messages['strHideQueryBox']) {
107             $link.text(PMA_messages['strShowQueryBox']);
108         } else {
109             $link.text(PMA_messages['strHideQueryBox']);
110         }
111         /** avoid default click action */
112         return false;
113     })
115     /** don't show it until we have results on-screen */
117    /** Changing the displayed text according to the hide/show criteria in search criteria form*/
118    $('#togglesearchformlink')
119        .html(PMA_messages['strShowSearchCriteria'])
120        .bind('click', function() {
121             var $link = $(this);
122             $('#db_search_form').slideToggle();
123             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
124                 $link.text(PMA_messages['strShowSearchCriteria']);
125             } else {
126                 $link.text(PMA_messages['strHideSearchCriteria']);
127             }
128             /** avoid default click action */
129             return false;
130        });
131     /**
132      * Ajax Event handler for retrieving the result of an SQL Query
133      * (see $GLOBALS['cfg']['AjaxEnable'])
134      *
135      * @uses    PMA_ajaxShowMessage()
136      * @see     $GLOBALS['cfg']['AjaxEnable']
137      */
138     $("#db_search_form.ajax").live('submit', function(event) {
139         event.preventDefault();
141         PMA_ajaxShowMessage(PMA_messages['strSearching']);
142         // jQuery object to reuse
143         $form = $(this);
145         // add this hidden field just once
146         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
147             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
148         }
150         $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(),  function(response) {
151             if (typeof response == 'string') {
152                 // found results
153                 $("#searchresults").html(response);
154                 $("#sqlqueryresults").trigger('appendAnchor');
155                 $('#db_search_form')
156                     // workaround for Chrome problem (bug #3168569)
157                     .slideToggle()
158                     .hide();
159                 $('#togglesearchformlink')
160                     // always start with the Show message
161                     .text(PMA_messages['strShowSearchCriteria'])
162                 $('#togglesearchformdiv')
163                     // now it's time to show the div containing the link
164                     .show();
165             } else {
166                 // error message (zero rows)
167                 $("#sqlqueryresults").html(response['message']);
168             }
169         })
170     })
171 }, 'top.frame_content'); // end $(document).ready()