Add auto-refresh process and prepared xact using ajax
authorLeonardo Sápiras <l.sapiras@gmail.com>
Wed, 9 Jun 2010 19:40:20 +0000 (21:40 +0200)
committerioguix <ioguix@free.fr>
Wed, 9 Jun 2010 19:40:20 +0000 (21:40 +0200)
This patch rename the existing js/locks.js as js/database.js
and factorise the code to use it from both page.

database.php
js/locks.js [deleted file]

index f075b9a164c062bc2fff6d57fd5419744e603264..31e4d0a3a1c4e1c072ae0132f86c716d8874defe 100755 (executable)
                $misc->printTabs('database','processes');
                $misc->printMsg($msg);
 
+               if (strlen($msg) === 0) {
+                       echo "<br /><a id=\"control\" href=\"\"><img src=\"".$misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/>&nbsp;{$lang['strrefresh']}</a>";
+               }
+
+               echo "<div id=\"data_block\">";
+               currentProcesses();
+               echo "</div>";
+       }
+       
+       function currentProcesses($isAjax = false) {
+               global $data, $misc, $lang;
+               
                // Display prepared transactions
                if($data->hasPreparedXacts()) {
                        echo "<h3>{$lang['strpreparedxacts']}</h3>\n";
                if (!isset($processes->fields['query_start'])) unset($columns['start_time']);
 
                $misc->printTable($processes, $columns, $actions, $lang['strnodata']);
+               
+               if ($isAjax) exit;
        }
 
        function currentLocks($isAjax = false) {
 
                echo "<br /><a id=\"control\" href=\"\"><img src=\"".$misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/>&nbsp;{$lang['strrefresh']}</a>";
 
-               echo "<div id=\"locks_block\" class=\"data_block\">";
+               echo "<div id=\"data_block\">";
                currentLocks();
                echo "</div>";
        }
        /* shortcuts: these functions exit the script */
        if ($action == 'tree') doTree();
        if ($action == 'refresh_locks') currentLocks(true);
+       if ($action == 'refresh_processes') currentProcesses(true);
 
        /* normal flow */
-       if ($action == 'locks') {
+       if ($action == 'locks' or $action == 'processes') {
                $scripts  = "<script src=\"libraries/js/jquery.js\" type=\"text/javascript\"></script>\n";
-               $scripts .= "<script src=\"js/locks.js\" type=\"text/javascript\"></script>";
+               $scripts .= "<script src=\"js/database.js\" type=\"text/javascript\"></script>";
 
                $refreshTime = $conf['ajax_refresh'] * 1000;
 
                $scripts .= "load_icon: '". $misc->icon('Loading') ."',\n";
                $scripts .= "server:'{$_REQUEST['server']}',\n";
                $scripts .= "dbname:'{$_REQUEST['database']}',\n";
+               $scripts .= "action:'refresh_{$action}',\n";
                $scripts .= "errmsg: '". str_replace("'", "\'", $lang['strconnectionfail']) ."',\n";
                $scripts .= "};\n";
                $scripts .= "</script>\n";
diff --git a/js/locks.js b/js/locks.js
deleted file mode 100644 (file)
index d532bd6..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-$(document).ready(function() {
-
-       var timeid = query = null;
-       var controlLink = $('#control');
-       var errmsg = $('<p class="errmsg">'+Database.errmsg+'</p>')
-               .insertBefore(controlLink)
-               .hide();
-       var loading = $('<img class="loading" alt="[loading]" src="'+ Database.load_icon +'" />')
-               .insertAfter(controlLink)
-               .hide();
-
-       function refreshLocksTable() {
-               if (Database.ajax_time_refresh > 0) {
-                       loading.show();
-                       query = $.ajax({
-                               type: 'GET',
-                               dataType: 'html',
-                               data: {server: Database.server, database: Database.dbname, action: 'refresh_locks'},
-                               url: 'database.php',
-                               cache: false,
-                               contentType: 'application/x-www-form-urlencoded',
-                               success: function(html) {
-                                       $('#locks_block').html(html);
-                                       timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh)
-                               },
-                               error: function() {
-                                       controlLink.click();
-                                       errmsg.show();
-                               },
-                               complete: function () {
-                                       loading.hide();
-                               }
-                       });
-               }
-       }
-
-       controlLink.toggle(
-               function() {
-                       $(errmsg).hide();
-                       timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh);
-                       controlLink.html('<img src="'+ Database.str_stop.icon +'" alt="" />&nbsp;'
-                               + Database.str_stop.text + '&nbsp;&nbsp;&nbsp;'
-                       );
-               },
-               function() {
-                       $(errmsg).hide();
-                       $(loading).hide();
-                       window.clearInterval(timeid);
-                       query.abort();
-                       controlLink.html('<img src="'+ Database.str_start.icon +'" alt="" />&nbsp;'
-                               + Database.str_start.text
-                       );
-               }
-       );
-
-       /* preload images */
-       $('#control img').hide()
-               .attr('src', Database.str_start.icon)
-               .attr('src', Database.str_stop.icon)
-               .show();
-       
-       /* start refreshing */
-       controlLink.click();
-});