Translated using Weblate (Slovenian)
[phpmyadmin.git] / js / server_status_processes.js
blob017735fcfb03bc8bbb5b21654c0167227bf64987
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * Server Status Processes
4  *
5  * @package PhpMyAdmin
6  */
8 // object to store process list state information
9 var processList = {
11     // denotes whether auto refresh is on or off
12     autoRefresh: false,
13     // stores the GET request which refresh process list
14     refreshRequest: null,
15     // stores the timeout id returned by setTimeout
16     refreshTimeout: null,
17     // the refresh interval in seconds
18     refreshInterval: null,
19     // the refresh URL (required to save last used option)
20     // i.e. full or sorting url
21     refreshUrl: null,
23     /**
24      * Handles killing of a process
25      *
26      * @return void
27      */
28     init: function() {
29         processList.setRefreshLabel();
30         if (processList.refreshUrl === null) {
31             processList.refreshUrl = 'server_status_processes.php' +
32                 PMA_commonParams.get('common_query');
33         }
34         if (processList.refreshInterval === null) {
35             processList.refreshInterval = $('#id_refreshRate').val();
36         } else {
37             $('#id_refreshRate').val(processList.refreshInterval);
38         }
39     },
41     /**
42      * Handles killing of a process
43      *
44      * @param object the event object
45      *
46      * @return void
47      */
48     killProcessHandler: function(event) {
49         event.preventDefault();
50         var url = $(this).attr('href');
51         // Get row element of the process to be killed.
52         var $tr = $(this).closest('tr');
53         $.getJSON(url, function(data) {
54             // Check if process was killed or not.
55             if (data.hasOwnProperty('success') && data.success) {
56                 // remove the row of killed process.
57                 $tr.remove();
58                 // As we just removed a row, reapply odd-even classes
59                 // to keep table stripes consistent
60                 $('#tableprocesslist > tbody > tr').filter(':even')
61                 .removeClass('odd').addClass('even');
62                 $('#tableprocesslist > tbody > tr').filter(':odd')
63                 .removeClass('even').addClass('odd');
64                 // Show process killed message
65                 PMA_ajaxShowMessage(data.message, false);
66             } else {
67                 // Show process error message
68                 PMA_ajaxShowMessage(data.error, false);
69             }
70         });
71     },
73     /**
74      * Handles Auto Refreshing
75      *
76      * @param object the event object
77      *
78      * @return void
79      */
80     refresh: function(event) {
81         // abort any previous pending requests
82         // this is necessary, it may go into
83         // multiple loops causing unnecessary
84         // requests even after leaving the page.
85         processList.abortRefresh();
86         // if auto refresh is enabled
87         if (processList.autoRefresh) {
88             var interval = parseInt(processList.refreshInterval, 10) * 1000;
89             var urlParams = processList.getUrlParams();
90             processList.refreshRequest = $.get(processList.refreshUrl,
91                 urlParams,
92                 function(data) {
93                     if (data.hasOwnProperty('success') && data.success) {
94                         $newTable = $(data.message);
95                         $('#tableprocesslist').html($newTable.html());
96                         PMA_highlightSQL($('#tableprocesslist'));
97                     }
98                     processList.refreshTimeout = setTimeout(
99                         processList.refresh,
100                         interval
101                     );
102                 });
103         }
104     },
106     /**
107      * Stop current request and clears timeout
108      *
109      * @return void
110      */
111     abortRefresh: function() {
112         if (processList.refreshRequest !== null) {
113             processList.refreshRequest.abort();
114             processList.refreshRequest = null;
115         }
116         clearTimeout(processList.refreshTimeout);
117     },
119     /**
120      * Set label of refresh button
121      * change between play & pause
122      *
123      * @return void
124      */
125     setRefreshLabel: function() {
126         var img = 'play.png';
127         var label = PMA_messages.strStartRefresh;
128         if (processList.autoRefresh) {
129             img = 'pause.png';
130             label = PMA_messages.strStopRefresh;
131             processList.refresh();
132         }
133         $('a#toggleRefresh').html(PMA_getImage(img) + escapeHtml(label));
134     },
136     /**
137      * Return the Url Parameters
138      * for autorefresh request,
139      * includes showExecuting if the filter is checked
140      *
141      * @return urlParams - url parameters with autoRefresh request
142      */
143     getUrlParams: function() {
144         var urlParams = { 'ajax_request': true, 'refresh': true };
145         if ($('#showExecuting').is(":checked")) {
146             urlParams['showExecuting'] = true;
147             return urlParams;
148         }
149         return urlParams;
150     }
153 AJAX.registerOnload('server_status_processes.js', function() {
155     processList.init();
156     // Bind event handler for kill_process
157     $('#tableprocesslist').on(
158         'click',
159         'a.kill_process',
160         processList.killProcessHandler
161     );
162     // Bind event handler for toggling refresh of process list
163     $('a#toggleRefresh').on('click', function(event) {
164         event.preventDefault();
165         processList.autoRefresh = !processList.autoRefresh;
166         processList.setRefreshLabel();
167     });
168     // Bind event handler for change in refresh rate
169     $('#id_refreshRate').on('change', function(event) {
170         processList.refreshInterval = $(this).val();
171         processList.refresh();
172     });
173     // Bind event handler for table header links
174     $('#tableprocesslist').on('click', 'thead a', function() {
175         processList.refreshUrl = $(this).attr('href');
176     });
180  * Unbind all event handlers before tearing down a page
181  */
182 AJAX.registerTeardown('server_status_processes.js', function() {
183     $('#tableprocesslist').off('click', 'a.kill_process');
184     $('a#toggleRefresh').off('click');
185     $('#id_refreshRate').off('change');
186     $('#tableprocesslist').off('click', 'thead a');
187     // stop refreshing further
188     processList.abortRefresh();