MDL-18014 Atto: Add a notification when text is autosaved.

This commit is contained in:
Damyon Wiese 2014-07-30 13:34:14 +08:00
parent 8593521f4c
commit a108fbeecf
6 changed files with 21 additions and 11 deletions

View file

@ -22,6 +22,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$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_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'] = 'Text was automatically saved.';
$string['cancel'] = 'Cancel'; $string['cancel'] = 'Cancel';
$string['confirm'] = 'Confirm'; $string['confirm'] = 'Confirm';
$string['confirmrecover'] = 'A previously unsaved version of the text for field "{$a->label}" was found. Do you want to recover it?'; $string['confirmrecover'] = 'A previously unsaved version of the text for field "{$a->label}" was found. Do you want to recover it?';
@ -42,4 +46,3 @@ $string['plugin_title_shortcut'] = '{$a->title} [{$a->shortcut}]';
$string['recover'] = 'Recover'; $string['recover'] = 'Recover';
$string['infostatus'] = 'Information'; $string['infostatus'] = 'Information';
$string['warningstatus'] = 'Warning'; $string['warningstatus'] = 'Warning';
$string['autosavefailed'] = 'Could not connect to the server. If you submit this page now, your changes may be lost.';

View file

@ -129,7 +129,8 @@ class atto_texteditor extends texteditor {
'recover', 'recover',
'cancel', 'cancel',
'confirmrecover', 'confirmrecover',
'autosavefailed' 'autosavefailed',
'autosavesucceeded'
), 'editor_atto'); ), 'editor_atto');
$PAGE->requires->strings_for_js(array( $PAGE->requires->strings_for_js(array(
'warning', 'warning',

View file

@ -733,7 +733,8 @@ Y.Base.mix(Y.M.editor_atto.Editor, [EditorTextArea]);
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
var AUTOSAVE_FREQUENCY = 60000; var AUTOSAVE_FREQUENCY = 60000,
SUCCESS_MESSAGE_TIMEOUT = 5000;
function EditorAutosave() {} function EditorAutosave() {}
@ -916,13 +917,14 @@ EditorAutosave.prototype = {
this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY); this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY);
}, },
success: function(code, response) { success: function(code, response) {
if (response !== "") { if (response.response !== "") {
Y.log('Failure while autosaving text.', 'warn'); Y.log('Failure while autosaving text.', 'warn');
Y.log(response, 'debug'); Y.log(response, 'debug');
this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY); this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY);
} else { } else {
// All working. // All working.
this.lastText = newText; this.lastText = newText;
this.showMessage(M.util.get_string('autosavesucceeded', 'editor_atto'), 'info', SUCCESS_MESSAGE_TIMEOUT);
} }
} }
}, },

File diff suppressed because one or more lines are too long

View file

@ -728,7 +728,8 @@ Y.Base.mix(Y.M.editor_atto.Editor, [EditorTextArea]);
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
var AUTOSAVE_FREQUENCY = 60000; var AUTOSAVE_FREQUENCY = 60000,
SUCCESS_MESSAGE_TIMEOUT = 5000;
function EditorAutosave() {} function EditorAutosave() {}
@ -905,11 +906,12 @@ EditorAutosave.prototype = {
this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY); this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY);
}, },
success: function(code, response) { success: function(code, response) {
if (response !== "") { if (response.response !== "") {
this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY); this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY);
} else { } else {
// All working. // All working.
this.lastText = newText; this.lastText = newText;
this.showMessage(M.util.get_string('autosavesucceeded', 'editor_atto'), 'info', SUCCESS_MESSAGE_TIMEOUT);
} }
} }
}, },

View file

@ -23,7 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
var AUTOSAVE_FREQUENCY = 60000; var AUTOSAVE_FREQUENCY = 60000,
SUCCESS_MESSAGE_TIMEOUT = 5000;
function EditorAutosave() {} function EditorAutosave() {}
@ -206,13 +207,14 @@ EditorAutosave.prototype = {
this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY); this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY);
}, },
success: function(code, response) { success: function(code, response) {
if (response !== "") { if (response.response !== "") {
Y.log('Failure while autosaving text.', 'warn'); Y.log('Failure while autosaving text.', 'warn');
Y.log(response, 'debug'); Y.log(response, 'debug');
this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY); this.showMessage(M.util.get_string('autosavefailed', 'editor_atto'), 'warning', AUTOSAVE_FREQUENCY);
} else { } else {
// All working. // All working.
this.lastText = newText; this.lastText = newText;
this.showMessage(M.util.get_string('autosavesucceeded', 'editor_atto'), 'info', SUCCESS_MESSAGE_TIMEOUT);
} }
} }
}, },