Skip to content

Commit

Permalink
[RazortoothRTC#39] home page displays different content if a session …
Browse files Browse the repository at this point in the history
…is already running
  • Loading branch information
chrqls committed Apr 18, 2014
1 parent ef11ae4 commit ad66305
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 44 deletions.
100 changes: 60 additions & 40 deletions static/js/smileteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

Expand Down Expand Up @@ -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() === "") {
Expand All @@ -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
//
Expand Down Expand Up @@ -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';
}
});
}
21 changes: 17 additions & 4 deletions static/smile-teacher.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h3>

<section class="active">

<div class="content" data-slug="login-pane1" data-section-content>
<div class="content" data-slug="create-session" data-section-content>
<!-- NICE DEBUG TRICK -->
<!-- KO:<span data-bind="text: ko.toJSON($data)"></span>
<form action="return false;"> -->
Expand All @@ -89,11 +89,24 @@ <h3>

<ul class="button-group even two-up">
<li>
<a href="#" data-bind='click: doLogin, disable: hasSubmitted'
class="button">Submit</a>
<a href="#" data-bind='click: createSession'
class="button">Next</a>
</li>
<li>
<a href="#" data-bind='click: doLoginReset' class="button">Reset</a>
<a href="#" data-bind='click: resetSessionValues' class="button">Reset</a>
</li>
</ul>
</form>
</div>
</section>


<section>

<div class="content" data-slug="recover-session" data-section-content>
<ul class="button-group even two-up">
<li>
<a href="#" data-bind='click: recoverSession' class="button">Recovering session</a>
</li>
</ul>
</form>
Expand Down

0 comments on commit ad66305

Please sign in to comment.