]> git.joonet.de Git - adminer.git/commitdiff
Report offline and other AJAX errors (bug #419)
authorJakub Vrana <jakub@vrana.cz>
Sun, 14 Sep 2014 21:46:54 +0000 (14:46 -0700)
committerJakub Vrana <jakub@vrana.cz>
Sun, 14 Sep 2014 22:47:09 +0000 (15:47 -0700)
adminer/include/design.inc.php
adminer/include/functions.inc.php
adminer/lang/cs.inc.php
adminer/lang/xx.inc.php
adminer/static/functions.js
changes.txt

index ee021b7f84a6867269f0e4c4b8ecd401dba7b5aa..508c922f16d0376b3693ca8f76a1a69c063ded2e 100644 (file)
@@ -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 = "") {
 <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">
 document.body.className = document.body.className.replace(/ nojs/, ' js');
+var offlineMessage = '<?php echo js_escape(lang('You are offline.')); ?>';
 </script>
 
 <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 "<div id='ajaxstatus' class='jsonly hidden'></div>\n";
        restart_session();
        page_messages($error);
        $databases = &get_session("dbs");
index 69b0ad16e8947ac9d42b513fc4e9efa3a606642f..05ff09360653f28e66d4e733966efb9f03796ef2 100644 (file)
@@ -1307,7 +1307,6 @@ function edit_form($TABLE, $fields, $row, $update) {
                echo "<p class='error'>" . lang('No rows.') . "\n";
        }
        ?>
-<div id="message"></div>
 <form action="" method="post" enctype="multipart/form-data" id="form">
 <?php
        if (!$fields) {
index f45c4815fd9573522ddcbd0d86de424df72882eb..c2d6a192d96a93b533c411160378a0d89bb8fe85 100644 (file)
@@ -67,6 +67,7 @@ $translations = array(
        '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.',
        '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',
index 04b09049de2d325923860602a82f328d641dd03a..5e5c15f733621e33abc011ca870fe6ab7165a5a7 100644 (file)
@@ -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',
index cbb89fcc1b73388eafb826054834009bba90a13e..2cce663a021b64cb54a4231c10429eb9b77b894a 100644 (file)
@@ -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 = '<div class="message">' + message + '</div>';
+                       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 : '<div class="error">' + offlineMessage + '</div>');
+                                       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', '<div class="message">' + message + '</div>');
        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;
                        }
index 2dda7f40ec0275136d0201e870b888b1c712f3a7..476d672d30694a4bfe6bc147a31e341defe699e5 100644 (file)
@@ -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