Commit 17201a0c by Tim Krones

Add functionality for resetting new mentoring block.

parent d02539cb
......@@ -916,6 +916,19 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
'step': self.step
}
@XBlock.json_handler
def try_again(self, data, suffix=''):
self.step = 0
step_blocks = [self.runtime.get_block(child_id) for child_id in self.steps]
for step in step_blocks:
step.reset()
return {
'result': 'success'
}
def author_edit_view(self, context):
"""
Add some HTML to the author view that allows authors to add child blocks.
......
......@@ -4,7 +4,7 @@ function MentoringWithStepsBlock(runtime, element) {
function(c) { return c.element.className.indexOf('pb-mentoring-step') > -1; }
);
var step = $('.mentoring', element).data('step');
var active_child, checkmark, submitDOM, nextDOM;
var active_child, checkmark, submitDOM, nextDOM, tryAgainDOM, submitXHR;
function isLastChild() {
return (active_child === steps.length-1);
......@@ -15,7 +15,6 @@ function MentoringWithStepsBlock(runtime, element) {
$.post(handlerUrl, JSON.stringify(step+1))
.success(function(response) {
step = response.step;
console.log('Step: ' + step);
});
}
......@@ -36,6 +35,11 @@ function MentoringWithStepsBlock(runtime, element) {
nextDOM.removeAttr("disabled");
if (nextDOM.is(':visible')) { nextDOM.focus(); }
if (isLastChild()) {
tryAgainDOM.removeAttr('disabled');
tryAgainDOM.show();
}
}
function submit() {
......@@ -103,6 +107,27 @@ function MentoringWithStepsBlock(runtime, element) {
}
}
function handleTryAgain(result) {
if (result.result !== 'success')
return;
active_child = -1;
displayNextChild();
tryAgainDOM.hide();
submitDOM.show();
if (! isLastChild()) {
nextDOM.show();
}
}
function tryAgain() {
var handlerUrl = runtime.handlerUrl(element, 'try_again');
if (submitXHR) {
submitXHR.abort();
}
submitXHR = $.post(handlerUrl, JSON.stringify({})).success(handleTryAgain);
}
function initXBlockView() {
checkmark = $('.assessment-checkmark', element);
......@@ -114,6 +139,9 @@ function MentoringWithStepsBlock(runtime, element) {
nextDOM.bind('click', displayNextChild);
nextDOM.show();
tryAgainDOM = $(element).find('.submit .input-try-again');
tryAgainDOM.bind('click', tryAgain);
var options = {
onChange: onChange
};
......
......@@ -146,6 +146,10 @@ class MentoringStepBlock(
'results': submit_results,
}
def reset(self):
while self.student_results:
self.student_results.pop()
def author_edit_view(self, context):
"""
Add some HTML to the author view that allows authors to add child blocks.
......
......@@ -13,6 +13,7 @@
<span class="assessment-checkmark fa icon-2x"></span>
<input type="button" class="input-main" value="Submit" disabled="disabled" />
<input type="button" class="input-next" value="Next Step" disabled="disabled" />
<input type="button" class="input-try-again" value="Try again" disabled="disabled" />
</div>
</div>
......
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