Merge branch 'wip-MDL-46819-master' of git://github.com/abgreeve/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 13 Oct 2014 10:02:59 +0000 (11:02 +0100)
committerDan Poltawski <dan@moodle.com>
Mon, 13 Oct 2014 10:02:59 +0000 (11:02 +0100)
grade/import/csv/classes/load_data.php
grade/import/direct/index.php
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 3cbb069..21477b9 100644 (file)
@@ -77,17 +77,21 @@ class gradeimport_csv_load_data {
         $csvimport->load_csv_content($text, $encoding, $separator);
         $this->error = $csvimport->get_error();
 
-        // Get header (field names).
-        $this->headers = $csvimport->get_columns();
-        $this->trim_headers();
+        // If there are no import errors then proceed.
+        if (empty($this->error)) {
 
-        $csvimport->init();
-        $this->previewdata = array();
+            // Get header (field names).
+            $this->headers = $csvimport->get_columns();
+            $this->trim_headers();
 
-        for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
-            $lines = $csvimport->next();
-            if ($lines) {
-                $this->previewdata[] = $lines;
+            $csvimport->init();
+            $this->previewdata = array();
+
+            for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
+                $lines = $csvimport->next();
+                if ($lines) {
+                    $this->previewdata[] = $lines;
+                }
             }
         }
     }
index 1a9fc67..d1b6a4b 100644 (file)
@@ -69,7 +69,7 @@ if (!$iid) {
         $csvimport->load_csv_content($text, $formdata->encoding, 'tab', $formdata->previewrows);
         $csvimporterror = $csvimport->get_error();
         if (!empty($csvimporterror)) {
-            echo $renderer->errors($csvimport->get_error());
+            echo $renderer->errors(array($csvimport->get_error()));
             echo $OUTPUT->footer();
             die();
         }
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);
                 }
             }
         });