Skip to content
Browse files

Use AJAX in select

  • Loading branch information...
1 parent 53804a2 commit 7eb85a75f8823faf9dc2b7bb6f4b0e4b8c6a2b8e @vrana committed
View
1 adminer/file.inc.php
@@ -18,6 +18,7 @@
case "up.gif": echo base64_decode("compile_file('../adminer/static/up.gif', 'base64_encode');"); break;
case "down.gif": echo base64_decode("compile_file('../adminer/static/down.gif', 'base64_encode');"); break;
case "arrow.gif": echo base64_decode("compile_file('../adminer/static/arrow.gif', 'base64_encode');"); break;
+ case "loader.gif": echo base64_decode("compile_file('../adminer/static/loader.gif', 'base64_encode');"); break;
}
}
exit;
View
2 adminer/include/adminer.inc.php
@@ -123,7 +123,7 @@ function backwardKeysPrint($backwardKeys, $row) {
*/
function selectQuery($query) {
global $jush;
- return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
+ return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a> <a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
}
/** Description of a row in a table
View
56 adminer/include/design.inc.php
@@ -10,9 +10,10 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
global $LANG, $HTTPS, $adminer, $connection, $drivers;
header("Content-Type: text/html; charset=utf-8");
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox NoScript plugin
- $title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
- $protocol = ($HTTPS ? "https" : "http");
- ?>
+ if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+ $title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
+ $protocol = ($HTTPS ? "https" : "http");
+ ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="<?php echo $LANG; ?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@@ -31,33 +32,35 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<div id="content">
<?php
- if (isset($breadcrumb)) {
- $link = substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1);
- echo '<p id="breadcrumb"><a href="' . ($link ? h($link) : ".") . '">' . $drivers[DRIVER] . '</a> &raquo; ';
- $link = substr(preg_replace('~(db|ns)=[^&]*&~', '', ME), 0, -1);
- $server = (SERVER != "" ? h(SERVER) : lang('Server'));
- if ($breadcrumb === false) {
- echo "$server\n";
- } else {
- echo "<a href='" . ($link ? h($link) : ".") . "'>$server</a> &raquo; ";
- if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
- echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
- }
- if (is_array($breadcrumb)) {
- if ($_GET["ns"] != "") {
- echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
+ if (isset($breadcrumb)) {
+ $link = substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1);
+ echo '<p id="breadcrumb"><a href="' . ($link ? h($link) : ".") . '">' . $drivers[DRIVER] . '</a> &raquo; ';
+ $link = substr(preg_replace('~(db|ns)=[^&]*&~', '', ME), 0, -1);
+ $server = (SERVER != "" ? h(SERVER) : lang('Server'));
+ if ($breadcrumb === false) {
+ echo "$server\n";
+ } else {
+ echo "<a href='" . ($link ? h($link) : ".") . "'>$server</a> &raquo; ";
+ if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
+ echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
}
- foreach ($breadcrumb as $key => $val) {
- $desc = (is_array($val) ? $val[1] : $val);
- if ($desc != "") {
- echo '<a href="' . h(ME . "$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . h($desc) . '</a> &raquo; ';
+ if (is_array($breadcrumb)) {
+ if ($_GET["ns"] != "") {
+ echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
+ }
+ foreach ($breadcrumb as $key => $val) {
+ $desc = (is_array($val) ? $val[1] : $val);
+ if ($desc != "") {
+ echo '<a href="' . h(ME . "$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . h($desc) . '</a> &raquo; ';
+ }
}
}
+ echo "$title\n";
}
- echo "$title\n";
}
+ echo "<h2>$title_all</h2>\n";
+ echo "<div id='main'>\n";
}
- echo "<h2>$title_all</h2>\n";
restart_session();
if ($_SESSION["messages"]) {
echo "<div class='message'>" . implode("</div>\n<div class='message'>", $_SESSION["messages"]) . "</div>\n";
@@ -78,7 +81,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
*/
function page_footer($missing = "") {
global $adminer;
- ?>
+ if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+ ?>
+</div>
</div>
<?php switch_lang(); ?>
@@ -86,4 +91,5 @@ function page_footer($missing = "") {
<?php $adminer->navigation($missing); ?>
</div>
<?php
+ }
}
View
4 adminer/select.inc.php
@@ -192,7 +192,7 @@
if (!$columns) {
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
} else {
- echo "<form action='' id='form'>\n";
+ echo "<form action='' id='form' onsubmit='return !ajaxForm(this);'>\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
@@ -254,7 +254,7 @@
if ($name != "") {
$order++;
$names[$key] = $name;
- echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
+ echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '" onclick="return !ajax(this.href);">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
}
$functions[$key] = $val["fun"];
next($select);
View
8 adminer/static/editing.js
@@ -34,14 +34,6 @@ function bodyLoad(version, protocol) {
document.body.appendChild(script);
}
-/** Get value of select
-* @param HTMLSelectElement
-* @return string
-*/
-function selectValue(select) {
- return select.value || select.options[select.selectedIndex].text;
-}
-
/** Get value of dynamically created form field
* @param HTMLFormElement
* @param string
View
59 adminer/static/functions.js
@@ -32,6 +32,14 @@ function verifyVersion(protocol) {
document.body.appendChild(script);
}
+/** Get value of select
+* @param HTMLSelectElement
+* @return string
+*/
+function selectValue(select) {
+ return (select.value !== undefined ? select.value : select.options[select.selectedIndex].text);
+}
+
/** Check all elements matching given name
* @param HTMLInputElement
* @param RegExp
@@ -123,6 +131,57 @@ function selectAddRow(field) {
+var ajaxState = 0;
+var ajaxTimeout;
+
+/** Create AJAX request
+* @param string
+* @return XMLHttpRequest or false in case of an error
+*/
+function ajax(url) {
+ var xmlhttp;
+ if (window.XMLHttpRequest) {
+ xmlhttp = new XMLHttpRequest();
+ } else if (window.ActiveXObject) {
+ xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
+ } else {
+ return false;
+ }
+ var currentState = ++ajaxState;
+ clearTimeout(ajaxTimeout);
+ ajaxTimeout = setTimeout(function () {
+ setHtml('main', '<img src="../adminer/static/loader.gif" alt="">');
+ }, 1000); // defer displaying loader
+ xmlhttp.open('GET', url);
+ xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
+ xmlhttp.onreadystatechange = function () {
+ if (xmlhttp.readyState == 4 && currentState == ajaxState) {
+ clearTimeout(ajaxTimeout);
+ setHtml('main', xmlhttp.responseText);
+ if (window.jush) {
+ jush.highlight_tag('code');
+ }
+ }
+ };
+ xmlhttp.send('');
+ return xmlhttp;
+}
+
+/** Send form by AJAX GET
+* @param HTMLFormElement
+* @return XMLHttpRequest or false in case of an error
+*/
+function ajaxForm(form) {
+ var params = [ ];
+ for (var i=0; i < form.elements.length; i++) {
+ var el = form.elements[i];
+ if (el.name && (!/checkbox|radio/i.test(el.type) || el.checked)) {
+ params.push(el.name + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value));
+ }
+ }
+ return ajax((form.action || location.pathname) + '?' + params.join('&'));
+}
+
/** Display edit field
View
BIN adminer/static/loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1 compile.php
@@ -254,6 +254,7 @@ function compile_file($match) {
$file = str_replace('<script type="text/javascript" src="static/editing.js"></script>' . "\n", "", $file);
$file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\);~", 'compile_file', $file); // integrate static files
$replace = 'h(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\1&amp;version=' . $VERSION;
+ $file = preg_replace('~\\.\\./adminer/static/(loader\\.gif)~', "'+location.pathname+'?file=\\1&amp;version=$VERSION", $file);
$file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
$file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
$file = str_replace("'../externals/jush/'", "protocol + '://www.adminer.org/static/'", $file);
View
1 editor/include/adminer.inc.php
@@ -58,6 +58,7 @@ function selectLinks($tableStatus, $set = "") {
echo '<p class="tabs"><a href="' . h(ME . 'edit=' . urlencode($TABLE) . $set) . '">' . lang('New item') . "</a>\n";
}
echo "<a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a>\n";
+ echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
}
function backwardKeys($table, $tableName) {

0 comments on commit 7eb85a7

Please sign in to comment.
Something went wrong with that request. Please try again.