diff --git a/routes/index.js b/routes/index.js index 5ec5f17..3f0cad0 100644 --- a/routes/index.js +++ b/routes/index.js @@ -118,9 +118,7 @@ exports.handleDeleteIQSet = function(req, res) { exports.handlePostNewIQSet = function(req, res) { console.log("\n\n[BODY of json request]"); - console.log("\t>> %j\n", req.body); - console.log("[HEADERS of json request]"); - console.log("\t>> %j\n\n", req.headers); + console.log("%j\n", req.body); var headers = req.headers; var iqset; @@ -136,21 +134,9 @@ exports.handlePostNewIQSet = function(req, res) { iqset = req.body; } - if (!iqset.title) { - // iqset.title = iqdoc.date + "-IQSet"; - } - - if (!iqset.teachername) { - // iqset.teachername = "Teacher"; - } - - if (!iqset.groupname) { - // iqset.groupname = "General"; - } - - if (!iqset.iqdata) { - isValid = false; - } + // Adding values of the current session before saving the IQSet + iqset.teachername = game.teacherName; + iqset.groupname = game.groupName; if (isValid === true) { // @@ -165,7 +151,6 @@ exports.handlePostNewIQSet = function(req, res) { // 1. Get the original index of the image // 2. Change the PICURL to match the new index // - if (iqset.iqdata[i].PICURL) { // /smile/questionview/1.jpg var tmpidx = parseInt(iqset.iqdata[i].PICURL.split('/')[3].split('.')[0], 10); diff --git a/static/js/smileteacher.js b/static/js/smileteacher.js index b3fd265..334a974 100644 --- a/static/js/smileteacher.js +++ b/static/js/smileteacher.js @@ -33,9 +33,19 @@ var VERSION = '0.0.2'; var SMILEROUTES = { "currentmessage": "/smile/currentmessage", "all": "/smile/all", + "iqsets": "/smile/iqsets", + "iqset": "/smile/iqset/", "createsession": "/smile/createsession" }; +var IQSet = function(id,title,teacherName,groupName,date) { + //var self = this; + this.id = id; + this.sessionName = title; + this.teacherName = teacherName; + this.groupName = groupName; + this.date = date; +} // // KO Extenders @@ -67,38 +77,32 @@ var GlobalViewModel = { teacher_name: ko.observable(""), session_name: ko.observable(""), group_name: ko.observable(""), + iqsets: ko.observableArray([]), + iqsetToLoad: ko.observable(''), version: ko.observable(VERSION) }; GlobalViewModel.createSession = function() { - var self = this; - if (!self.teacher_name() || self.teacher_name() === "") { - - self.teacher_name('Default Teacher'); - } - if (!self.session_name() || self.session_name() === "") { - - self.session_name('Default Session'); - } - if (!self.group_name() || self.group_name() === "") { - - self.group_name('Default Group'); - } + //var self = this; + + if (!this.teacher_name() || this.teacher_name() === "") { this.teacher_name('Default Teacher'); } + if (!this.session_name() || this.session_name() === "") { this.session_name('Default Session'); } + if (!this.group_name() || this.group_name() === "") { this.group_name('Default Group'); } $.ajax({ cache: false, type: "POST", dataType: "text", - url: SMILEROUTES["createsession"], + url: SMILEROUTES["createsession"], data: {"teacherName":GlobalViewModel.teacher_name,"groupName":GlobalViewModel.group_name,"sessionName":GlobalViewModel.session_name}, error: function(xhr, text, err) { smileAlert('#globalstatus', 'Unable to post session values. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', 'trace'); }, success: function(data) { - smileAlert('#globalstatus', 'Success ('+self.teacher_name()+','+self.session_name()+','+self.group_name()+')', 'green', 5000); - switchSection('div[data-slug=chooseActivityFlow]'); + smileAlert('#globalstatus', 'Success ('+GlobalViewModel.teacher_name()+','+GlobalViewModel.session_name()+','+GlobalViewModel.group_name()+')', 'green', 5000); + switchSection('div[data-slug=choose-activity-flow]'); } }); @@ -119,11 +123,47 @@ GlobalViewModel.startMakingQuestions = function() { GlobalViewModel.usePreparedQuestions = function() { - smileAlert('#globalstatus', 'Load iqsets', 'green', 5000); + //smileAlert('#globalstatus', 'Load iqsets', 'green', 5000); + + 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/all. 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; + + for (i = 0; i < dataObject.total_rows; i++) { + + GlobalViewModel.iqsets.push( + new IQSet( + i, + iqsets[i].value[0], + iqsets[i].value[1], + iqsets[i].value[2], + iqsets[i].key.substr(0, 10) + ) + ); + //smileAlert('#globalstatus', iqsets[i].value[0], 'blue', 7000); + } + } + }); + return false; } + GlobalViewModel.resetSessionValues = function() { this.teacher_name(""); @@ -157,8 +197,6 @@ GlobalViewModel.initializePage = function() { // If a session is already running, we replace the session values fields by a "recovering session" button if(data.indexOf('SessionID') !== -1 ){ - //$('div[data-slug=create-session]').parent().removeClass('active'); - //$('div[data-slug=recover-session]').parent().addClass('active'); switchSection('div[data-slug=recover-session]'); } } diff --git a/static/smile-teacher.html b/static/smile-teacher.html index d8e3ec2..3fd51ac 100644 --- a/static/smile-teacher.html +++ b/static/smile-teacher.html @@ -95,7 +95,6 @@