Save note on F5/quit
This commit is contained in:
@@ -84,8 +84,8 @@ oCATC.pageInit = function(asHash, bFirstPage) {
|
||||
loadDocs();
|
||||
};
|
||||
|
||||
oCATC.onQuitPage = function() {
|
||||
return save(true);
|
||||
oCATC.onQuitPage = function(sExitMode) {
|
||||
return save(true, (sExitMode==self.consts.exitmodes.closing));
|
||||
};
|
||||
|
||||
function loadDocs() {
|
||||
@@ -133,12 +133,16 @@ function noteFeedback(sType, sMsg) {
|
||||
}
|
||||
};
|
||||
|
||||
function save(bForce) {
|
||||
function save(bForce, bOnUnload) {
|
||||
bForce = bForce || false;
|
||||
bOnUnload = bOnUnload || false;
|
||||
if(bOnUnload) bForce = true;
|
||||
|
||||
if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer);
|
||||
var bSave = (oEditor.keystrokes % 20 == 0 || bForce);
|
||||
|
||||
if(bSave) {
|
||||
if(self.tmp('saving')) {
|
||||
if(self.tmp('saving') && !bOnUnload) {
|
||||
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
||||
}
|
||||
else {
|
||||
@@ -146,22 +150,24 @@ function save(bForce) {
|
||||
if(self.tmp('id_course') != 0) {
|
||||
self.tmp('saving', true);
|
||||
noteFeedback('info', 'Saving...');
|
||||
getInfo(
|
||||
Tools.ajax(
|
||||
'set_note',
|
||||
function(sDesc, asData) {
|
||||
noteFeedback('notice', 'Note saved ('+asData.led_time+')');
|
||||
function(asData) {
|
||||
self.tmp('saving', false);
|
||||
var sMsg = 'Note saved ('+asData.led_time+')';
|
||||
noteFeedback('notice', sMsg) || oCATC.feedback('success', sMsg);
|
||||
},
|
||||
{
|
||||
id: self.tmp('id_course'),
|
||||
content: sContent
|
||||
},
|
||||
{id: self.tmp('id_course'), content: sContent},
|
||||
function(sError) {
|
||||
noteFeedback('error', 'Not saved! An error occured: '+sError);
|
||||
var sMsg = 'Not saved! An error occured: '+sError;
|
||||
noteFeedback('error', sMsg) || oCATC.feedback('error', sMsg);;
|
||||
self.tmp('saving', false);
|
||||
oSaveTimer = setTimeout(save, 1000);
|
||||
},
|
||||
'POST'
|
||||
false,
|
||||
'POST',
|
||||
'json',
|
||||
bOnUnload
|
||||
);
|
||||
}
|
||||
else noteFeedback('error', 'No Course ID');
|
||||
|
||||
Reference in New Issue
Block a user