]> git.joonet.de Git - adminer.git/commitdiff
Send all forms by AJAX
authorJakub Vrana <jakub@vrana.cz>
Tue, 23 Nov 2010 10:50:53 +0000 (11:50 +0100)
committerJakub Vrana <jakub@vrana.cz>
Tue, 23 Nov 2010 12:01:30 +0000 (13:01 +0100)
adminer/edit.inc.php
adminer/include/design.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
adminer/static/functions.js

index 6e419ba474c7874613cf8342be97d78159c372a3..d88108be6475e6a0e942f7dd95d5440b7214af9f 100644 (file)
@@ -98,13 +98,13 @@ if (isset($_GET["select"])) {
        hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
 }
 if ($fields) {
-       echo "<input type='submit' value='" . lang('Save') . "'" . (isset($_GET["select"]) ? " onclick='return !ajaxForm(this.form);'" : "") . ">\n";
+       echo "<input type='submit' value='" . lang('Save') . "'>\n";
        if (!isset($_GET["select"])) {
-               echo '<input type="submit" name="insert" value="' . ($update ? lang('Save and continue edit') : lang('Save and insert next')) . "\" onclick=\"return !ajaxForm(this.form, 'insert=1');\">\n";
+               echo '<input type="submit" name="insert" value="' . ($update ? lang('Save and continue edit') : lang('Save and insert next')) . "\">\n";
        }
 }
 if ($update) {
-       echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "')" . (isset($_GET["select"]) ? " &amp;&amp; !ajaxForm(this.form, 'delete=1')" : "") . ";\">\n";
+       echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\">\n";
 }
 ?>
 </form>
index 4d273ccaa2cd7b8a7518f79c67446935140eb470..464c931a4741b89de182d5fbce4f258fa3934870 100644 (file)
@@ -14,6 +14,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
        $title_page = $title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name();
        if (is_ajax()) {
                header("X-AJAX-Title: " . rawurlencode($title_page));
+               if ($_GET["ajax"]) {
+                       header("X-AJAX-Redirect: " . remove_from_uri("ajax"));
+               }
        } else {
                $protocol = ($HTTPS ? "https" : "http");
                ?>
index 58ef4fd1cd4f3b4a41c08da21cd30a3ecc633191..2c62d12c3b5e53f86f1f9855c37c72bb20c92548 100644 (file)
@@ -355,7 +355,7 @@ function auth_url($driver, $server, $username) {
 * @return bool
 */
 function is_ajax() {
-       return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
+       return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" || $_GET["ajax"]);
 }
 
 /** Send Location header and exit
@@ -372,12 +372,8 @@ function redirect($location, $message = null) {
                if ($location == "") {
                        $location = ".";
                }
-               if (!is_ajax()) {
-                       header("Location: $location");
-                       exit;
-               }
-               header("X-AJAX-Redirect: $location");
-               $_POST = array();
+               header("Location: $location" . (is_ajax() ? (strpos($location, "?") !== false ? "&" : "?") . "ajax=1" : ""));
+               exit;
        }
 }
 
index 053c1d85268b08cf30a6b6885a65edd350817bc7..da191889d9427e260396f2edfd0930e3d0c99a1a 100644 (file)
@@ -200,7 +200,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' onsubmit='return !ajaxForm(this);'>\n";
+       echo "<form action='' id='form'>\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
@@ -393,10 +393,10 @@ if (!$columns) {
                        if (!information_schema(DB)) {
                                ?>
 <fieldset><legend><?php echo lang('Edit'); ?></legend><div>
-<input type="submit" id="save" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>" onclick="return !ajaxForm(this.form);">
-<input type="submit" name="edit" value="<?php echo lang('Edit'); ?>" onclick="return !ajaxForm(this.form, 'edit=1');">
-<input type="submit" name="clone" value="<?php echo lang('Clone'); ?>" onclick="return !ajaxForm(this.form, 'clone=1');">
-<input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?> (' + (this.form['all'].checked ? <?php echo $found_rows; ?> : formChecked(this, /check/)) + ')') &amp;&amp; !ajaxForm(this.form, 'delete=1');">
+<input type="submit" id="save" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>">
+<input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
+<input type="submit" name="clone" value="<?php echo lang('Clone'); ?>">
+<input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?> (' + (this.form['all'].checked ? <?php echo $found_rows; ?> : formChecked(this, /check/)) + ')');">
 </div></fieldset>
 <?php
                        }
index 0faae95f312fabe95ec63675c24902c45dc40cb9..76bb19eacc92ddfd5e32dfec61e16166baaec8ab 100644 (file)
@@ -248,6 +248,17 @@ function ajaxSend(url, data) {
                                script.text = scripts[i].text;
                                content.appendChild(script);
                        }
+                       
+                       var as = document.getElementById('menu').getElementsByTagName('a');
+                       for (var i=0; i < as.length; i++) {
+                               if (as[i].className == 'active') {
+                                       as[i].className = '';
+                               } else if (location.href == as[i].href) {
+                                       as[i].className = 'active';
+                               }
+                       }
+                       //! modify Export link
+                       
                        if (window.jush) {
                                jush.highlight_tag('code', 0);
                        }
@@ -361,23 +372,21 @@ function selectDblClick(td, event, text) {
 * @return bool
 */
 function bodyClick(event, db) {
+       if (event.getPreventDefault ? event.getPreventDefault() : !event.returnValue) {
+               return false;
+       }
        var el = event.target || event.srcElement;
        if (/^a$/i.test(el.parentNode.tagName)) {
                el = el.parentNode;
        }
-       if (/^a$/i.test(el.tagName) && !/^https?:/i.test(el.getAttribute('href')) && !el.onclick && /[&?]username=/.exec(el.href)) {
+       if (/^a$/i.test(el.tagName) && !/^https?:|#/i.test(el.getAttribute('href')) && /[&?]username=/.exec(el.href)) {
                var match = /&db=([^&]*)/.exec(el.href);
                if (db === (match ? match[1] : '') && ajaxMain(el.href, '', event)) {
-                       var as = document.getElementById('menu').getElementsByTagName('a');
-                       for (var i=0; i < as.length; i++) {
-                               if (as[i].className == 'active') {
-                                       as[i].className = '';
-                               } else if (el.href == as[i].href) {
-                                       as[i].className = 'active';
-                               }
-                       }
-                       //! modify Export link
                        return false;
                }
        }
+       if (/^input$/i.test(el.tagName) && /submit|image/.test(el.type) && !/&(database|scheme|create|view|sql|user)=/.test(location.href)) {
+               return !ajaxForm(el.form, (el.name ? encodeURIComponent(el.name) + '=1' : ''));
+       }
+       return true;
 }