Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / js / server_status_variables.js
blob0b006c70b34350c0dee20fbab2a4dbb86fb1e821
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  *
4  *
5  * @package PhpMyAdmin
6  */
8 /**
9  * Unbind all event handlers before tearing down a page
10  */
11 AJAX.registerTeardown('server_status_variables.js', function () {
12     $('#filterAlert').unbind('change');
13     $('#filterText').unbind('keyup');
14     $('#filterCategory').unbind('change');
15     $('#dontFormat').unbind('change');
16 });
18 AJAX.registerOnload('server_status_variables.js', function () {
19     /*** Table sort tooltip ***/
20     PMA_tooltip(
21         $('table.sortable>thead>tr:first').find('th'),
22         'th',
23         PMA_messages.strSortHint
24     );
25     initTableSorter('statustabs_allvars');
27     // Filters for status variables
28     var textFilter = null;
29     var alertFilter = $('#filterAlert').prop('checked');
30     var categoryFilter = $('#filterCategory').find(':selected').val();
31     var odd_row = false;
32     var text = ''; // Holds filter text
34     /* 3 Filtering functions */
35     $('#filterAlert').change(function () {
36         alertFilter = this.checked;
37         filterVariables();
38     });
40     $('#filterCategory').change(function () {
41         categoryFilter = $(this).val();
42         filterVariables();
43     });
45     $('#dontFormat').change(function () {
46         // Hiding the table while changing values speeds up the process a lot
47         $('#serverstatusvariables').hide();
48         $('#serverstatusvariables td.value span.original').toggle(this.checked);
49         $('#serverstatusvariables td.value span.formatted').toggle(! this.checked);
50         $('#serverstatusvariables').show();
51     }).trigger('change');
53     $('#filterText').keyup(function (e) {
54         var word = $(this).val().replace(/_/g, ' ');
55         if (word.length === 0) {
56             textFilter = null;
57         } else {
58             textFilter = new RegExp("(^| )" + word, 'i');
59         }
60         text = word;
61         filterVariables();
62     }).trigger('keyup');
64     /* Filters the status variables by name/category/alert in the variables tab */
65     function filterVariables() {
66         var useful_links = 0;
67         var section = text;
69         if (categoryFilter.length > 0) {
70             section = categoryFilter;
71         }
73         if (section.length > 1) {
74             $('#linkSuggestions span').each(function () {
75                 if ($(this).attr('class').indexOf('status_' + section) != -1) {
76                     useful_links++;
77                     $(this).css('display', '');
78                 } else {
79                     $(this).css('display', 'none');
80                 }
81             });
82         }
84         if (useful_links > 0) {
85             $('#linkSuggestions').css('display', '');
86         } else {
87             $('#linkSuggestions').css('display', 'none');
88         }
90         odd_row = false;
91         $('#serverstatusvariables th.name').each(function () {
92             if ((textFilter === null || textFilter.exec($(this).text()))
93                 && (! alertFilter || $(this).next().find('span.attention').length > 0)
94                 && (categoryFilter.length === 0 || $(this).parent().hasClass('s_' + categoryFilter))
95             ) {
96                 odd_row = ! odd_row;
97                 $(this).parent().css('display', '');
98                 if (odd_row) {
99                     $(this).parent().addClass('odd');
100                     $(this).parent().removeClass('even');
101                 } else {
102                     $(this).parent().addClass('even');
103                     $(this).parent().removeClass('odd');
104                 }
105             } else {
106                 $(this).parent().css('display', 'none');
107             }
108         });
109     }