Commit 17201a0c by Tim Krones

Add functionality for resetting new mentoring block.

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