95 lines
2.3 KiB
HTML
95 lines
2.3 KiB
HTML
<div id="course">
|
|
<div id="docs"></div>
|
|
<div id="notes_box">
|
|
<div id="notes_feedback"></div>
|
|
<div id="notes"></div>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
oCATC.pageInit = function(asHash, bFirstPage) {
|
|
self.setPageTitle('Course');
|
|
self.tmp('id_course', asHash.items[0]);
|
|
|
|
//Setup Quill
|
|
oEditor = new Editor('#notes');
|
|
oEditor.onKeyStroke = (e) => {
|
|
if(e.which == 83 && e.ctrlKey) {
|
|
e.preventDefault();
|
|
save(true);
|
|
}
|
|
else save();
|
|
};
|
|
|
|
//Load notes
|
|
Tools.ajax(
|
|
'get_note',
|
|
(asData) => {
|
|
oEditor.setContent(asData.notes);
|
|
oCATC.feedback('notice', 'Last update on ('+asData.led.substr(11, 5)+')');
|
|
},
|
|
{id: self.tmp('id_course')},
|
|
() => {console.log('Note not found for course ID = '+self.tmp('id_course'))}
|
|
);
|
|
|
|
//oQuill.keyboard.addBinding({key: 'S', ctrlKey: true}, function(){saveNotes(true);});
|
|
};
|
|
|
|
oCATC.onQuitPage = function() {
|
|
return save(true);
|
|
};
|
|
|
|
oCATC.onFeedback = function(sType, sMsg)
|
|
{
|
|
var $Feedback = $('#notes_feedback').stop();
|
|
if(sMsg != $Feedback.find('span').text()) {
|
|
$Feedback.fadeOut($Feedback.is(':empty')?0:'fast', function(){
|
|
$(this)
|
|
.empty()
|
|
.append($('<span>', {'class':sType}).text(sMsg))
|
|
.fadeIn('fast');
|
|
});
|
|
}
|
|
};
|
|
|
|
function save(bForce)
|
|
{
|
|
if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer);
|
|
var bSave = (oEditor.keystrokes % 20 == 0 || bForce);
|
|
|
|
if(bSave) {
|
|
if(self.tmp('saving')) {
|
|
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
|
}
|
|
else {
|
|
var sContent = oEditor.getContent();
|
|
if(oEditor.id != 0) {
|
|
self.tmp('saving', true);
|
|
oCATC.onFeedback('info', 'Saving...');
|
|
getInfo(
|
|
'set_note',
|
|
function(sDesc, asData) {
|
|
oCATC.feedback('notice', 'Note saved ('+asData.led.substr(11, 5)+')');
|
|
self.tmp('saving', false);
|
|
},
|
|
{
|
|
id: self.tmp('id_course'),
|
|
content: sContent
|
|
},
|
|
function(sError) {
|
|
oCATC.feedback('error', 'Not saved! An error occured: '+sError);
|
|
self.tmp('saving', false);
|
|
oSaveTimer = setTimeout(save, 1000);
|
|
},
|
|
'POST'
|
|
);
|
|
}
|
|
else oCATC.feedback('error', 'No Course ID');
|
|
}
|
|
}
|
|
else {
|
|
oSaveTimer = setTimeout(function(){save(true);}, 1000*5);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
</script> |