Save note on F5/quit
This commit is contained in:
@@ -133,6 +133,7 @@ class CATC extends Main
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setNote($iCourseId, $asOps) {
|
public function setNote($iCourseId, $asOps) {
|
||||||
|
if(is_string($asOps)) $asOps = json_decode($asOps, true);
|
||||||
$oNote = new Note($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
$oNote = new Note($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||||
$sError = $oNote->setNote($asOps);
|
$sError = $oNote->setNote($asOps);
|
||||||
$bSuccess = ($sError=='');
|
$bSuccess = ($sError=='');
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ oCATC.pageInit = function(asHash, bFirstPage) {
|
|||||||
loadDocs();
|
loadDocs();
|
||||||
};
|
};
|
||||||
|
|
||||||
oCATC.onQuitPage = function() {
|
oCATC.onQuitPage = function(sExitMode) {
|
||||||
return save(true);
|
return save(true, (sExitMode==self.consts.exitmodes.closing));
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadDocs() {
|
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);
|
if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer);
|
||||||
var bSave = (oEditor.keystrokes % 20 == 0 || bForce);
|
var bSave = (oEditor.keystrokes % 20 == 0 || bForce);
|
||||||
|
|
||||||
if(bSave) {
|
if(bSave) {
|
||||||
if(self.tmp('saving')) {
|
if(self.tmp('saving') && !bOnUnload) {
|
||||||
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -146,22 +150,24 @@ function save(bForce) {
|
|||||||
if(self.tmp('id_course') != 0) {
|
if(self.tmp('id_course') != 0) {
|
||||||
self.tmp('saving', true);
|
self.tmp('saving', true);
|
||||||
noteFeedback('info', 'Saving...');
|
noteFeedback('info', 'Saving...');
|
||||||
getInfo(
|
Tools.ajax(
|
||||||
'set_note',
|
'set_note',
|
||||||
function(sDesc, asData) {
|
function(asData) {
|
||||||
noteFeedback('notice', 'Note saved ('+asData.led_time+')');
|
|
||||||
self.tmp('saving', false);
|
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) {
|
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);
|
self.tmp('saving', false);
|
||||||
oSaveTimer = setTimeout(save, 1000);
|
oSaveTimer = setTimeout(save, 1000);
|
||||||
},
|
},
|
||||||
'POST'
|
false,
|
||||||
|
'POST',
|
||||||
|
'json',
|
||||||
|
bOnUnload
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else noteFeedback('error', 'No Course ID');
|
else noteFeedback('error', 'No Course ID');
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ Prise de notes pour les cours du Collège des Arts Thérapeutiques Chinois
|
|||||||
* [ ] Quick view of muscles / nerves schemas
|
* [ ] Quick view of muscles / nerves schemas
|
||||||
* [x] Dictionary
|
* [x] Dictionary
|
||||||
* [x] Progress bar
|
* [x] Progress bar
|
||||||
* [ ] Save note on F5/quit
|
* [x] Save note on F5/quit
|
||||||
@@ -5,6 +5,7 @@ function CATC(asGlobals)
|
|||||||
this.consts.hash_sep = '-';
|
this.consts.hash_sep = '-';
|
||||||
this.consts.default_page = 'workshops';
|
this.consts.default_page = 'workshops';
|
||||||
this.consts.title = 'CATC';
|
this.consts.title = 'CATC';
|
||||||
|
this.consts.exitmodes = {same_page:'SP', new_page:'NP', closing:'LE'};
|
||||||
this.consts.root = location.protocol+'//'+location.host+location.pathname;
|
this.consts.root = location.protocol+'//'+location.host+location.pathname;
|
||||||
|
|
||||||
this.init = function()
|
this.init = function()
|
||||||
@@ -22,6 +23,9 @@ function CATC(asGlobals)
|
|||||||
//on window resize
|
//on window resize
|
||||||
$(window).resize(self.onResize).resize();
|
$(window).resize(self.onResize).resize();
|
||||||
|
|
||||||
|
//on Quit / F5
|
||||||
|
$(window).on('unload', function(){self.onQuitPage(self.consts.exitmodes.closing);});
|
||||||
|
|
||||||
//Hash management
|
//Hash management
|
||||||
self.resetTmpFunctions();
|
self.resetTmpFunctions();
|
||||||
$(window)
|
$(window)
|
||||||
@@ -34,23 +38,6 @@ function CATC(asGlobals)
|
|||||||
$.each(asVars, function(sKey, oValue){self.vars(sKey, oValue)});
|
$.each(asVars, function(sKey, oValue){self.vars(sKey, oValue)});
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Scrollbar */
|
|
||||||
|
|
||||||
/*this.scrollbar = function(sPos)
|
|
||||||
{
|
|
||||||
var $Cv = $('#main');
|
|
||||||
if(!self.vars('mobile'))
|
|
||||||
{
|
|
||||||
if(typeof self.vars('scrollbar') === 'undefined')
|
|
||||||
{
|
|
||||||
$Cv.tinyscrollbar({axis:'y', thumbSizeMin:'20', thumbSize:'20'});
|
|
||||||
self.vars('scrollbar', $Cv.data("plugin_tinyscrollbar"));
|
|
||||||
}
|
|
||||||
else self.vars('scrollbar').update(sPos);
|
|
||||||
}
|
|
||||||
else $Cv.unbind("tinyscrollbar");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* Menu */
|
/* Menu */
|
||||||
|
|
||||||
this.initMenu = function()
|
this.initMenu = function()
|
||||||
@@ -181,24 +168,11 @@ function CATC(asGlobals)
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setSideElemVisibility = function() {
|
|
||||||
if(self.elem.$Side) {
|
|
||||||
var iHeight = 0;
|
|
||||||
var iMaxHeight = self.elem.$Side.height();
|
|
||||||
self.elem.$Side.children().each(function(){
|
|
||||||
$(this).toggle(iMaxHeight - iHeight > 0);
|
|
||||||
iHeight += $(this).outerHeight(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Events */
|
/* Events */
|
||||||
|
|
||||||
this.onResize = function()
|
this.onResize = function()
|
||||||
{
|
{
|
||||||
self.vars('mobile', $('body').css('min-width')=='120px');
|
self.vars('mobile', $('body').css('min-width')=='120px');
|
||||||
self.setSideElemVisibility();
|
|
||||||
//self.scrollbar();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onHashChange = function()
|
this.onHashChange = function()
|
||||||
@@ -211,7 +185,7 @@ function CATC(asGlobals)
|
|||||||
{
|
{
|
||||||
self.pageInit = function(asHash, bFirstPage){console.log('no init for the page: '+asHash.page)};
|
self.pageInit = function(asHash, bFirstPage){console.log('no init for the page: '+asHash.page)};
|
||||||
self.onSamePageMove = function(asHash){return false};
|
self.onSamePageMove = function(asHash){return false};
|
||||||
self.onQuitPage = function(){return true};
|
self.onQuitPage = function(sExitMode){return true};
|
||||||
self.onFeedback = function(sType, sMsg){Tools.feedback(sType, sMsg);};
|
self.onFeedback = function(sType, sMsg){Tools.feedback(sType, sMsg);};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -251,21 +225,6 @@ function CATC(asGlobals)
|
|||||||
if(bReboot) location.reload();
|
if(bReboot) location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getVars = function(fOnSuccess)
|
|
||||||
{
|
|
||||||
fOnSuccess = fOnSuccess || function(){};
|
|
||||||
getInfo
|
|
||||||
(
|
|
||||||
'vars',
|
|
||||||
function(asData)
|
|
||||||
{
|
|
||||||
self.updateVars(asData.vars);
|
|
||||||
fOnSuccess();
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Page Switching */
|
/* Page Switching */
|
||||||
|
|
||||||
this.loadHome = function(asData) {
|
this.loadHome = function(asData) {
|
||||||
@@ -316,7 +275,7 @@ function CATC(asGlobals)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var bSamePage = (sCurrPage == sNextPage);
|
var bSamePage = (sCurrPage == sNextPage);
|
||||||
if(self.onQuitPage(bSamePage) && !bSamePage || self.onSamePageMove(asHash))
|
if(self.onQuitPage(self.consts.exitmodes[bSamePage?'same_page':'new_page']) && !bSamePage || self.onSamePageMove(asHash))
|
||||||
{
|
{
|
||||||
//Delete tmp variables
|
//Delete tmp variables
|
||||||
self.vars('tmp', {});
|
self.vars('tmp', {});
|
||||||
@@ -340,7 +299,6 @@ function CATC(asGlobals)
|
|||||||
self.elem.$Main = self.elem.$Container.find('#main');
|
self.elem.$Main = self.elem.$Container.find('#main');
|
||||||
|
|
||||||
self.elem.$Menu = self.elem.$Container.find('#menu');
|
self.elem.$Menu = self.elem.$Container.find('#menu');
|
||||||
self.elem.$Side = self.elem.$Container.find('#side');
|
|
||||||
if(self.vars.log_in) self.initMenu();
|
if(self.vars.log_in) self.initMenu();
|
||||||
|
|
||||||
self.splash(self.elem.$Main, $Dom, asHash, bFirstPage); //first page
|
self.splash(self.elem.$Main, $Dom, asHash, bFirstPage); //first page
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ var Tools = {
|
|||||||
return asForm;
|
return asForm;
|
||||||
},
|
},
|
||||||
|
|
||||||
ajax: function(sAction, fOnSuccess, oData, fOnFail, $Loader, sType, sDataType)
|
ajax: function(sAction, fOnSuccess, oData, fOnFail, $Loader, sType, sDataType, bBeacon)
|
||||||
{
|
{
|
||||||
sType = sType || 'GET';
|
sType = sType || 'GET';
|
||||||
sDataType = sDataType || 'json';
|
sDataType = sDataType || 'json';
|
||||||
|
bBeacon = bBeacon || false;
|
||||||
oData = oData || {};
|
oData = oData || {};
|
||||||
var asData = {};
|
var asData = {};
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ var Tools = {
|
|||||||
asData = this.serialize(oData);
|
asData = this.serialize(oData);
|
||||||
}
|
}
|
||||||
else asData = oData;
|
else asData = oData;
|
||||||
|
asData['a'] = sAction;
|
||||||
|
|
||||||
if($Loader)
|
if($Loader)
|
||||||
{
|
{
|
||||||
@@ -30,32 +32,40 @@ var Tools = {
|
|||||||
.html($('<img>', {'class':'onlyimg', src: Config.paths.dir.theme_image+"ajax.svg"}));
|
.html($('<img>', {'class':'onlyimg', src: Config.paths.dir.theme_image+"ajax.svg"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
asData['a'] = sAction;
|
if(bBeacon) {
|
||||||
return $.ajax({
|
var oFD = new FormData();
|
||||||
url: oCATC.consts.context.process_page,
|
$.each(asData, function(sKey, sValue){
|
||||||
type: sType,
|
if($.type(sValue) != 'string') sValue = JSON.stringify(sValue);
|
||||||
data: asData,
|
oFD.append(sKey, sValue);
|
||||||
dataType: sDataType
|
});
|
||||||
})
|
return navigator.sendBeacon(oCATC.consts.context.process_page, oFD);
|
||||||
.done(function(oData) {
|
}
|
||||||
if(oData.result==oCATC.consts.error) {
|
else {
|
||||||
if(!fOnFail) Tools.feedback('error', oData.desc);
|
return $.ajax({
|
||||||
else fOnFail(oData.desc);
|
url: oCATC.consts.context.process_page,
|
||||||
}
|
type: sType,
|
||||||
else fOnSuccess(oData.data, oData.desc);
|
data: asData,
|
||||||
|
dataType: sDataType
|
||||||
|
})
|
||||||
|
.done(function(oData) {
|
||||||
|
if(oData.result==oCATC.consts.error) {
|
||||||
|
if(!fOnFail) Tools.feedback('error', oData.desc);
|
||||||
|
else fOnFail(oData.desc);
|
||||||
|
}
|
||||||
|
else fOnSuccess(oData.data, oData.desc);
|
||||||
|
|
||||||
if($Loader) {
|
if($Loader) {
|
||||||
$Loader
|
$Loader
|
||||||
.removeClass()
|
.removeClass()
|
||||||
.addClass($Loader.data('load_class'))
|
.addClass($Loader.data('load_class'))
|
||||||
.html($Loader.data('load_html'));
|
.html($Loader.data('load_html'));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(function(jqXHR, textStatus, errorThrown) {
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
||||||
if(!fOnFail) Tools.feedback('error', textStatus+' '+errorThrown);
|
if(!fOnFail) Tools.feedback('error', textStatus+' '+errorThrown);
|
||||||
else fOnFail(textStatus);
|
else fOnFail(textStatus);
|
||||||
}
|
});
|
||||||
);
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getIcon: function(sIcon, bFull){
|
getIcon: function(sIcon, bFull){
|
||||||
@@ -118,42 +128,6 @@ function addInput(form, name, type, value)
|
|||||||
document.forms[form].appendChild(registerInput);
|
document.forms[form].appendChild(registerInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInfo(action, fOnSuccess, vars, fOnError, sType/*, bProcessIcon*/)
|
|
||||||
{
|
|
||||||
if(!vars) vars = {};
|
|
||||||
sType = sType || 'GET';
|
|
||||||
//bProcessIcon = bProcessIcon || false;
|
|
||||||
//if(bProcessIcon) self.addBufferIcon();
|
|
||||||
|
|
||||||
vars['a'] = action;
|
|
||||||
$.ajax(
|
|
||||||
{
|
|
||||||
url: oCATC.consts.context.process_page,
|
|
||||||
type:sType,
|
|
||||||
data: vars,
|
|
||||||
dataType: 'json'
|
|
||||||
})
|
|
||||||
.done(function(oData)
|
|
||||||
{
|
|
||||||
if(oData.result==oCATC.consts.error)
|
|
||||||
{
|
|
||||||
if(!fOnError) console.log(oData.desc);
|
|
||||||
else fOnError(oData.desc);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//if(bProcessIcon) self.resetIcon();
|
|
||||||
fOnSuccess(oData.desc, oData.data);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.fail(function(jqXHR, textStatus, errorThrown)
|
|
||||||
{
|
|
||||||
//if(bProcessIcon) self.resetIcon();
|
|
||||||
if(!fOnError) console.log(textStatus+' '+errorThrown);
|
|
||||||
else fOnError(textStatus);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function addPunctuation(sMsg)
|
function addPunctuation(sMsg)
|
||||||
{
|
{
|
||||||
var asPunctuations = ['?', '!', '.', ',', ':', ';', '-', '/'];
|
var asPunctuations = ['?', '!', '.', ',', ':', ';', '-', '/'];
|
||||||
|
|||||||
Reference in New Issue
Block a user