Translated using Weblate (Czech)
[phpmyadmin.git] / js / server_status_variables.js
blob4028bc75d65c5aa1914f50167470a2f8a3118087
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').off('change');
13     $('#filterText').off('keyup');
14     $('#filterCategory').off('change');
15     $('#dontFormat').off('change');
16 });
18 AJAX.registerOnload('server_status_variables.js', function () {
19     // Filters for status variables
20     var textFilter = null;
21     var alertFilter = $('#filterAlert').prop('checked');
22     var categoryFilter = $('#filterCategory').find(':selected').val();
23     var text = ''; // Holds filter text
25     /* 3 Filtering functions */
26     $('#filterAlert').change(function () {
27         alertFilter = this.checked;
28         filterVariables();
29     });
31     $('#filterCategory').change(function () {
32         categoryFilter = $(this).val();
33         filterVariables();
34     });
36     $('#dontFormat').change(function () {
37         // Hiding the table while changing values speeds up the process a lot
38         $('#serverstatusvariables').hide();
39         $('#serverstatusvariables').find('td.value span.original').toggle(this.checked);
40         $('#serverstatusvariables').find('td.value span.formatted').toggle(! this.checked);
41         $('#serverstatusvariables').show();
42     }).trigger('change');
44     $('#filterText').keyup(function (e) {
45         var word = $(this).val().replace(/_/g, ' ');
46         if (word.length === 0) {
47             textFilter = null;
48         } else {
49             try {
50                 textFilter = new RegExp('(^| )' + word, 'i');
51                 $(this).removeClass('error');
52             } catch (e) {
53                 if (e instanceof SyntaxError) {
54                     $(this).addClass('error');
55                     textFilter = null;
56                 }
57             }
58         }
59         text = word;
60         filterVariables();
61     }).trigger('keyup');
63     /* Filters the status variables by name/category/alert in the variables tab */
64     function filterVariables () {
65         var useful_links = 0;
66         var section = text;
68         if (categoryFilter.length > 0) {
69             section = categoryFilter;
70         }
72         if (section.length > 1) {
73             $('#linkSuggestions').find('span').each(function () {
74                 if ($(this).attr('class').indexOf('status_' + section) !== -1) {
75                     useful_links++;
76                     $(this).css('display', '');
77                 } else {
78                     $(this).css('display', 'none');
79                 }
80             });
81         }
83         if (useful_links > 0) {
84             $('#linkSuggestions').css('display', '');
85         } else {
86             $('#linkSuggestions').css('display', 'none');
87         }
89         $('#serverstatusvariables').find('th.name').each(function () {
90             if ((textFilter === null || textFilter.exec($(this).text())) &&
91                 (! alertFilter || $(this).next().find('span.attention').length > 0) &&
92                 (categoryFilter.length === 0 || $(this).parent().hasClass('s_' + categoryFilter))
93             ) {
94                 $(this).parent().css('display', '');
95             } else {
96                 $(this).parent().css('display', 'none');
97             }
98         });
99     }