diff --git a/static/js/smileteacher.js b/static/js/smileteacher.js index 146b742..139c202 100644 --- a/static/js/smileteacher.js +++ b/static/js/smileteacher.js @@ -28,7 +28,7 @@ #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **/ -var VERSION = '0.1.2'; +var VERSION = '0.1.5'; var SMILEROUTES = { "currentmessage": "/smile/currentmessage", @@ -38,6 +38,10 @@ var SMILEROUTES = { "createsession": "/smile/createsession" }; +var TEMP_IQSETS = []; +var TEMP_POSITION = 0; +//var READY = false; + /* -------- MODELS -------- */ @@ -63,8 +67,11 @@ var IQSet = function(position,id,title,teacherName,groupName,date) { this.groupName = groupName; this.date = date; this.questions = []; + //this.size = size; } + + var GlobalViewModel = { teacher_name: ko.observable(""), session_name: ko.observable(""), @@ -104,6 +111,40 @@ ko.extenders.required = function(target, overrideMessage) { /* --------- ACTIONS --------- */ + +// Displays directly a "Recovering Session" button if a session is already running +GlobalViewModel.initializePage = function() { + + $.ajax({ + cache: false, + type: "GET", + dataType: "text", + url: SMILEROUTES["all"], + data: {}, + + error: function(xhr, text, err) { + smileAlert('#globalstatus', 'Unable to call /smile/all. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', 'trace'); + }, + success: function(data) { + + // If a session is already running, we replace the session values fields by a "recovering session" button + if(data.indexOf('SessionID') !== -1 ){ + switchSection('div[data-slug=recover-session]'); + } + } + }); +} + +GlobalViewModel.resetSessionValues = function() { + + this.teacher_name(""); + this.session_name(""); + this.group_name(""); + //window.location.href = window.location.pathname; + //window.location.reload(true); + return false; +} + GlobalViewModel.createSession = function() { if (!this.teacher_name() || this.teacher_name() === "") { this.teacher_name('Default Teacher'); } @@ -128,6 +169,106 @@ GlobalViewModel.createSession = function() { return false; } +GlobalViewModel.usePreparedQuestions = function() { + + switchSection('div[data-slug=choose-an-iqset]'); + + + + $.ajax({ + cache: false, + type: "GET", + dataType: "text", + url: SMILEROUTES["iqsets"], + data: {}, + + error: function(xhr, text, err) { + smileAlert('#globalstatus', 'Unable to call /smile/iqsets. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', 'trace'); + }, + + success: function(data) { + + var dataObject = JSON.parse(data); + var iqsets = dataObject.rows; + + TEMP_POSITION = 0; + + for (i = 0; i < dataObject.total_rows; i++) { + + // Getting the values accessible from /smile/iqsets + /* + TEMP_IQSET.position = i; + TEMP_IQSET.id = iqsets[i].id; + TEMP_IQSET.sessionName = iqsets[i].value[0]; + TEMP_IQSET.teacherName = iqsets[i].value[1]; + TEMP_IQSET.groupName = iqsets[i].value[2]; + TEMP_IQSET.date = iqsets[i].key.substr(0, 10); + */ + + GlobalViewModel.iqsets.push(new IQSet( + i, + iqsets[i].id, + iqsets[i].value[0], + iqsets[i].value[1], + iqsets[i].value[2], + iqsets[i].key.substr(0, 10) + )); + + //smileAlert('#globalstatus', 'during push='+GlobalViewModel.iqsets.length, 'blue', 15000); + + + /* + // Getting the values accessible from /smile/iqset/{id} (for now, the size) + $.ajax({ + cache: false, + type: "GET", + dataType: "text", + url: SMILEROUTES["iqset"]+iqsets[i].id, + data: {}, + error: function(xhr, text, err) { smileAlert('#globalstatus', 'Unable to ajax in ajax.', 'trace'); }, + + success: function(data) { + var iqset = JSON.parse(data); + + + smileAlert('#globalstatus', 'TEMP_POSITION='+TEMP_POSITION, 'green', 15000); + //GlobalViewModel.iqsets[0].size = iqset.iqdata.length; + + TEMP_POSITION++; + + //smileAlert('#globalstatus', '???='+iqset.title, 'green', 15000); + + + // The IQSet is ready, we can add it to the list + //GlobalViewModel.iqsets.push(TEMP_IQSET); + + //smileAlert('#globalstatus', 'session name='+TEMP_IQSET.sessionName, 'green', 5000); + } + }); + + */ + } + } + }); + + //smileAlert('#globalstatus', 'FINAL='+GlobalViewModel.iqsets.length, 'blue', 15000); + + //GlobalViewModel.iqsets = TEMP_IQSETS; + + return false; +} + +function previewIQSet() { + + // Do something + //alert($(this).parent().find('input[name=id]').attr('value')); + + //smileAlert('#globalstatus', '1st attempt='+$(this).val(), 'blue', 10000); + smileAlert('#globalstatus', '1st attempt='+$(this).attr('name'), 'blue', 10000); // should display the string 'id' + smileAlert('#globalstatus', '2nd attempt='+$(this).attr('value'), 'blue', 10000); // should display a very long id + smileAlert('#globalstatus', '3rd attempt='+$(this).parent().find('input[type=hidden]').attr('name'), 'blue', 10000); // should display a very long id +} + GlobalViewModel.recoverSession = function() { smileAlert('#globalstatus', 'Session recovered', 'green', 5000); @@ -176,11 +317,7 @@ GlobalViewModel.startMakingQuestionsWithIQSet = function() { ) ); } - - GlobalViewModel.title_iqset = iqset.title; - - //smileAlert('#globalstatus', 'title_iqset='+GlobalViewModel.title_iqset, 'blue', 15000); - //smileAlert('#globalstatus', 'questions='+GlobalViewModel.questions()[0].author, 'blue', 5000); + //GlobalViewModel.title_iqset = iqset.title; } }); @@ -189,94 +326,71 @@ GlobalViewModel.startMakingQuestionsWithIQSet = function() { return false; } -GlobalViewModel.usePreparedQuestions = function() { +$(document).ready(function() { + + // Init Data Model + ko.applyBindings(GlobalViewModel); - switchSection('div[data-slug=choose-an-iqset]'); + GlobalViewModel.initializePage(); - $.ajax({ - cache: false, - type: "GET", - dataType: "text", - url: SMILEROUTES["iqsets"], - data: {}, - - error: function(xhr, text, err) { - smileAlert('#globalstatus', 'Unable to call /smile/iqsets. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', 'trace'); - }, - - success: function(data) { + $('#more').click(function () { - var dataObject = JSON.parse(data); - var iqsets = dataObject.rows; + alert('test'); + }); +}); - for (i = 0; i < dataObject.total_rows; i++) { +/* --------- + UTILITY + --------- */ - GlobalViewModel.iqsets.push( - new IQSet( - i, - iqsets[i].id, - iqsets[i].value[0], - iqsets[i].value[1], - iqsets[i].value[2], - iqsets[i].key.substr(0, 10) - ) - ); - } - } - }); +function switchSection(newSection) { + $('section.active').removeClass('active'); + $(newSection).parent().addClass('active'); +} - return false; +function sleep(seconds) { + + var now = new Date(); + var desiredTime = new Date().setSeconds(now.getSeconds() + seconds); + while (now < desiredTime) { now = new Date(); } } -GlobalViewModel.resetSessionValues = function() { +GlobalViewModel.foobar = function() { - this.teacher_name(""); - this.session_name(""); - this.group_name(""); - //window.location.href = window.location.pathname; - //window.location.reload(true); - return false; + //smileAlert('#globalstatus', 'TEMP_IQSETS='+TEMP_IQSETS.length, 'blue', 15000); + smileAlert('#globalstatus', 'GlobalViewModel.iqsets.length='+GlobalViewModel.iqsets.total_rows, 'blue', 15000); } -// Displays directly a "Recovering Session" button if a session is already running -GlobalViewModel.initializePage = function() { +GlobalViewModel.addFakeIQSet = function() { + + GlobalViewModel.iqsets.push( + new IQSet(i,'blabla','name','teacher','group','date',0) + ); +} + +/* +function getJsonIQSet(id) { + + var jsonIQSet = ''; $.ajax({ cache: false, type: "GET", dataType: "text", - url: SMILEROUTES["all"], + url: SMILEROUTES["iqset"]+id, data: {}, - - error: function(xhr, text, err) { - smileAlert('#globalstatus', 'Unable to call /smile/all. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', 'trace'); - }, - success: function(data) { - - // If a session is already running, we replace the session values fields by a "recovering session" button - if(data.indexOf('SessionID') !== -1 ){ - switchSection('div[data-slug=recover-session]'); - } + error: function(xhr, text, err) { smileAlert('#globalstatus', 'Unable to ajax in ajax.', 'trace'); }, + success: function(data) { + jsonIQSet = JSON.parse(data); + } }); -} - -$(document).ready(function() { - - // Init Data Model - ko.applyBindings(GlobalViewModel); - GlobalViewModel.initializePage(); -}); - -/* --------- - UTILITY - --------- */ - -function switchSection(newSection) { - $('section.active').removeClass('active'); - $(newSection).parent().addClass('active'); + while(jsonIQSet === '') { var lol = 'lol'; } +smileAlert('#globalstatus', 'A la sortie >> '+jsonIQSet, 'blue',5000); + return jsonIQSet; } +*/ // alerttype // - by default, none is required if you don't intend to use lifetime diff --git a/static/smile-teacher.html b/static/smile-teacher.html index e541193..7e71d70 100644 --- a/static/smile-teacher.html +++ b/static/smile-teacher.html @@ -119,6 +119,8 @@

+ + more (, , @@ -127,6 +129,10 @@

@@ -138,7 +144,11 @@

- + - + - + - + +