Commit d02539cb by Tim Krones

Persist step info.

parent 9cf2ee45
......@@ -834,6 +834,14 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
scope=Scope.settings
)
# User state
step = Integer(
# Keep track of the student progress.
default=0,
scope=Scope.user_state,
enforce_type=True
)
editable_fields = ('display_name',)
@lazy
......@@ -900,6 +908,14 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
NestedXBlockSpec(OnAssessmentReviewMentoringMessageShim, boilerplate='on-assessment-review'),
]
@XBlock.json_handler
def update_step(self, step, suffix=''):
if step < len(self.steps):
self.step = step
return {
'step': self.step
}
def author_edit_view(self, context):
"""
Add some HTML to the author view that allows authors to add child blocks.
......
......@@ -3,14 +3,27 @@ function MentoringWithStepsBlock(runtime, element) {
var steps = runtime.children(element).filter(
function(c) { return c.element.className.indexOf('pb-mentoring-step') > -1; }
);
var active_child = -1;
var checkmark, submitDOM, nextDOM;
var step = $('.mentoring', element).data('step');
var active_child, checkmark, submitDOM, nextDOM;
function isLastChild() {
return (active_child === steps.length-1);
}
function updateStep() {
var handlerUrl = runtime.handlerUrl(element, 'update_step');
$.post(handlerUrl, JSON.stringify(step+1))
.success(function(response) {
step = response.step;
console.log('Step: ' + step);
});
}
function handleResults(response) {
// Update step so next step is shown on page reload (even if user does not click "Next Step")
updateStep();
// Update UI
if (response.completed === 'correct') {
checkmark.addClass('checkmark-correct icon-ok fa-check');
} else if (response.completed === 'partial') {
......@@ -106,6 +119,8 @@ function MentoringWithStepsBlock(runtime, element) {
};
initSteps(options);
active_child = step;
active_child -= 1;
displayNextChild();
}
......
......@@ -75,13 +75,15 @@ class MentoringStepBlock(
STUDIO_LABEL = _(u"Mentoring Step")
CATEGORY = 'pb-mentoring-step'
# Fields:
# Settings
display_name = String(
display_name=_("Step Title"),
help=_('Leave blank to use sequential numbering'),
default="",
scope=Scope.content
)
# User state
student_results = List(
# Store results of student choices.
default=[],
......
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