fix in tab ui for top.restoreSession
[openemr.git] / phpmyadmin / js / server_status_processes.js
bloba8b47662f7e85025e4858ce3affd77c0ef504e6d
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                 var $tableProcessListTr = $('#tableprocesslist').find('> tbody > tr');
61                 $tableProcessListTr.filter(':even').removeClass('odd').addClass('even');
62                 $tableProcessListTr.filter(':odd').removeClass('even').addClass('odd');
63                 // Show process killed message
64                 PMA_ajaxShowMessage(data.message, false);
65             } else {
66                 // Show process error message
67                 PMA_ajaxShowMessage(data.error, false);
68             }
69         });
70     },
72     /**
73      * Handles Auto Refreshing
74      *
75      * @param object the event object
76      *
77      * @return void
78      */
79     refresh: function(event) {
80         // abort any previous pending requests
81         // this is necessary, it may go into
82         // multiple loops causing unnecessary
83         // requests even after leaving the page.
84         processList.abortRefresh();
85         // if auto refresh is enabled
86         if (processList.autoRefresh) {
87             var interval = parseInt(processList.refreshInterval, 10) * 1000;
88             var urlParams = processList.getUrlParams();
89             processList.refreshRequest = $.get(processList.refreshUrl,
90                 urlParams,
91                 function(data) {
92                     if (data.hasOwnProperty('success') && data.success) {
93                         $newTable = $(data.message);
94                         $('#tableprocesslist').html($newTable.html());
95                         PMA_highlightSQL($('#tableprocesslist'));
96                     }
97                     processList.refreshTimeout = setTimeout(
98                         processList.refresh,
99                         interval
100                     );
101                 });
102         }
103     },
105     /**
106      * Stop current request and clears timeout
107      *
108      * @return void
109      */
110     abortRefresh: function() {
111         if (processList.refreshRequest !== null) {
112             processList.refreshRequest.abort();
113             processList.refreshRequest = null;
114         }
115         clearTimeout(processList.refreshTimeout);
116     },
118     /**
119      * Set label of refresh button
120      * change between play & pause
121      *
122      * @return void
123      */
124     setRefreshLabel: function() {
125         var img = 'play.png';
126         var label = PMA_messages.strStartRefresh;
127         if (processList.autoRefresh) {
128             img = 'pause.png';
129             label = PMA_messages.strStopRefresh;
130             processList.refresh();
131         }
132         $('a#toggleRefresh').html(PMA_getImage(img) + escapeHtml(label));
133     },
135     /**
136      * Return the Url Parameters
137      * for autorefresh request,
138      * includes showExecuting if the filter is checked
139      *
140      * @return urlParams - url parameters with autoRefresh request
141      */
142     getUrlParams: function() {
143         var urlParams = { 'ajax_request': true, 'refresh': true };
144         if ($('#showExecuting').is(":checked")) {
145             urlParams['showExecuting'] = true;
146             return urlParams;
147         }
148         return urlParams;
149     }
152 AJAX.registerOnload('server_status_processes.js', function() {
154     processList.init();
155     // Bind event handler for kill_process
156     $('#tableprocesslist').on(
157         'click',
158         'a.kill_process',
159         processList.killProcessHandler
160     );
161     // Bind event handler for toggling refresh of process list
162     $('a#toggleRefresh').on('click', function(event) {
163         event.preventDefault();
164         processList.autoRefresh = !processList.autoRefresh;
165         processList.setRefreshLabel();
166     });
167     // Bind event handler for change in refresh rate
168     $('#id_refreshRate').on('change', function(event) {
169         processList.refreshInterval = $(this).val();
170         processList.refresh();
171     });
172     // Bind event handler for table header links
173     $('#tableprocesslist').on('click', 'thead a', function() {
174         processList.refreshUrl = $(this).attr('href');
175     });
179  * Unbind all event handlers before tearing down a page
180  */
181 AJAX.registerTeardown('server_status_processes.js', function() {
182     $('#tableprocesslist').off('click', 'a.kill_process');
183     $('a#toggleRefresh').off('click');
184     $('#id_refreshRate').off('change');
185     $('#tableprocesslist').off('click', 'thead a');
186     // stop refreshing further
187     processList.abortRefresh();