Skip to content

Commit

Permalink
[RazortoothRTC#39] Preview IQSet is working
Browse files Browse the repository at this point in the history
  • Loading branch information
chrqls committed Apr 29, 2014
1 parent 20b9116 commit 3e310ff
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 49 deletions.
100 changes: 63 additions & 37 deletions static/js/smileteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
var VERSION = '0.1.5';

var SMILEROUTES = {
"currentmessage": "/smile/currentmessage",
//"currentmessage": "/smile/currentmessage",
"all": "/smile/all",
"iqsets": "/smile/iqsets",
"iqset": "/smile/iqset/",
"createsession": "/smile/createsession"
"question":"/smile/question",
"createsession": "/smile/createsession",
"startmakequestion":"startmakequestion"
};

var TEMP_IQSET = '';
var TEMP_IQSETS = [];
var TEMP_POSITION = 0;
//var READY = false;

/* --------
MODELS
Expand Down Expand Up @@ -77,6 +79,11 @@ var GlobalViewModel = {
session_name: ko.observable(""),
group_name: ko.observable(""),
iqsets: ko.observableArray([]),

// Preview IQSet
iqset_to_preview: ko.observable(''),
questions_to_preview: ko.observableArray([]),

position: ko.observable(''),
questions: ko.observableArray([]),
version: ko.observable(VERSION)
Expand Down Expand Up @@ -171,10 +178,10 @@ GlobalViewModel.createSession = function() {

GlobalViewModel.usePreparedQuestions = function() {

// Refresh
//GlobalViewModel.iqsets = [];
switchSection('div[data-slug=choose-an-iqset]');



$.ajax({
cache: false,
type: "GET",
Expand All @@ -191,7 +198,9 @@ GlobalViewModel.usePreparedQuestions = function() {
var dataObject = JSON.parse(data);
var iqsets = dataObject.rows;

TEMP_POSITION = 0;
//TEMP_POSITION = 0;

GlobalViewModel.iqsets.removeAll();

for (i = 0; i < dataObject.total_rows; i++) {

Expand Down Expand Up @@ -258,15 +267,41 @@ GlobalViewModel.usePreparedQuestions = function() {
return false;
}

function previewIQSet() {

// Do something
//alert($(this).parent().find('input[name=id]').attr('value'));
function previewIQSet(idIQSet) {

var iqset = JSON.parse(getJsonIQSet(idIQSet));
var iqdata = iqset.iqdata;
GlobalViewModel.questions_to_preview.removeAll();

for (i = 0; i < iqdata.length; i++) {

var options = [];
options.push(iqdata[i].O1,iqdata[i].O2,iqdata[i].O3,iqdata[i].O4);

GlobalViewModel.questions_to_preview.push(
new Question(
i,
iqdata[i].PICURL,
iqdata[i].NAME,
iqdata[i].Q,
iqdata[i].A,
options,
iqdata[i].IP,
iqdata[i].TYPE
)
);
}
///

//smileAlert('#globalstatus', 'iqset='+iqset, 'blue', 7000);

//GlobalViewModel.iqset_to_preview = iqset;
//GlobalViewModel.questions_to_preview = iqset.iqdata;

//alert(iqset.iqdata);

switchSection('div[data-slug=preview-iqset]');

//smileAlert('#globalstatus', '1st attempt='+$(this).val(), 'blue', 10000);
smileAlert('#globalstatus', '1st attempt='+$(this).attr('name'), 'blue', 10000); // should display the string 'id'
smileAlert('#globalstatus', '2nd attempt='+$(this).attr('value'), 'blue', 10000); // should display a very long id
smileAlert('#globalstatus', '3rd attempt='+$(this).parent().find('input[type=hidden]').attr('name'), 'blue', 10000); // should display a very long id
}

GlobalViewModel.recoverSession = function() {
Expand Down Expand Up @@ -333,10 +368,9 @@ $(document).ready(function() {

GlobalViewModel.initializePage();

$('#more').click(function () {

alert('test');
});
// TEMP
var essai = getJsonIQSet('342E5328-BA65-437D-ABCA-BE1A735E3D49');
smileAlert('#globalstatus', 'essai='+essai, 'blue', 7000);
});

/* ---------
Expand All @@ -357,40 +391,32 @@ function sleep(seconds) {

GlobalViewModel.foobar = function() {

//smileAlert('#globalstatus', 'TEMP_IQSETS='+TEMP_IQSETS.length, 'blue', 15000);
smileAlert('#globalstatus', 'GlobalViewModel.iqsets.length='+GlobalViewModel.iqsets.total_rows, 'blue', 15000);
}

GlobalViewModel.addFakeIQSet = function() {

GlobalViewModel.iqsets.push(
new IQSet(i,'blabla','name','teacher','group','date',0)
);
}

/*
function getJsonIQSet(id) {
var jsonIQSet = '';

$.ajax({
cache: false,
type: "GET",
dataType: "text",
url: SMILEROUTES["iqset"]+id,
async: false,
data: {},
error: function(xhr, text, err) { smileAlert('#globalstatus', 'Unable to ajax in ajax.', 'trace'); },
success: function(data) {
jsonIQSet = JSON.parse(data);

error: function(xhr, text, err) {
smileAlert('#globalstatus', 'Unable to call /smile/iqset/{key}', 'trace',8000);
},

success: function(data) {

TEMP_IQSET = data;
}
});

while(jsonIQSet === '') { var lol = 'lol'; }
smileAlert('#globalstatus', 'A la sortie >> '+jsonIQSet, 'blue',5000);
return jsonIQSet;
return TEMP_IQSET;
}
*/


// alerttype
// - by default, none is required if you don't intend to use lifetime
Expand Down
29 changes: 17 additions & 12 deletions static/smile-teacher.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ <h3>
</section>

<section>

<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: position}, checked: $root.position" />
<input type="hidden" name="id" data-bind="attr: {value: id}" />
<a id="more" onclick="previewIQSet()" data-bind="attr: {name: id}" class="tiny round button more">more</a>
<a id="more" onclick="previewIQSet(this.name)" data-bind="attr: {name: id}" class="tiny round button more">more</a>
<span data-bind="text: sessionName"></span>
(<span data-bind="text: teacherName"></span>,
<span data-bind="text: groupName"></span>,
Expand All @@ -129,32 +127,39 @@ <h3>
</div>
<ul class="button-group even two-up">
<li><a href="#" data-bind='click: startMakingQuestionsWithIQSet' class="button">Load</a></li>
<!--
<li><a href="#" data-bind='click: foobar' class="button">FINAL</a></li>
<li><a href="#" data-bind='click: addFakeIQSet' class="button">ADD</a></li>
-->
</ul>
</div>
</section>

<section>

<div class="content" data-slug="list-questions" data-section-content>

<div data-bind="foreach: questions" >
<div>
<input type="checkbox" name="questionsToSave" data-bind="attr: {value: position}, checked: $root.position" />
<span data-bind="text: position"></span> -
<span data-bind="text: author"></span> -
<span data-bind="text: ip"></span> -
<span data-bind="text: type"></span>

</div>
</div>

</div>

</section>

<section>
<div class="content" data-slug="preview-iqset" data-section-content>

<!--div data-bind="text: title"></div-->
<div data-bind="foreach: questions_to_preview" >
<div>
<span data-bind="text: question"></span> <span data-bind="text: answer"></span>
</div>
</div>
<ul class="button-group even two-up">
<li><a href="#" data-bind='click: usePreparedQuestions' class="button">Back</a></li>
</ul>
</div>
</section>

</div>
</nav>
</div>
Expand Down

0 comments on commit 3e310ff

Please sign in to comment.