Use AJAX in select
This commit is contained in:
parent
53804a2c20
commit
7eb85a75f8
|
@ -18,6 +18,7 @@ if ($_GET["file"] == "favicon.ico") {
|
||||||
case "up.gif": echo base64_decode("compile_file('../adminer/static/up.gif', 'base64_encode');"); break;
|
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 "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 "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;
|
exit;
|
||||||
|
|
|
@ -123,7 +123,7 @@ document.getElementById('username').focus();
|
||||||
*/
|
*/
|
||||||
function selectQuery($query) {
|
function selectQuery($query) {
|
||||||
global $jush;
|
global $jush;
|
||||||
return "<p><a href='" . h(remove_from_uri("page")) . "&page=last' title='" . lang('Page') . ": " . lang('last') . "'>>></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")) . "&page=last' title='" . lang('Page') . ": " . lang('last') . "'>>></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
|
/** Description of a row in a table
|
||||||
|
|
|
@ -10,6 +10,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
global $LANG, $HTTPS, $adminer, $connection, $drivers;
|
global $LANG, $HTTPS, $adminer, $connection, $drivers;
|
||||||
header("Content-Type: text/html; charset=utf-8");
|
header("Content-Type: text/html; charset=utf-8");
|
||||||
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox NoScript plugin
|
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox NoScript plugin
|
||||||
|
if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
|
||||||
$title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
|
$title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
|
||||||
$protocol = ($HTTPS ? "https" : "http");
|
$protocol = ($HTTPS ? "https" : "http");
|
||||||
?>
|
?>
|
||||||
|
@ -58,6 +59,8 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "<h2>$title_all</h2>\n";
|
echo "<h2>$title_all</h2>\n";
|
||||||
|
echo "<div id='main'>\n";
|
||||||
|
}
|
||||||
restart_session();
|
restart_session();
|
||||||
if ($_SESSION["messages"]) {
|
if ($_SESSION["messages"]) {
|
||||||
echo "<div class='message'>" . implode("</div>\n<div class='message'>", $_SESSION["messages"]) . "</div>\n";
|
echo "<div class='message'>" . implode("</div>\n<div class='message'>", $_SESSION["messages"]) . "</div>\n";
|
||||||
|
@ -78,12 +81,15 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
*/
|
*/
|
||||||
function page_footer($missing = "") {
|
function page_footer($missing = "") {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
|
if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php switch_lang(); ?>
|
<?php switch_lang(); ?>
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<?php $adminer->navigation($missing); ?>
|
<?php $adminer->navigation($missing); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,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'>\n";
|
echo "<form action='' id='form' onsubmit='return !ajaxForm(this);'>\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
|
||||||
|
@ -254,7 +254,7 @@ if (!$columns) {
|
||||||
if ($name != "") {
|
if ($name != "") {
|
||||||
$order++;
|
$order++;
|
||||||
$names[$key] = $name;
|
$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"];
|
$functions[$key] = $val["fun"];
|
||||||
next($select);
|
next($select);
|
||||||
|
|
|
@ -34,14 +34,6 @@ function bodyLoad(version, protocol) {
|
||||||
document.body.appendChild(script);
|
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
|
/** Get value of dynamically created form field
|
||||||
* @param HTMLFormElement
|
* @param HTMLFormElement
|
||||||
* @param string
|
* @param string
|
||||||
|
|
|
@ -32,6 +32,14 @@ function verifyVersion(protocol) {
|
||||||
document.body.appendChild(script);
|
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
|
/** Check all elements matching given name
|
||||||
* @param HTMLInputElement
|
* @param HTMLInputElement
|
||||||
* @param RegExp
|
* @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
|
/** Display edit field
|
||||||
|
|
BIN
adminer/static/loader.gif
Normal file
BIN
adminer/static/loader.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 673 B |
|
@ -254,6 +254,7 @@ foreach (array("adminer", "editor") as $project) {
|
||||||
$file = str_replace('<script type="text/javascript" src="static/editing.js"></script>' . "\n", "", $file);
|
$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
|
$file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\);~", 'compile_file', $file); // integrate static files
|
||||||
$replace = 'h(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\1&version=' . $VERSION;
|
$replace = 'h(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\1&version=' . $VERSION;
|
||||||
|
$file = preg_replace('~\\.\\./adminer/static/(loader\\.gif)~', "'+location.pathname+'?file=\\1&version=$VERSION", $file);
|
||||||
$file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
|
$file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
|
||||||
$file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
|
$file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
|
||||||
$file = str_replace("'../externals/jush/'", "protocol + '://www.adminer.org/static/'", $file);
|
$file = str_replace("'../externals/jush/'", "protocol + '://www.adminer.org/static/'", $file);
|
||||||
|
|
|
@ -58,6 +58,7 @@ document.getElementById('username').focus();
|
||||||
echo '<p class="tabs"><a href="' . h(ME . 'edit=' . urlencode($TABLE) . $set) . '">' . lang('New item') . "</a>\n";
|
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")) . "&page=last' title='" . lang('Page') . ": " . lang('last') . "'>>></a>\n";
|
echo "<a href='" . h(remove_from_uri("page")) . "&page=last' title='" . lang('Page') . ": " . lang('last') . "'>>></a>\n";
|
||||||
|
echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function backwardKeys($table, $tableName) {
|
function backwardKeys($table, $tableName) {
|
||||||
|
|
Loading…
Reference in a new issue