Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#39] Updating web client for teacher #56

Merged
merged 4 commits into from
Apr 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
//
Expand All @@ -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);
Expand Down
76 changes: 57 additions & 19 deletions static/js/smileteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]');
}
});

Expand All @@ -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("");
Expand Down Expand Up @@ -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]');
}
}
Expand Down
34 changes: 17 additions & 17 deletions static/smile-teacher.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ <h3>
<a href="#" data-bind='click: resetSessionValues' class="button">Reset</a>
</li>
</ul>
</form>
</div>
</section>

Expand All @@ -108,39 +107,40 @@ <h3>
<a href="#" data-bind='click: recoverSession' class="button">Recovering session</a>
</li>
</ul>
</form>
</div>
</section>

<section>

<div class="content" data-slug="chooseActivityFlow" data-section-content>
<div class="content" data-slug="choose-activity-flow" data-section-content>
<ul class="button-group even two-up">
<li>
<a href="#" data-bind='click: startMakingQuestions' class="button">Start making questions</a>
</li>
<li>
<a href="#" data-bind='click: usePreparedQuestions' class="button">Use Prepared Questions</a>
</li>
</ul>
</form>
</ul>
</div>
</section>

<!--section>
<section>

<div class="content" data-slug="chooseActivityFlow" data-section-content>
<ul class="button-group even two-up">
<li>
<a href="#" data-bind='click: startMakingQuestions' class="button">Start making questions</a>
</li>
<li>
<a href="#" data-bind='click: usePreparedQuestions' class="button">Use Prepared Questions</a>
</li>
</ul>
</form>
<div class="content" data-slug="choose-an-iqset" data-section-content>

<div data-bind="foreach: iqsets" >
<div>
<input type="radio" name="optionsGroup" data-bind="attr: {value: id}, checked: $root.iqsetToLoad" />
<span data-bind="text: sessionName"></span>
(<span data-bind="text: teacherName"></span>,
<span data-bind="text: groupName"></span>,
<span data-bind="text: date"></span>)
</div>
</div>


</div>
</section-->
</section>
</div>
</nav>
</div>
Expand Down