MDL-47140 editor_atto: Improved error handling
authorDave Cooper <dave@moodle.com>
Tue, 7 Oct 2014 07:34:25 +0000 (15:34 +0800)
committerDave Cooper <dave@moodle.com>
Mon, 13 Oct 2014 02:51:17 +0000 (10:51 +0800)
lib/editor/atto/autosave-ajax.php
lib/editor/atto/lang/en/editor_atto.php
lib/editor/atto/lib.php
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js
lib/editor/atto/yui/src/editor/js/autosave.js

index 36dcc06..fa45fd4 100644 (file)
@@ -45,6 +45,8 @@ require_sesskey();
 
 $action = required_param('action', PARAM_ALPHA);
 
+$response = array();
+
 if ($action === 'save') {
     $drafttext = required_param('drafttext', PARAM_RAW);
     $params = array('elementid' => $elementid,
@@ -138,7 +140,8 @@ if ($action === 'save') {
 
         // A response means the draft has been restored and here is the auto-saved text.
         if (!$stale) {
-            echo $record->drafttext;
+            $response['result'] = $record->drafttext;
+            echo json_encode($response);
         }
         die();
     }
index d1c2b68..c151c0a 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 $string['autosavefailed'] = 'Could not connect to the server. If you submit this page now, your changes may be lost.';
-$string['autosavefrequency'] = 'Autosave frequency (seconds).';
+$string['autosavefrequency'] = 'Autosave frequency';
 $string['autosavefrequency_desc'] = 'This is the number of seconds between auto save attempts. Atto will automatically save the text in the editor according to this setting, so that text can be automatically restored when the same user returns to the same form.';
 $string['autosavesucceeded'] = 'Draft saved.';
 $string['errorcannotparseline'] = 'The line \'{$a}\' is not in the correct format.';
@@ -31,6 +31,7 @@ $string['errorgroupisusedtwice'] = 'The group \'{$a}\' is defined twice; group n
 $string['errornopluginsorgroupsfound'] = 'No plugins or groups found; please add some groups and plugins.';
 $string['errorpluginnotfound'] = 'The plugin \'{$a}\' cannot be used; it does not appear to be installed.';
 $string['errorpluginisusedtwice'] = 'The plugin \'{$a}\' is used twice; plugins can only be defined once.';
+$string['errortextrecovery'] = 'The draft version of this text was unable to be restored.';
 $string['pluginname'] = 'Atto HTML editor';
 $string['subplugintype_atto'] = 'Atto plugin';
 $string['subplugintype_atto_plural'] = 'Atto plugins';
index 00cd928..65caee5 100644 (file)
@@ -127,7 +127,8 @@ class atto_texteditor extends texteditor {
                 'plugin_title_shortcut',
                 'textrecovered',
                 'autosavefailed',
-                'autosavesucceeded'
+                'autosavesucceeded',
+                'errortextrecovery'
             ), 'editor_atto');
         $PAGE->requires->strings_for_js(array(
                 'warning',
index 6969164..2254cc0 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js differ
index 5ce80c8..0a8ea93 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js differ
index d743822..8f3a664 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js differ
index 07598bc..ee2ec44 100644 (file)
@@ -145,10 +145,19 @@ EditorAutosave.prototype = {
                     if (typeof o.responseText !== "undefined" &&
                             o.responseText !== "" &&
                             o.responseText !== this.textarea.get('value')) {
-                        Y.log('Autosave text found - recover it.', 'debug', LOGNAME_AUTOSAVE);
-                        this.recoverText(o.responseText);
+                        response_json = JSON.parse(o.responseText);
+                        if (!response_json.error && response_json.result) {
+                            Y.log('Autosave text found - recover it.', 'debug', LOGNAME_AUTOSAVE);
+                            this.recoverText(response_json.result);
+                        } else {
+                            Y.log('Error occurred recovering draft text: ' + response_json.error, 'debug', LOGNAME_AUTOSAVE);
+                            this.showMessage(M.util.get_string('errortextrecovery', 'editor_atto'), NOTIFY_WARNING, RECOVER_MESSAGE_TIMEOUT);
+                        }
                         this._fireSelectionChanged();
                     }
+                },
+                failure: function() {
+                    this.showMessage(M.util.get_string('errortextrecovery', 'editor_atto'), NOTIFY_WARNING, RECOVER_MESSAGE_TIMEOUT);
                 }
             }
         });