$action = required_param('action', PARAM_ALPHA);
+$response = array();
+
if ($action === 'save') {
$drafttext = required_param('drafttext', PARAM_RAW);
$params = array('elementid' => $elementid,
// 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();
}
*/
$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.';
$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';
'plugin_title_shortcut',
'textrecovered',
'autosavefailed',
- 'autosavesucceeded'
+ 'autosavesucceeded',
+ 'errortextrecovery'
), 'editor_atto');
$PAGE->requires->strings_for_js(array(
'warning',
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);
}
}
});