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) { ...@@ -61,10 +61,12 @@ function MessageView(element, mentoring) {
}; };
} }
function MCQBlock(runtime, element, mentoring) { function MCQBlock(runtime, element) {
return { return {
mode: null, mode: null,
mentoring: null,
init: function(options) { init: function(options) {
this.mentoring = options.mentoring;
this.mode = options.mode; this.mode = options.mode;
$('input[type=radio]', element).on('change', options.onChange); $('input[type=radio]', element).on('change', options.onChange);
}, },
...@@ -83,6 +85,8 @@ function MCQBlock(runtime, element, mentoring) { ...@@ -83,6 +85,8 @@ function MCQBlock(runtime, element, mentoring) {
if (this.mode === 'assessment') if (this.mode === 'assessment')
return; return;
mentoring = this.mentoring;
var messageView = MessageView(element, mentoring); var messageView = MessageView(element, mentoring);
messageView.clearResult(); messageView.clearResult();
...@@ -123,7 +127,7 @@ function MCQBlock(runtime, element, mentoring) { ...@@ -123,7 +127,7 @@ function MCQBlock(runtime, element, mentoring) {
}, },
clearResult: function() { clearResult: function() {
MessageView(element, mentoring).clearResult(); MessageView(element, this.mentoring).clearResult();
}, },
validate: function(){ validate: function(){
...@@ -136,7 +140,9 @@ function MCQBlock(runtime, element, mentoring) { ...@@ -136,7 +140,9 @@ function MCQBlock(runtime, element, mentoring) {
function MRQBlock(runtime, element, mentoring) { function MRQBlock(runtime, element, mentoring) {
return { return {
mode: null, mode: null,
mentoring: null,
init: function(options) { init: function(options) {
this.mentoring = options.mentoring;
this.mode = options.mode; this.mode = options.mode;
$('input[type=checkbox]', element).on('change', options.onChange); $('input[type=checkbox]', element).on('change', options.onChange);
}, },
...@@ -155,6 +161,8 @@ function MRQBlock(runtime, element, mentoring) { ...@@ -155,6 +161,8 @@ function MRQBlock(runtime, element, mentoring) {
if (this.mode === 'assessment') if (this.mode === 'assessment')
return; return;
mentoring = this.mentoring;
var messageView = MessageView(element, mentoring); var messageView = MessageView(element, mentoring);
if (result.message) { if (result.message) {
...@@ -193,7 +201,7 @@ function MRQBlock(runtime, element, mentoring) { ...@@ -193,7 +201,7 @@ function MRQBlock(runtime, element, mentoring) {
}, },
clearResult: function() { clearResult: function() {
MessageView(element, mentoring).clearResult(); MessageView(element, this.mentoring).clearResult();
}, },
validate: function(){ validate: function(){
......
function MentoringBlock(runtime, element) { function MentoringBlock(runtime, element) {
var attemptsTemplate = _.template($('#xblock-attempts-template').html()); var attemptsTemplate = _.template($('#xblock-attempts-template').html());
var data = $('.mentoring', element).data(); var data = $('.mentoring', element).data();
var children_dom = []; // Keep track of children. A Child need a single object scope for its data. var children = runtime.children(element);
var children = [];
var step = data.step; 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) { function publish_event(data) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -66,41 +77,14 @@ function MentoringBlock(runtime, element) { ...@@ -66,41 +77,14 @@ function MentoringBlock(runtime, element) {
} }
} }
function readChildren() { function initChildren(options) {
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) {
options = options || {}; options = options || {};
options.mentoring = mentoring;
options.mode = data.mode; options.mode = data.mode;
if (index >= children.length) for (var i=0; i < children.length; i++) {
return children.length; var child = children[i];
callIfExists(child, 'init', options);
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);
});
} }
function getChildByName(element, name) { function getChildByName(element, name) {
...@@ -112,21 +96,6 @@ function MentoringBlock(runtime, element) { ...@@ -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') { if (data.mode === 'standard') {
MentoringStandardView(runtime, element, mentoring); MentoringStandardView(runtime, element, mentoring);
} }
......
...@@ -73,7 +73,7 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -73,7 +73,7 @@ function MentoringStandardView(runtime, element, mentoring) {
onChange: onChange onChange: onChange
}; };
mentoring.displayChildren(options); mentoring.initChildren(options);
mentoring.renderAttempts(); mentoring.renderAttempts();
mentoring.renderDependency(); mentoring.renderDependency();
...@@ -81,17 +81,6 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -81,17 +81,6 @@ function MentoringStandardView(runtime, element, mentoring) {
validateXBlock(); 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 // validate all children
function validateXBlock() { function validateXBlock() {
var is_valid = true; var is_valid = true;
...@@ -100,8 +89,7 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -100,8 +89,7 @@ function MentoringStandardView(runtime, element, mentoring) {
if ((data.max_attempts > 0) && (data.num_attempts >= data.max_attempts)) { if ((data.max_attempts > 0) && (data.num_attempts >= data.max_attempts)) {
is_valid = false; is_valid = false;
} } else {
else {
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var child = children[i]; var child = children[i];
if (child && child.name !== undefined) { if (child && child.name !== undefined) {
...@@ -112,15 +100,12 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -112,15 +100,12 @@ function MentoringStandardView(runtime, element, mentoring) {
} }
} }
} }
if (!is_valid) { if (!is_valid) {
submitDOM.attr('disabled','disabled'); submitDOM.attr('disabled','disabled');
} } else {
else {
submitDOM.removeAttr("disabled"); submitDOM.removeAttr("disabled");
} }
} }
// We need to manually refresh, XBlocks are currently loaded together with the section initXBlockView();
refreshXBlock(element);
} }
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