Report offline and other AJAX errors (bug #419)

This commit is contained in:
Jakub Vrana 2014-09-14 14:46:54 -07:00
parent a987a2a4de
commit 37c8a3a123
6 changed files with 31 additions and 13 deletions

View file

@ -9,6 +9,10 @@
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
global $LANG, $VERSION, $adminer, $drivers, $jush; global $LANG, $VERSION, $adminer, $drivers, $jush;
page_headers(); page_headers();
if (is_ajax() && $error) {
page_messages($error);
exit;
}
$title_all = $title . ($title2 != "" ? ": $title2" : ""); $title_all = $title . ($title2 != "" ? ": $title2" : "");
$title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name()); $title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name());
?> ?>
@ -32,6 +36,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<body class="<?php echo lang('ltr'); ?> nojs" onkeydown="bodyKeydown(event);" onclick="bodyClick(event);"<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " onload=\"verifyVersion('$VERSION');\""); ?>> <body class="<?php echo lang('ltr'); ?> nojs" onkeydown="bodyKeydown(event);" onclick="bodyClick(event);"<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " onload=\"verifyVersion('$VERSION');\""); ?>>
<script type="text/javascript"> <script type="text/javascript">
document.body.className = document.body.className.replace(/ nojs/, ' js'); document.body.className = document.body.className.replace(/ nojs/, ' js');
var offlineMessage = '<?php echo js_escape(lang('You are offline.')); ?>';
</script> </script>
<div id="help" class="jush-<?php echo $jush; ?> jsonly hidden" onmouseover="helpOpen = 1;" onmouseout="helpMouseout(this, event);"></div> <div id="help" class="jush-<?php echo $jush; ?> jsonly hidden" onmouseover="helpOpen = 1;" onmouseout="helpMouseout(this, event);"></div>
@ -65,6 +70,7 @@ document.body.className = document.body.className.replace(/ nojs/, ' js');
} }
} }
echo "<h2>$title_all</h2>\n"; echo "<h2>$title_all</h2>\n";
echo "<div id='ajaxstatus' class='jsonly hidden'></div>\n";
restart_session(); restart_session();
page_messages($error); page_messages($error);
$databases = &get_session("dbs"); $databases = &get_session("dbs");

View file

