Skip to content

Commit

Permalink
[RazortoothRTC#39] Use prepared questions step is coming: IQSets listed
Browse files Browse the repository at this point in the history
  • Loading branch information
chrqls committed Apr 19, 2014
1 parent 3ccb8c4 commit 5a43eff
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 34 deletions.
70 changes: 53 additions & 17 deletions static/js/smileteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ 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(title,teacherName,groupName,date) {
var self = this;
self.sessionName = title;
self.teacherName = teacherName;
self.groupName = groupName;
self.date = date;
}

//
// KO Extenders
Expand Down Expand Up @@ -67,38 +76,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');
}
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'); }

$.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]');
switchSection('div[data-slug=choose-activity-flow]');
}
});

Expand All @@ -119,11 +122,46 @@ 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(
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 +195,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
31 changes: 14 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,37 @@ <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: sessionName}, checked: $root.iqsetToLoad" />
<span data-bind="text: sessionName"></span>
</div>
</div>


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

0 comments on commit 5a43eff

Please sign in to comment.