Save and continue edit by AJAX
This commit is contained in:
parent
ba1bb263b3
commit
749f51afe6
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<?php
|
||||
$VERSION = "3.7.1";
|
||||
$VERSION = "3.7.2-dev";
|
||||
|
|
|
@ -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"])) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue