From 37c8a3a123dfb8869009d45efebd22c77a50dbb5 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 14 Sep 2014 14:46:54 -0700 Subject: [PATCH] Report offline and other AJAX errors (bug #419) --- adminer/include/design.inc.php | 6 ++++++ adminer/include/functions.inc.php | 1 - adminer/lang/cs.inc.php | 1 + adminer/lang/xx.inc.php | 1 + adminer/static/functions.js | 34 ++++++++++++++++++++----------- changes.txt | 1 + 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index ee021b7f..508c922f 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -9,6 +9,10 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { global $LANG, $VERSION, $adminer, $drivers, $jush; page_headers(); + if (is_ajax() && $error) { + page_messages($error); + exit; + } $title_all = $title . ($title2 != "" ? ": $title2" : ""); $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 = "") { > @@ -65,6 +70,7 @@ document.body.className = document.body.className.replace(/ nojs/, ' js'); } } echo "

$title_all

\n"; + echo "\n"; restart_session(); page_messages($error); $databases = &get_session("dbs"); diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 69b0ad16..05ff0936 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -1307,7 +1307,6 @@ function edit_form($TABLE, $fields, $row, $update) { echo "

" . lang('No rows.') . "\n"; } ?> -

'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.', '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', 'Output' => 'Výstup', diff --git a/adminer/lang/xx.inc.php b/adminer/lang/xx.inc.php index 04b09049..5e5c15f7 100644 --- a/adminer/lang/xx.inc.php +++ b/adminer/lang/xx.inc.php @@ -67,6 +67,7 @@ $translations = array( 'Maximum allowed file size is %sB.' => '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 are offline.' => 'xx', 'Export' => 'xx', 'Output' => 'xx', diff --git a/adminer/static/functions.js b/adminer/static/functions.js index cbb89fcc..2cce663a 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -503,11 +503,19 @@ function fieldChange(field) { * @param string * @param function (XMLHttpRequest) * @param [string] +* @param [string] * @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)); if (request) { + var ajaxStatus = document.getElementById('ajaxstatus'); + if (message) { + ajaxStatus.innerHTML = '
' + message + '
'; + ajaxStatus.className = ajaxStatus.className.replace(/ hidden/g, ''); + } else { + ajaxStatus.className += ' hidden'; + } request.open((data ? 'POST' : 'GET'), url); if (data) { 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.onreadystatechange = function () { if (request.readyState == 4) { - callback(request); + if (/^2/.test(request.status)) { + callback(request); + } else { + ajaxStatus.innerHTML = (request.status ? request.responseText : '
' + offlineMessage + '
'); + ajaxStatus.className = ajaxStatus.className.replace(/ hidden/g, ''); + } } }; request.send(data); @@ -529,11 +542,9 @@ function ajax(url, callback, data) { */ function ajaxSetHtml(url) { return ajax(url, function (request) { - if (request.status) { - var data = eval('(' + request.responseText + ')'); - for (var key in data) { - setHtml(key, data[key]); - } + var data = eval('(' + request.responseText + ')'); + for (var key in data) { + setHtml(key, data[key]); } }); } @@ -560,18 +571,17 @@ function ajaxForm(form, message, button) { } data = data.join('&'); - setHtml('message', '
' + message + '
'); var url = form.action; if (!/post/i.test(form.method)) { url = url.replace(/\?.*/, '') + '?' + data; data = ''; } return ajax(url, function (request) { - setHtml('message', request.responseText); + setHtml('ajaxstatus', request.responseText); 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(); if (text == 2) { // long text return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', function (request) { - if (request.status && request.responseText) { + if (request.responseText) { input.value = request.responseText; input.name = td.id; } diff --git a/changes.txt b/changes.txt index 2dda7f40..476d672d 100644 --- a/changes.txt +++ b/changes.txt @@ -6,6 +6,7 @@ Fix edit by long non-utf8 string Specify encoding for PHP 5.6 with invalid default_charset Fix saving NULL value, bug since Adminer 4.0.3 Send 403 for auth error +Report offline and other AJAX errors (bug #419) MySQL: Use utf8mb4 if available PostgreSQL: Materialized views Elasticsearch: Use where in select