diff --git a/static/js/smileteacher.js b/static/js/smileteacher.js index f670e23..5d4fa6c 100644 --- a/static/js/smileteacher.js +++ b/static/js/smileteacher.js @@ -28,13 +28,14 @@ #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **/ -var VERSION = '0.7.1'; +var VERSION = '0.7.4'; // Interval of time used to update the GlobalViewModel var DELAY_UPDATE_BOARD = 5000; +var DELAY_ERROR = 60000; var DELAY_SHORT = 5000; -var DELAY_NORMAL = 10000; -var DELAY_LONG = 20000; +var DELAY_NORMAL = 10000;/* +var DELAY_LONG = 20000;*/ var SMILEROUTES = { 'all': '/smile/all', @@ -51,6 +52,13 @@ var SMILEROUTES = { var deamon_updating_board; +$(document).ready(function() { + + // Init Data Model + ko.applyBindings(GlobalViewModel); + + GlobalViewModel.redirectView(); +}); /* ------------------ @@ -107,7 +115,6 @@ var GlobalViewModel = { iqset_to_preview: ko.observableArray([]), // Start making questions - position: ko.observable(''), students: ko.observableArray([]), questions: ko.observableArray([]), @@ -143,11 +150,12 @@ ko.extenders.required = function(target, overrideMessage) { return target; }; -/* ------------------ - - ACTIONS +/* ----------------------------------- + + ACTIONS + (functions called by the view) - ------------------ */ + ----------------------------------- */ GlobalViewModel.redirectView = function() { @@ -170,6 +178,9 @@ GlobalViewModel.redirectView = function() { break; case 'START_MAKE': + // If we are at least at START_MAKE phase, we display the 'status' progress bar + switchProgressBar('loading'); + section = 'general-board'; clearInterval(deamon_updating_board); deamon_updating_board = setInterval(updateGVM, DELAY_UPDATE_BOARD); @@ -213,6 +224,7 @@ GlobalViewModel.resetSession = function() { this.session_name(''); this.group_name(''); this.status(''); + switchProgressBar(''); GlobalViewModel.questions.removeAll(); GlobalViewModel.students.removeAll(); clearInterval(deamon_updating_board); @@ -233,6 +245,7 @@ GlobalViewModel.startMakingQuestions = function() { GlobalViewModel.usePreparedQuestions = function() { + // If a session is already running, we redirect directly to the current session if(typeExist('START_MAKE')) { this.redirectView(); } else { @@ -261,6 +274,16 @@ GlobalViewModel.usePreparedQuestions = function() { iqset.iqdata.length )); } + + // Preparing listener for single selection (radio mode) + $('section[smile=list-of-iqsets] table tr').click(function() { + if(!$(this).hasClass('selected')) { + $('section[smile=list-of-iqsets] table tr.selected').each(function(index) { + $(this).removeClass('selected'); + }); + $(this).addClass('selected'); + } + }); } } @@ -310,24 +333,34 @@ function previewIQSet(idIQSet) { GlobalViewModel.startMakingQuestionsWithIQSet = function() { - var iqset = JSON.parse(smile_iqset(GlobalViewModel.iqsets()[GlobalViewModel.position()].id)); - var iqdata = iqset.iqdata; + if($('section[smile=list-of-iqsets] table tr.selected')) { + + var positionOfIQSet = document.querySelector('[smile=list-of-iqsets]') + .querySelector('[class=selected]') + .getAttribute('position_iqset'); + + /* We get the position to get the id of the iqset + var iqset = JSON.parse(smile_iqset(GlobalViewModel.iqsets()[GlobalViewModel.position()].id));*/ + var iqset = JSON.parse(smile_iqset(GlobalViewModel.iqsets()[positionOfIQSet].id)); + var iqdata = iqset.iqdata; - for (i = 0; i < iqdata.length; i++) { + for (i = 0; i < iqdata.length; i++) { - // We send each question to the server - postMessage('question',iqdata[i]); - } - - postMessage('startmake'); + // We send each question to the server + postMessage('question',iqdata[i]); + } + + postMessage('startmake'); - deamon_updating_board = setInterval(updateGVM, DELAY_UPDATE_BOARD); - location.reload(); + deamon_updating_board = setInterval(updateGVM, DELAY_UPDATE_BOARD); + location.reload(); + } else { + smileAlert('Please select an iqset', DELAY_SHORT,'red'); + } } GlobalViewModel.startSolvingQuestions = function() { - $('.start_solving').addClass('hidden'); postMessage('startsolve'); smileAlert('Trying to start solving...', DELAY_SHORT); this.redirectView(); @@ -422,10 +455,10 @@ GlobalViewModel.removeQuestionFromSession = function() { data: {}, error: function(xhr, text, err) { - smileAlert('Unable to remove question from session', DELAY_LONG, 'trace','#globalstatus'); + smileAlert('Unable to remove question from session', DELAY_ERROR, 'trace'); }, success: function(data) { - smileAlert('Question deleted', DELAY_NORMAL, 'green'); + smileAlert('Question deleted', DELAY_NORMAL, 'green'); switchSection('general-board'); } }); @@ -484,19 +517,14 @@ GlobalViewModel.saveNewIQSet = function() { } } -$(document).ready(function() { - - // Init Data Model - ko.applyBindings(GlobalViewModel); - GlobalViewModel.redirectView(); -}); -/* ------------------ +/* -------------------------------------------------------- - UTILITY + UTILITY + (encapsulation of code used by the actions) - ------------------ */ + -------------------------------------------------------- */ /* GlobalViewModel.seeContent = function() { @@ -509,40 +537,35 @@ GlobalViewModel.seeContent = function() { smileAlert('checked:'+content,10000); }*/ -function smileAlert(text, lifetime, alerttype, divId) { +function smileAlert(text, lifetime, alerttype, hasCross) { + var container = '#absolute_alerts'; var alertID = 'id_'+Math.floor(Math.random()*99999); + var cross = hasCross? '×' : ''; - // Colors - var defaultalert = 'secondary'; - var redalert = 'alert'; - var bluealert = ''; - var greenalert = 'success'; + // Types of box + var box_grey = 'secondary'; + var box_red = 'alert'; + var box_blue = ''; + var box_green = 'success'; - if (!alerttype) { alerttype = defaultalert; } - else if (alerttype === 'trace') { alerttype = redalert; - text += ' : ' + printStackTrace(); } - else if (alerttype === 'red') { alerttype = redalert; } - else if (alerttype === 'blue') { alerttype = bluealert; } - else if (alerttype === 'green') { alerttype = greenalert; } - - if(!divId || divId === '') { - divId = '#absolute_alerts'; - } + if (!alerttype) { alerttype = box_grey; } + else if (alerttype === 'trace') { alerttype = box_red; text += ' : ' + printStackTrace(); } + else if (alerttype === 'red') { alerttype = box_red; } + else if (alerttype === 'blue') { alerttype = box_blue; } + else if (alerttype === 'green') { alerttype = box_green; } - var formatstr = '
- - + - | -- | - | - | - | - |