forked from phpmyadmin/phpmyadmin
/
tbl_select.js
98 lines (87 loc) · 3.01 KB
/
tbl_select.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @fileoverview JavaScript functions used on tbl_select.php
*
* @requires jQuery
* @requires js/functions.js
*/
/**
* Ajax event handlers for this page
*
* Actions ajaxified here:
* Table Search
*/
$(document).ready(function() {
/**
* Set a parameter for all Ajax queries made on this page. Don't let the
* web server serve cached pages
*/
$.ajaxSetup({
cache: 'false'
});
/**
* Attach the {@link appendInlineAnchor} function to a custom event, which
* will be triggered manually everytime the table of results is reloaded;
*
* Needs appendInlineAnchor() which is defined in sql.js
* @memberOf jQuery
*/
$("#searchresults").live('appendAnchor',function() {
appendInlineAnchor();
})
/**
* Trigger the appendAnchor event to prepare the first table for inline edit
*
* @memberOf jQuery
*/
$("#searchresults").trigger('appendAnchor');
$('<a id="togglesearchform"></a>')
.html(PMA_messages['strShowSearchCriteria'])
.insertAfter('#tbl_search_form')
// don't show it until we have results on-screen
.hide();
$('#togglesearchform').bind('click', function() {
var $link = $(this);
$('#tbl_search_form').slideToggle();
if ($link.text() == PMA_messages['strHideSearchCriteria']) {
$link.text(PMA_messages['strShowSearchCriteria']);
} else {
$link.text(PMA_messages['strHideSearchCriteria']);
}
// avoid default click action
return false;
})
/**
* Ajax event handler for Table Search
*
* @uses PMA_ajaxShowMessage()
*/
$("#tbl_search_form").live('submit', function(event) {
// jQuery object to reuse
$search_form = $(this);
event.preventDefault();
// empty previous search results while we are waiting for new results
$("#searchresults").empty();
PMA_ajaxShowMessage(PMA_messages['strSearching']);
// add this hidden field just once
if (! $search_form.find('input:hidden').is('#ajax_request_hidden')) {
$search_form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($search_form.attr('action'), $search_form.serialize(), function(response) {
if (typeof response == 'string') {
// found results
$("#searchresults").html(response);
$("#searchresults").trigger('appendAnchor');
$('#tbl_search_form').hide();
$('#togglesearchform')
// always start with the Show message
.text(PMA_messages['strShowSearchCriteria'])
// now it's time to show the link
.show();
} else {
// error message (zero rows)
$("#searchresults").html(response['message']);
}
})
})
}, 'top.frame_content'); // end $(document).ready()