Translation update done using Pootle.
[phpmyadmin-themes.git] / js / db_search.js
blob0a82a8f7b2968cf6a6a9d279b72c8ed67b9fc310
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 $(document).ready(function() {
19     /**
20      * Set a parameter for all Ajax queries made on this page.  Don't let the
21      * web server serve cached pages
22      */
23     $.ajaxSetup({
24         cache: 'false'
25     });
27     /**
28      * Prepare a div containing a link, otherwise it's incorrectly displayed 
29      * after a couple of clicks
30      */
31     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
32     .insertAfter('#db_search_form')
33     // don't show it until we have results on-screen
34     .hide();
36    $('#togglesearchformlink')
37        .html(PMA_messages['strShowSearchCriteria'])
38        .bind('click', function() {
39             var $link = $(this);
40             $('#db_search_form').slideToggle();
41             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
42                 $link.text(PMA_messages['strShowSearchCriteria']);
43             } else {
44                 $link.text(PMA_messages['strHideSearchCriteria']);
45             }
46             // avoid default click action
47             return false;
48        });
49     /**
50      * Ajax Event handler for retrieving the result of an SQL Query
51      * (see $GLOBALS['cfg']['AjaxEnable'])
52      *
53      * @uses    PMA_ajaxShowMessage()
54      * @see     $GLOBALS['cfg']['AjaxEnable']
55      */
56     $("#db_search_form.ajax").live('submit', function(event) {
57         event.preventDefault();
59         PMA_ajaxShowMessage(PMA_messages['strSearching']);
60         // jQuery object to reuse
61         $form = $(this);
62         
63         // add this hidden field just once 
64         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
65             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
66         }
68         $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(),  function(response) {
69             if (typeof response == 'string') {
70                 // found results
71                 $("#searchresults").html(response);
72                 $("#sqlqueryresults").trigger('appendAnchor');
73                 $('#db_search_form')
74                     // workaround for Chrome problem (bug #3168569)
75                     .slideToggle()
76                     .hide();
77                 $('#togglesearchformlink')
78                     // always start with the Show message
79                     .text(PMA_messages['strShowSearchCriteria'])
80                 $('#togglesearchformdiv')
81                     // now it's time to show the div containing the link 
82                     .show();
83             } else {
84                 // error message (zero rows)
85                 $("#sqlqueryresults").html(response['message']);
86             }            
87         })
88     })
89 }, 'top.frame_content'); // end $(document).ready()