Send all forms by AJAX
This commit is contained in:
parent
0e29a6a783
commit
38894b2977
|
@ -98,13 +98,13 @@ if (isset($_GET["select"])) {
|
||||||
hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
|
hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
|
||||||
}
|
}
|
||||||
if ($fields) {
|
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"])) {
|
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) {
|
if ($update) {
|
||||||
echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "')" . (isset($_GET["select"]) ? " && !ajaxForm(this.form, 'delete=1')" : "") . ";\">\n";
|
echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\">\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -14,6 +14,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
$title_page = $title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name();
|
$title_page = $title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name();
|
||||||
if (is_ajax()) {
|
if (is_ajax()) {
|
||||||
header("X-AJAX-Title: " . rawurlencode($title_page));
|
header("X-AJAX-Title: " . rawurlencode($title_page));
|
||||||
|
if ($_GET["ajax"]) {
|
||||||
|
header("X-AJAX-Redirect: " . remove_from_uri("ajax"));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$protocol = ($HTTPS ? "https" : "http");
|
$protocol = ($HTTPS ? "https" : "http");
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -355,7 +355,7 @@ function auth_url($driver, $server, $username) {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function is_ajax() {
|
function is_ajax() {
|
||||||
return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
|
return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" || $_GET["ajax"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send Location header and exit
|
/** Send Location header and exit
|
||||||
|
@ -372,13 +372,9 @@ function redirect($location, $message = null) {
|
||||||
if ($location == "") {
|
if ($location == "") {
|
||||||
$location = ".";
|
$location = ".";
|
||||||
}
|
}
|
||||||
if (!is_ajax()) {
|
header("Location: $location" . (is_ajax() ? (strpos($location, "?") !== false ? "&" : "?") . "ajax=1" : ""));
|
||||||
header("Location: $location");
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
header("X-AJAX-Redirect: $location");
|
|
||||||
$_POST = array();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Execute query and redirect if successful
|
/** Execute query and redirect if successful
|
||||||
|
|
|
@ -200,7 +200,7 @@ $adminer->selectLinks($table_status, $set);
|
||||||
if (!$columns) {
|
if (!$columns) {
|
||||||
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
|
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
|
||||||
} else {
|
} else {
|
||||||
echo "<form action='' id='form' onsubmit='return !ajaxForm(this);'>\n";
|
echo "<form action='' id='form'>\n";
|
||||||
echo "<div style='display: none;'>";
|
echo "<div style='display: none;'>";
|
||||||
hidden_fields_get();
|
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
|
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)) {
|
if (!information_schema(DB)) {
|
||||||
?>
|
?>
|
||||||
<fieldset><legend><?php echo lang('Edit'); ?></legend><div>
|
<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" 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'); ?>" onclick="return !ajaxForm(this.form, 'edit=1');">
|
<input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
|
||||||
<input type="submit" name="clone" value="<?php echo lang('Clone'); ?>" onclick="return !ajaxForm(this.form, 'clone=1');">
|
<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/)) + ')') && !ajaxForm(this.form, 'delete=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/)) + ')');">
|
||||||
</div></fieldset>
|
</div></fieldset>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,17 @@ function ajaxSend(url, data) {
|
||||||
script.text = scripts[i].text;
|
script.text = scripts[i].text;
|
||||||
content.appendChild(script);
|
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) {
|
if (window.jush) {
|
||||||
jush.highlight_tag('code', 0);
|
jush.highlight_tag('code', 0);
|
||||||
}
|
}
|
||||||
|
@ -361,23 +372,21 @@ function selectDblClick(td, event, text) {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function bodyClick(event, db) {
|
function bodyClick(event, db) {
|
||||||
|
if (event.getPreventDefault ? event.getPreventDefault() : !event.returnValue) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var el = event.target || event.srcElement;
|
var el = event.target || event.srcElement;
|
||||||
if (/^a$/i.test(el.parentNode.tagName)) {
|
if (/^a$/i.test(el.parentNode.tagName)) {
|
||||||
el = el.parentNode;
|
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);
|
var match = /&db=([^&]*)/.exec(el.href);
|
||||||
if (db === (match ? match[1] : '') && ajaxMain(el.href, '', event)) {
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue