Commit 6598d2b0 by Braden MacDonald

JS changes to get "Mentoring With Only One Step" scenario working

parent 338c6d50
......@@ -61,10 +61,12 @@ function MessageView(element, mentoring) {
};
}
function MCQBlock(runtime, element, mentoring) {
function MCQBlock(runtime, element) {
return {
mode: null,
mentoring: null,
init: function(options) {
this.mentoring = options.mentoring;
this.mode = options.mode;
$('input[type=radio]', element).on('change', options.onChange);
},
......@@ -83,6 +85,8 @@ function MCQBlock(runtime, element, mentoring) {
if (this.mode === 'assessment')
return;
mentoring = this.mentoring;
var messageView = MessageView(element, mentoring);
messageView.clearResult();
......@@ -123,7 +127,7 @@ function MCQBlock(runtime, element, mentoring) {
},
clearResult: function() {
MessageView(element, mentoring).clearResult();
MessageView(element, this.mentoring).clearResult();
},
validate: function(){
......@@ -136,7 +140,9 @@ function MCQBlock(runtime, element, mentoring) {
function MRQBlock(runtime, element, mentoring) {
return {
mode: null,
mentoring: null,
init: function(options) {
this.mentoring = options.mentoring;
this.mode = options.mode;
$('input[type=checkbox]', element).on('change', options.onChange);
},
......@@ -155,6 +161,8 @@ function MRQBlock(runtime, element, mentoring) {
if (this.mode === 'assessment')
return;
mentoring = this.mentoring;
var messageView = MessageView(element, mentoring);
if (result.message) {
......@@ -193,7 +201,7 @@ function MRQBlock(runtime, element, mentoring) {
},
clearResult: function() {
MessageView(element, mentoring).clearResult();
MessageView(element, this.mentoring).clearResult();
},
validate: function(){
......
function MentoringBlock(runtime, element) {
var attemptsTemplate = _.template($('#xblock-attempts-template').html());
var data = $('.mentoring', element).data();
var children_dom = []; // Keep track of children. A Child need a single object scope for its data.
var children = [];
var children = runtime.children(element);
var step = data.step;
var mentoring = {
callIfExists: callIfExists,
setContent: setContent,
renderAttempts: renderAttempts,
renderDependency: renderDependency,
children: children,
initChildren: initChildren,
getChildByName: getChildByName,
step: step,
publish_event: publish_event
};
function publish_event(data) {
$.ajax({
type: "POST",
......@@ -66,41 +77,14 @@ function MentoringBlock(runtime, element) {
}
}
function readChildren() {
var doms = $('.xblock-light-child', element);
$.each(doms, function(index, child_dom) {
var child_type = $(child_dom).attr('data-type');
var child = window[child_type];
children_dom.push(child_dom);
children.push(child);
if (typeof child !== 'undefined') {
child = child(runtime, child_dom, mentoring);
child.name = $(child_dom).attr('name');
children[children.length-1] = child;
}
});
}
/* Init and display a child. */
function displayChild(index, options) {
function initChildren(options) {
options = options || {};
options.mentoring = mentoring;
options.mode = data.mode;
if (index >= children.length)
return children.length;
var template = $('#light-child-template', children_dom[index]).html();
$(children_dom[index]).append(template);
$(children_dom[index]).show();
var child = children[index];
callIfExists(child, 'init', options);
return child;
}
function displayChildren(options) {
$.each(children_dom, function(index) {
displayChild(index, options);
});
for (var i=0; i < children.length; i++) {
var child = children[i];
callIfExists(child, 'init', options);
}
}
function getChildByName(element, name) {
......@@ -112,21 +96,6 @@ function MentoringBlock(runtime, element) {
}
}
var mentoring = {
callIfExists: callIfExists,
setContent: setContent,
renderAttempts: renderAttempts,
renderDependency: renderDependency,
readChildren: readChildren,
children_dom: children_dom,
children: children,
displayChild: displayChild,
displayChildren: displayChildren,
getChildByName: getChildByName,
step: step,
publish_event: publish_event
};
if (data.mode === 'standard') {
MentoringStandardView(runtime, element, mentoring);
}
......
......@@ -73,7 +73,7 @@ function MentoringStandardView(runtime, element, mentoring) {
onChange: onChange
};
mentoring.displayChildren(options);
mentoring.initChildren(options);
mentoring.renderAttempts();
mentoring.renderDependency();
......@@ -81,17 +81,6 @@ function MentoringStandardView(runtime, element, mentoring) {
validateXBlock();
}
function handleRefreshResults(results) {
$(element).html(results.html);
mentoring.readChildren();
initXBlockView();
}
function refreshXBlock() {
var handlerUrl = runtime.handlerUrl(element, 'view');
$.post(handlerUrl, '{}').success(handleRefreshResults);
}
// validate all children
function validateXBlock() {
var is_valid = true;
......@@ -100,8 +89,7 @@ function MentoringStandardView(runtime, element, mentoring) {
if ((data.max_attempts > 0) && (data.num_attempts >= data.max_attempts)) {
is_valid = false;
}
else {
} else {
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child && child.name !== undefined) {
......@@ -112,15 +100,12 @@ function MentoringStandardView(runtime, element, mentoring) {
}
}
}
if (!is_valid) {
submitDOM.attr('disabled','disabled');
}
else {
} else {
submitDOM.removeAttr("disabled");
}
}
// We need to manually refresh, XBlocks are currently loaded together with the section
refreshXBlock(element);
initXBlockView();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment