From 749f51afe64ac9ecec70775000498f8e8a03ae15 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sat, 29 Jun 2013 12:41:35 -0700 Subject: [PATCH] Save and continue edit by AJAX --- adminer/edit.inc.php | 12 ++++++++++- adminer/include/design.inc.php | 38 +++++++++++++++++++++++---------- adminer/include/version.inc.php | 2 +- adminer/select.inc.php | 5 +++-- adminer/static/functions.js | 37 ++++++++++++++++++++++++++++++++ changes.txt | 5 ++++- 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index f7e2350d..844e5354 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -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) { } ?> +
+
\n"; if (!isset($_GET["select"])) { - echo "\n"; + echo "\n"; } } echo ($update ? "\n" diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index 0a9b1818..2fe85d33 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -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 "

$title_all

\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 "
" . implode("
\n
", $messages) . "
\n"; unset($_SESSION["messages"][$uri]); } - $databases = &get_session("dbs"); - if (DB != "" && $databases && !in_array(DB, $databases, true)) { - $databases = null; - } - stop_session(); if ($error) { echo "
$error
\n"; } - define("PAGE_HEADER", 1); } /** Print HTML footer diff --git a/adminer/include/version.inc.php b/adminer/include/version.inc.php index 858c3928..c2330274 100644 --- a/adminer/include/version.inc.php +++ b/adminer/include/version.inc.php @@ -1,2 +1,2 @@ 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"])) { diff --git a/adminer/static/functions.js b/adminer/static/functions.js index e4378aa9..31bcf3eb 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -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 diff --git a/changes.txt b/changes.txt index 40234045..ce1d8242 100644 --- a/changes.txt +++ b/changes.txt @@ -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