Permalink
Browse files

Send all forms by AJAX

  • Loading branch information...
1 parent 0e29a6a commit 38894b29777fd47bf546547949c242088577576e @vrana committed Nov 23, 2010
View
@@ -98,13 +98,13 @@
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>
@@ -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");
?>
@@ -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;
}
}
View
@@ -200,7 +200,7 @@
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 (!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
}
@@ -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;
}

0 comments on commit 38894b2

Please sign in to comment.