]> git.joonet.de Git - adminer.git/commitdiff
Use AJAX in select
authorJakub Vrana <jakub@vrana.cz>
Sat, 16 Oct 2010 23:51:56 +0000 (01:51 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 17 Oct 2010 00:22:22 +0000 (02:22 +0200)
adminer/file.inc.php
adminer/include/adminer.inc.php
adminer/include/design.inc.php
adminer/select.inc.php
adminer/static/editing.js
adminer/static/functions.js
adminer/static/loader.gif [new file with mode: 0644]
compile.php
editor/include/adminer.inc.php

index 0b3e8e7dc1b67d88e9c69d9891f784cfbd9880ef..c89feb46c95b25ad9eb62c9dad251dfdadd65a1b 100644 (file)
@@ -18,6 +18,7 @@ if ($_GET["file"] == "favicon.ico") {
                case "up.gif": echo base64_decode("compile_file('../adminer/static/up.gif', 'base64_encode');"); break;
                case "down.gif": echo base64_decode("compile_file('../adminer/static/down.gif', 'base64_encode');"); break;
                case "arrow.gif": echo base64_decode("compile_file('../adminer/static/arrow.gif', 'base64_encode');"); break;
+               case "loader.gif": echo base64_decode("compile_file('../adminer/static/loader.gif', 'base64_encode');"); break;
        }
 }
 exit;
index d96921339a2be2565a21747e3e2495e68daac0ed..c47519f364952dd3b041f7b91bbb1547743d7a54 100644 (file)
@@ -123,7 +123,7 @@ document.getElementById('username').focus();
        */
        function selectQuery($query) {
                global $jush;
-               return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
+               return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a> <a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
        }
        
        /** Description of a row in a table
index 621ec5bc6d92dc5b91e23f1ae8a0748398bb6bf3..2130198557ad06e7ec210a6b596be9733965c945 100644 (file)
@@ -10,9 +10,10 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
        global $LANG, $HTTPS, $adminer, $connection, $drivers;
        header("Content-Type: text/html; charset=utf-8");
        header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox NoScript plugin
-       $title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
-       $protocol = ($HTTPS ? "https" : "http");
-       ?>
+       if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+               $title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
+               $protocol = ($HTTPS ? "https" : "http");
+               ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
 <html lang="<?php echo $LANG; ?>">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@@ -31,33 +32,35 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
 
 <div id="content">
 <?php
-       if (isset($breadcrumb)) {
-               $link = substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1);
-               echo '<p id="breadcrumb"><a href="' . ($link ? h($link) : ".") . '">' . $drivers[DRIVER] . '</a> &raquo; ';
-               $link = substr(preg_replace('~(db|ns)=[^&]*&~', '', ME), 0, -1);
-               $server = (SERVER != "" ? h(SERVER) : lang('Server'));
-               if ($breadcrumb === false) {
-                       echo "$server\n";
-               } else {
-                       echo "<a href='" . ($link ? h($link) : ".") . "'>$server</a> &raquo; ";
-                       if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
-                               echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
-                       }
-                       if (is_array($breadcrumb)) {
-                               if ($_GET["ns"] != "") {
-                                       echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
+               if (isset($breadcrumb)) {
+                       $link = substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1);
+                       echo '<p id="breadcrumb"><a href="' . ($link ? h($link) : ".") . '">' . $drivers[DRIVER] . '</a> &raquo; ';
+                       $link = substr(preg_replace('~(db|ns)=[^&]*&~', '', ME), 0, -1);
+                       $server = (SERVER != "" ? h(SERVER) : lang('Server'));
+                       if ($breadcrumb === false) {
+                               echo "$server\n";
+                       } else {
+                               echo "<a href='" . ($link ? h($link) : ".") . "'>$server</a> &raquo; ";
+                               if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
+                                       echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
                                }
-                               foreach ($breadcrumb as $key => $val) {
-                                       $desc = (is_array($val) ? $val[1] : $val);
-                                       if ($desc != "") {
-                                               echo '<a href="' . h(ME . "$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . h($desc) . '</a> &raquo; ';
+                               if (is_array($breadcrumb)) {
+                                       if ($_GET["ns"] != "") {
+                                               echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
+                                       }
+                                       foreach ($breadcrumb as $key => $val) {
+                                               $desc = (is_array($val) ? $val[1] : $val);
+                                               if ($desc != "") {
+                                                       echo '<a href="' . h(ME . "$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . h($desc) . '</a> &raquo; ';
+                                               }
                                        }
                                }
+                               echo "$title\n";
                        }
-                       echo "$title\n";
                }
+               echo "<h2>$title_all</h2>\n";
+               echo "<div id='main'>\n";
        }
-       echo "<h2>$title_all</h2>\n";
        restart_session();
        if ($_SESSION["messages"]) {
                echo "<div class='message'>" . implode("</div>\n<div class='message'>", $_SESSION["messages"]) . "</div>\n";
@@ -78,7 +81,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
 */
 function page_footer($missing = "") {
        global $adminer;
-       ?>
+       if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+               ?>
+</div>
 </div>
 
 <?php switch_lang(); ?>
@@ -86,4 +91,5 @@ function page_footer($missing = "") {
 <?php $adminer->navigation($missing); ?>
 </div>
 <?php
+       }
 }
index 363ef22a48fbd8c98aac565c83ee3105fff7d5cc..8d118bcd53ad1c25f877321180f56bc1755293fa 100644 (file)
@@ -192,7 +192,7 @@ $adminer->selectLinks($table_status, $set);
 if (!$columns) {
        echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
 } else {
-       echo "<form action='' id='form'>\n";
+       echo "<form action='' id='form' onsubmit='return !ajaxForm(this);'>\n";
        echo "<div style='display: none;'>";
        hidden_fields_get();
        echo (DB != "" ? '<input type="hidden" name="db" value="' . h(DB) . '">' . (isset($_GET["ns"]) ? '<input type="hidden" name="ns" value="' . h($_GET["ns"]) . '">' : "") : ""); // not used in Editor
@@ -254,7 +254,7 @@ if (!$columns) {
                                if ($name != "") {
                                        $order++;
                                        $names[$key] = $name;
-                                       echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
+                                       echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '" onclick="return !ajax(this.href);">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
                                }
                                $functions[$key] = $val["fun"];
                                next($select);
index 72506d66cfc55054eb59633877cd116be71ec984..91ef87f1d9f7499005f42250765ec6a29a0d41d3 100644 (file)
@@ -34,14 +34,6 @@ function bodyLoad(version, protocol) {
        document.body.appendChild(script);
 }
 
-/** Get value of select
-* @param HTMLSelectElement
-* @return string
-*/
-function selectValue(select) {
-       return select.value || select.options[select.selectedIndex].text;
-}
-
 /** Get value of dynamically created form field
 * @param HTMLFormElement
 * @param string
index f610ab8d8db152b159a7c2e241e6bc2581352670..acdd3b72939639d185982a0317c8cb9068588709 100644 (file)
@@ -32,6 +32,14 @@ function verifyVersion(protocol) {
        document.body.appendChild(script);
 }
 
+/** Get value of select
+* @param HTMLSelectElement
+* @return string
+*/
+function selectValue(select) {
+       return (select.value !== undefined ? select.value : select.options[select.selectedIndex].text);
+}
+
 /** Check all elements matching given name
 * @param HTMLInputElement
 * @param RegExp
@@ -123,6 +131,57 @@ function selectAddRow(field) {
 
 
 
+var ajaxState = 0;
+var ajaxTimeout;
+
+/** Create AJAX request
+* @param string
+* @return XMLHttpRequest or false in case of an error
+*/
+function ajax(url) {
+       var xmlhttp;
+       if (window.XMLHttpRequest) {
+               xmlhttp = new XMLHttpRequest();
+       } else if (window.ActiveXObject) {
+               xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
+       } else {
+               return false;
+       }
+       var currentState = ++ajaxState;
+       clearTimeout(ajaxTimeout);
+       ajaxTimeout = setTimeout(function () {
+               setHtml('main', '<img src="../adminer/static/loader.gif" alt="">');
+       }, 1000); // defer displaying loader
+       xmlhttp.open('GET', url);
+       xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
+       xmlhttp.onreadystatechange = function () {
+               if (xmlhttp.readyState == 4 && currentState == ajaxState) {
+                       clearTimeout(ajaxTimeout);
+                       setHtml('main', xmlhttp.responseText);
+                       if (window.jush) {
+                               jush.highlight_tag('code');
+                       }
+               }
+       };
+       xmlhttp.send('');
+       return xmlhttp;
+}
+
+/** Send form by AJAX GET
+* @param HTMLFormElement
+* @return XMLHttpRequest or false in case of an error
+*/
+function ajaxForm(form) {
+       var params = [ ];
+       for (var i=0; i < form.elements.length; i++) {
+               var el = form.elements[i];
+               if (el.name && (!/checkbox|radio/i.test(el.type) || el.checked)) {
+                       params.push(el.name + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value));
+               }
+       }
+       return ajax((form.action || location.pathname) + '?' + params.join('&'));
+}
+
 
 
 /** Display edit field
diff --git a/adminer/static/loader.gif b/adminer/static/loader.gif
new file mode 100644 (file)
index 0000000..f2a1bc0
Binary files /dev/null and b/adminer/static/loader.gif differ
index a9cc4e4b82b6b722a0ef2c2b882e04c4694921da..2cfd8ad7944027e332631088896ae58178222d17 100644 (file)
@@ -254,6 +254,7 @@ foreach (array("adminer", "editor") as $project) {
        $file = str_replace('<script type="text/javascript" src="static/editing.js"></script>' . "\n", "", $file);
        $file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\);~", 'compile_file', $file); // integrate static files
        $replace = 'h(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\1&amp;version=' . $VERSION;
+       $file = preg_replace('~\\.\\./adminer/static/(loader\\.gif)~', "'+location.pathname+'?file=\\1&amp;version=$VERSION", $file);
        $file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
        $file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
        $file = str_replace("'../externals/jush/'", "protocol + '://www.adminer.org/static/'", $file);
index 8c8d990d2bc70d1dae10b6d08c5a60d88e558100..9c5df1193231132badf234b7230b577d78052803 100644 (file)
@@ -58,6 +58,7 @@ document.getElementById('username').focus();
                        echo '<p class="tabs"><a href="' . h(ME . 'edit=' . urlencode($TABLE) . $set) . '">' . lang('New item') . "</a>\n";
                }
                echo "<a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a>\n";
+               echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
        }
        
        function backwardKeys($table, $tableName) {