]> git.joonet.de Git - adminer.git/commitdiff
Save and continue edit by AJAX
authorJakub Vrana <jakub@vrana.cz>
Sat, 29 Jun 2013 19:41:35 +0000 (12:41 -0700)
committerJakub Vrana <jakub@vrana.cz>
Sat, 29 Jun 2013 19:41:35 +0000 (12:41 -0700)
adminer/edit.inc.php
adminer/include/design.inc.php
adminer/include/version.inc.php
adminer/select.inc.php
adminer/static/functions.js
changes.txt

index f7e2350d09eb60df28ef69272f2bc2fd1fe7f6c5..844e5354fd01e5137593c0f623389e3b14c5595e 100644 (file)
@@ -47,6 +47,11 @@ if ($_POST && !$error && !isset($_GET["select"])) {
                                $location,
                                lang('Item has been updated.')
                        );
+                       if (is_ajax()) {
+                               page_headers();
+                               page_messages($error);
+                               exit;
+                       }
                } else {
                        $result = insert_into($TABLE, $set);
                        $last_id = ($result ? last_id() : 0);
@@ -92,6 +97,8 @@ if ($row === false) {
 }
 ?>
 
+<div id="message"></div>
+
 <form action="" method="post" enctype="multipart/form-data" id="form">
 <?php
 if (!$fields) {
@@ -132,7 +139,10 @@ if (!$fields) {
 if ($fields) {
        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')) . "' title='Ctrl+Shift+Enter'>\n";
+               echo "<input type='submit' name='insert' value='" . ($update
+                       ? lang('Save and continue edit') . "' onclick='return !ajaxForm(this.form, \"" . lang('Loading') . '", this)'
+                       : lang('Save and insert next')
+               ) . "' title='Ctrl+Shift+Enter'>\n";
        }
 }
 echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\">\n"
index 0a9b18185afc539f7b6caa4d241d04c98854202e..2fe85d33a555a81c54edbdcfd98d395cfb6987c0 100644 (file)
@@ -8,11 +8,7 @@
 */
 function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
        global $LANG, $adminer, $connection, $drivers;
-       header("Content-Type: text/html; charset=utf-8");
-       if ($adminer->headers()) {
-               header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox 3.6.9
-               header("X-XSS-Protection: 0"); // prevents introducing XSS in IE8 by removing safe parts of the page
-       }
+       page_headers();
        $title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
        $title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name());
        ?>
@@ -68,21 +64,41 @@ document.body.className = document.body.className.replace(/ nojs/, ' js');
        }
        echo "<h2>$title_all</h2>\n";
        restart_session();
+       page_messages($error);
+       $databases = &get_session("dbs");
+       if (DB != "" && $databases && !in_array(DB, $databases, true)) {
+               $databases = null;
+       }
+       stop_session();
+       define("PAGE_HEADER", 1);
+}
+
+/** Send HTTP headers
+* @return null
+*/
+function page_headers() {
+       global $adminer;
+       header("Content-Type: text/html; charset=utf-8");
+       if ($adminer->headers()) {
+               header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox 3.6.9
+               header("X-XSS-Protection: 0"); // prevents introducing XSS in IE8 by removing safe parts of the page
+       }
+}
+
+/** Print flash and error messages
+* @param string
+* @return null
+*/
+function page_messages($error) {
        $uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
        $messages = $_SESSION["messages"][$uri];
        if ($messages) {
                echo "<div class='message'>" . implode("</div>\n<div class='message'>", $messages) . "</div>\n";
                unset($_SESSION["messages"][$uri]);
        }
-       $databases = &get_session("dbs");
-       if (DB != "" && $databases && !in_array(DB, $databases, true)) {
-               $databases = null;
-       }
-       stop_session();
        if ($error) {
                echo "<div class='error'>$error</div>\n";
        }
-       define("PAGE_HEADER", 1);
 }
 
 /** Print HTML footer
index 858c39288331e745e52c8d66f3e20bbb19b28bed..c2330274038bf9d4b9b4da0fbaf6c67182f6a8a3 100644 (file)
@@ -1,2 +1,2 @@
 <?php
-$VERSION = "3.7.1";
+$VERSION = "3.7.2-dev";
index 940166316b685a6d7503cfe8417701ed45a8a786..8733f7df21bae60e2df1e4c5ff429a52c1caf52d 100644 (file)
@@ -199,10 +199,11 @@ if ($_POST && !$error) {
 
 $table_name = $adminer->tableName($table_status);
 if (is_ajax()) {
-       // needs to send headers
+       page_headers();
        ob_start();
+} else {
+       page_header(lang('Select') . ": $table_name", $error);
 }
-page_header(lang('Select') . ": $table_name", $error);
 
 $set = null;
 if (isset($rights["insert"])) {
index e4378aa994b709667946cdcbb35e625b4ef8c4b0..31bcf3eb51bd11e90a893d9b52d31a383705d231 100644 (file)
@@ -326,6 +326,7 @@ function bodyKeydown(event, button) {
                } else {
                        target.form.submit();
                }
+               target.focus();
                return false;
        }
        return true;
@@ -424,6 +425,42 @@ function ajaxSetHtml(url) {
        });
 }
 
+/** Save form contents through AJAX
+* @param HTMLFormElement
+* @param string
+* @param [HTMLInputElement]
+* @return boolean
+*/
+function ajaxForm(form, message, button) {
+       var data = [];
+       var els = form.elements;
+       for (var i = 0; i < els.length; i++) {
+               var el = els[i];
+               if (el.name && !el.disabled) {
+                       if (/^file$/i.test(el.type) && el.value) {
+                               return false;
+                       }
+                       if (!/^(checkbox|radio|submit|file)$/i.test(el.type) || el.checked || el == button) {
+                               data.push(encodeURIComponent(el.name) + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value));
+                       }
+               }
+       }
+       data = data.join('&');
+       
+       setHtml('message', message);
+       var url = form.action;
+       if (!/post/i.test(form.method)) {
+               url = url.replace(/\?.*/, '') + '?' + data;
+               data = '';
+       }
+       return ajax(url, function (request) {
+               setHtml('message', request.responseText);
+               if (window.jush) {
+                       jush.highlight_tag('code', 0);
+               }
+       }, data);
+}
+
 
 
 /** Display edit field
index 402340455e21158cf99bb93ba8c0d029c87541c4..ce1d8242e3f7723f260aae049dc6efe1ca27bd07 100644 (file)
@@ -1,4 +1,7 @@
-Adminer (released 2013-06-29):
+Adminer 3.7.2-dev:
+Save and continue edit by AJAX
+
+Adminer 3.7.1 (released 2013-06-29):
 Increase click target for checkboxes
 Use shadow for highlighting default button
 Don't use LIMIT 1 if inline updating unique row