From ad66305ad9b21fd2b1e9c5fa77a18e652278d76c Mon Sep 17 00:00:00 2001 From: chrqls Date: Fri, 18 Apr 2014 17:09:39 +0200 Subject: [PATCH 1/2] [#39] home page displays different content if a session is already running --- static/js/smileteacher.js | 100 +++++++++++++++++++++++--------------- static/smile-teacher.html | 21 ++++++-- 2 files changed, 77 insertions(+), 44 deletions(-) diff --git a/static/js/smileteacher.js b/static/js/smileteacher.js index 0ea7a3b..2717acd 100644 --- a/static/js/smileteacher.js +++ b/static/js/smileteacher.js @@ -28,11 +28,11 @@ #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **/ -var VERSION = '1.0.1'; -var SMILESTATE = "1"; +var VERSION = '0.0.2'; +//var SMILESTATE = "1"; var SMILEROUTES = { "currentmessage": "/smile/currentmessage", - "checkserver": "/smile/", + "all": "/smile/all", "createsession": "/smile/createsession" }; @@ -67,11 +67,10 @@ var GlobalViewModel = { teacher_name: ko.observable(""), session_name: ko.observable(""), group_name: ko.observable(""), - hasSubmitted: ko.observable(false), version: ko.observable(VERSION) }; -GlobalViewModel.doLogin = function() { +GlobalViewModel.createSession = function() { var self = this; if (!self.teacher_name() || self.teacher_name() === "") { @@ -86,47 +85,91 @@ GlobalViewModel.doLogin = function() { self.group_name('Default Group'); } + + $.ajax({ + cache: false, + type: "POST", + dataType: "text", + 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'); + //GlobalViewModel.hasSubmitted(false); // Reset this so clicks will work + }, + success: function(data) { + smileAlert('#globalstatus', 'Success ('+self.teacher_name()+','+self.session_name()+','+self.group_name()+')', 'green', 5000); + // Move to state 2 now + //SMILESTATE = '2'; + } + }); - if (!self.hasSubmitted()) { - console.log('doLogin'); - smileAlert('#globalstatus', 'Logging in ('+self.teacher_name()+','+self.teacher_name()+','+self.teacher_name()+')', 'green', 5000); - doSmileLogin(); - } + return false; +} - self.hasSubmitted(true); +GlobalViewModel.recoverSession = function() { + smileAlert('#globalstatus', 'Session recovered', 'green', 5000); return false; } -GlobalViewModel.doLoginReset = function() { +GlobalViewModel.resetSessionValues = function() { this.teacher_name(""); this.session_name(""); this.group_name(""); - this.hasSubmitted(false); // // XXX This is silly, fix this, cleanup the object model and reset the state // For now just reload the page // - window.location.href = window.location.pathname; - window.location.reload(true); + //window.location.href = window.location.pathname; + //window.location.reload(true); return false; } +GlobalViewModel.initializePage = function() { + + //var alreadyRunning = false; + + $.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 ){ + $('div[data-slug=create-session]').parent().removeClass('active'); + $('div[data-slug=recover-session]').parent().addClass('active'); + } + } + }); +} $(document).ready(function() { - // // Init Data Model - // ko.applyBindings(GlobalViewModel); + GlobalViewModel.initializePage(); + }); // NEEDED +function foobar() { + + return false; +} + // // App functions // @@ -169,27 +212,4 @@ function smileAlert(targetid, text, alerttype, lifetime) { $(targetid).find('.alert-box').fadeOut().remove(); }, lifetime) } -} - -function doSmileLogin() { - - var clientip; - - $.ajax({ - cache: false, - type: "POST", - dataType: "text", - 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 login. Reason: ' + xhr.status + ':' + xhr.responseText + '. Please verify your connection or server status.', 'trace'); - GlobalViewModel.hasSubmitted(false); // Reset this so clicks will work - }, - success: function(data) { - smileAlert('#globalstatus', 'Successfully logged in', 'green', 10000); - // Move to state 2 now - SMILESTATE = '2'; - } - }); } \ No newline at end of file diff --git a/static/smile-teacher.html b/static/smile-teacher.html index b086644..249d6ab 100644 --- a/static/smile-teacher.html +++ b/static/smile-teacher.html @@ -75,7 +75,7 @@

-
+
@@ -89,11 +89,24 @@

+ +

+
+ + +
+ +
+ From 2d1f0c2d74659fd610574f76346b19509fc44a7e Mon Sep 17 00:00:00 2001 From: chrqls Date: Fri, 18 Apr 2014 18:39:31 +0200 Subject: [PATCH 2/2] [#39] choose activity flow step... --- static/js/smileteacher.js | 29 +++++++++++++++++++------- static/smile-teacher.html | 43 +++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/static/js/smileteacher.js b/static/js/smileteacher.js index 2717acd..b3fd265 100644 --- a/static/js/smileteacher.js +++ b/static/js/smileteacher.js @@ -95,12 +95,10 @@ GlobalViewModel.createSession = function() { 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'); - //GlobalViewModel.hasSubmitted(false); // Reset this so clicks will work }, success: function(data) { smileAlert('#globalstatus', 'Success ('+self.teacher_name()+','+self.session_name()+','+self.group_name()+')', 'green', 5000); - // Move to state 2 now - //SMILESTATE = '2'; + switchSection('div[data-slug=chooseActivityFlow]'); } }); @@ -113,6 +111,18 @@ GlobalViewModel.recoverSession = function() { return false; } +GlobalViewModel.startMakingQuestions = function() { + + smileAlert('#globalstatus', 'Start making questions', 'green', 5000); + return false; +} + +GlobalViewModel.usePreparedQuestions = function() { + + smileAlert('#globalstatus', 'Load iqsets', 'green', 5000); + return false; +} + GlobalViewModel.resetSessionValues = function() { @@ -147,8 +157,9 @@ 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'); + //$('div[data-slug=create-session]').parent().removeClass('active'); + //$('div[data-slug=recover-session]').parent().addClass('active'); + switchSection('div[data-slug=recover-session]'); } } }); @@ -164,10 +175,14 @@ $(document).ready(function() { }); // NEEDED - function foobar() { + smileAlert('#globalstatus', 'Not yet implemented', 'blue',5000); +} + +function switchSection(newSection) { - return false; + $('section.active').removeClass('active'); + $(newSection).parent().addClass('active'); } // diff --git a/static/smile-teacher.html b/static/smile-teacher.html index 249d6ab..d8e3ec2 100644 --- a/static/smile-teacher.html +++ b/static/smile-teacher.html @@ -56,8 +56,7 @@

Welcome to SMILE Teacher Web

- SMILE Teacher - + SMILE Teacher

@@ -81,11 +80,11 @@

--> - + - + - +
  • @@ -113,6 +112,35 @@

+
+ + +
+ + @@ -124,9 +152,8 @@

- Instructions for -
Teacher
- + Instructions for +
Teacher