@ -1307,7 +1307,6 @@ function edit_form($TABLE, $fields, $row, $update) {
echo "<p class='error'>" . lang('No rows.') . "\n"; echo "<p class='error'>" . lang('No rows.') . "\n";
} }
?> ?>
<div id="message"></div>
<form action="" method="post" enctype="multipart/form-data" id="form"> <form action="" method="post" enctype="multipart/form-data" id="form">
<?php <?php
if (!$fields) { if (!$fields) {

View file

@ -67,6 +67,7 @@ $translations = array(
'Maximum allowed file size is %sB.' => 'Maximální povolená velikost souboru je %sB.', 'Maximum allowed file size is %sB.' => 'Maximální povolená velikost souboru je %sB.',
'Too big POST data. Reduce the data or increase the %s configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy %s.', 'Too big POST data. Reduce the data or increase the %s configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy %s.',
'You can upload a big SQL file via FTP and import it from server.' => 'Velký SQL soubor můžete nahrát pomocí FTP a importovat ho ze serveru.', 'You can upload a big SQL file via FTP and import it from server.' => 'Velký SQL soubor můžete nahrát pomocí FTP a importovat ho ze serveru.',
'You are offline.' => 'Jste offline.',
'Export' => 'Export', 'Export' => 'Export',
'Output' => 'Výstup', 'Output' => 'Výstup',

View file

@ -67,6 +67,7 @@ $translations = array(
'Maximum allowed file size is %sB.' => 'xx', 'Maximum allowed file size is %sB.' => 'xx',
'Too big POST data. Reduce the data or increase the %s configuration directive.' => 'xx', 'Too big POST data. Reduce the data or increase the %s configuration directive.' => 'xx',
'You can upload a big SQL file via FTP and import it from server.' => 'xx', 'You can upload a big SQL file via FTP and import it from server.' => 'xx',
'You are offline.' => 'xx',
'Export' => 'xx', 'Export' => 'xx',
'Output' => 'xx', 'Output' => 'xx',

View file

@ -503,11 +503,19 @@ function fieldChange(field) {
* @param string * @param string
* @param function (XMLHttpRequest) * @param function (XMLHttpRequest)
* @param [string] * @param [string]
* @param [string]
* @return XMLHttpRequest or false in case of an error * @return XMLHttpRequest or false in case of an error
*/ */
function ajax(url, callback, data) { function ajax(url, callback, data, message) {
var request = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false)); var request = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false));
if (request) { if (request) {
var ajaxStatus = document.getElementById('ajaxstatus');
if (message) {
ajaxStatus.innerHTML = '<div class="message">' + message + '</div>';
ajaxStatus.className = ajaxStatus.className.replace(/ hidden/g, '');
} else {
ajaxStatus.className += ' hidden';
}
request.open((data ? 'POST' : 'GET'), url); request.open((data ? 'POST' : 'GET'), url);
if (data) { if (data) {
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
@ -515,7 +523,12 @@ function ajax(url, callback, data) {
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
request.onreadystatechange = function () { request.onreadystatechange = function () {
if (request.readyState == 4) { if (request.readyState == 4) {
callback(request); if (/^2/.test(request.status)) {
callback(request);
} else {
ajaxStatus.innerHTML = (request.status ? request.responseText : '<div class="error">' + offlineMessage + '</div>');
ajaxStatus.className = ajaxStatus.className.replace(/ hidden/g, '');
}
} }
}; };
request.send(data); request.send(data);
@ -529,11 +542,9 @@ function ajax(url, callback, data) {
*/ */
function ajaxSetHtml(url) { function ajaxSetHtml(url) {
return ajax(url, function (request) { return ajax(url, function (request) {
if (request.status) { var data = eval('(' + request.responseText + ')');
var data = eval('(' + request.responseText + ')'); for (var key in data) {
for (var key in data) { setHtml(key, data[key]);
setHtml(key, data[key]);
}
} }
}); });
} }
@ -560,18 +571,17 @@ function ajaxForm(form, message, button) {
} }
data = data.join('&'); data = data.join('&');
setHtml('message', '<div class="message">' + message + '</div>');
var url = form.action; var url = form.action;
if (!/post/i.test(form.method)) { if (!/post/i.test(form.method)) {
url = url.replace(/\?.*/, '') + '?' + data; url = url.replace(/\?.*/, '') + '?' + data;
data = ''; data = '';
} }
return ajax(url, function (request) { return ajax(url, function (request) {
setHtml('message', request.responseText); setHtml('ajaxstatus', request.responseText);
if (window.jush) { if (window.jush) {
jush.highlight_tag(document.getElementById('message').getElementsByTagName('code'), 0); jush.highlight_tag(document.getElementById('ajaxstatus').getElementsByTagName('code'), 0);
} }
}, data); }, data, message);
} }
@ -629,7 +639,7 @@ function selectClick(td, event, text, warning) {
input.focus(); input.focus();
if (text == 2) { // long text if (text == 2) { // long text
return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', function (request) { return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', function (request) {
if (request.status && request.responseText) { if (request.responseText) {
input.value = request.responseText; input.value = request.responseText;
input.name = td.id; input.name = td.id;
} }

View file

@ -6,6 +6,7 @@ Fix edit by long non-utf8 string
Specify encoding for PHP 5.6 with invalid default_charset Specify encoding for PHP 5.6 with invalid default_charset
Fix saving NULL value, bug since Adminer 4.0.3 Fix saving NULL value, bug since Adminer 4.0.3
Send 403 for auth error Send 403 for auth error
Report offline and other AJAX errors (bug #419)
MySQL: Use utf8mb4 if available MySQL: Use utf8mb4 if available
PostgreSQL: Materialized views PostgreSQL: Materialized views
Elasticsearch: Use where in select Elasticsearch: Use where in select