diff --git a/problem_builder/answer.py b/problem_builder/answer.py index 5b68bfc5..68ddf973 100644 --- a/problem_builder/answer.py +++ b/problem_builder/answer.py @@ -125,6 +125,7 @@ class AnswerBlock(SubmittingXBlockMixin, AnswerMixin, QuestionMixin, StudioEdita """ CATEGORY = 'pb-answer' STUDIO_LABEL = _(u"Long Answer") + answerable = True name = String( display_name=_("Question ID (name)"), diff --git a/problem_builder/public/js/mentoring_with_steps.js b/problem_builder/public/js/mentoring_with_steps.js index cc64b15d..c790ad9d 100644 --- a/problem_builder/public/js/mentoring_with_steps.js +++ b/problem_builder/public/js/mentoring_with_steps.js @@ -56,6 +56,15 @@ function MentoringWithStepsBlock(runtime, element) { } } + function postUpdateStep(response) { + activeStep = response.active_step; + if (activeStep === -1) { + updateNumAttempts(); + } else { + updateControls(); + } + } + function handleResults(response) { showFeedback(response); @@ -64,14 +73,7 @@ function MentoringWithStepsBlock(runtime, element) { // Otherwise, get UI ready for showing next step. var handlerUrl = runtime.handlerUrl(element, 'update_active_step'); $.post(handlerUrl, JSON.stringify(activeStep+1)) - .success(function(response) { - activeStep = response.active_step; - if (activeStep === -1) { - updateNumAttempts(); - } else { - updateControls(); - } - }); + .success(postUpdateStep); } function updateNumAttempts() { @@ -138,6 +140,14 @@ function MentoringWithStepsBlock(runtime, element) { step.submit(handleResults); } + function markRead() { + var handlerUrl = runtime.handlerUrl(element, 'update_active_step'); + $.post(handlerUrl, JSON.stringify(activeStep+1)).success(function (response) { + postUpdateStep(response); + updateDisplay(); + }); + } + function getResults() { var step = steps[activeStep]; step.getResults(handleReviewResults); @@ -195,9 +205,18 @@ function MentoringWithStepsBlock(runtime, element) { showActiveStep(); validateXBlock(); updateNextLabel(); - nextDOM.attr('disabled', 'disabled'); + var step = steps[activeStep]; + if (step.hasQuestion()) { + nextDOM.attr('disabled', 'disabled'); + } else { + nextDOM.removeAttr('disabled'); + } if (isLastStep() && reviewStep) { - reviewDOM.attr('disabled', 'disabled'); + if (step.hasQuestion()) { + reviewDOM.attr('disabled', 'disabled'); + } else { + reviewDOM.removeAttr('disabled') + } reviewDOM.show(); } } @@ -261,9 +280,14 @@ function MentoringWithStepsBlock(runtime, element) { nextDOM.show(); nextDOM.removeAttr('disabled'); } + var step = steps[activeStep]; tryAgainDOM.hide(); - submitDOM.show(); + if (step.hasQuestion()) { + submitDOM.show(); + } else { + submitDOM.hide(); + } submitDOM.attr('disabled', 'disabled'); reviewLinkDOM.show(); @@ -302,8 +326,19 @@ function MentoringWithStepsBlock(runtime, element) { } else { submitDOM.removeAttr('disabled'); } - if (isLastStep()) { + if (isLastStep() && step.hasQuestion()) { nextDOM.hide(); + } else if (isLastStep()) { + reviewDOM.one('click', markRead); + reviewDOM.removeAttr('disabled'); + nextDOM.hide() + } else if (!step.hasQuestion()) { + nextDOM.one('click', markRead); + } + if (step.hasQuestion()) { + submitDOM.show(); + } else { + submitDOM.hide(); } } diff --git a/problem_builder/public/js/step.js b/problem_builder/public/js/step.js index 3751393e..83438acd 100644 --- a/problem_builder/public/js/step.js +++ b/problem_builder/public/js/step.js @@ -85,6 +85,10 @@ function MentoringStepBlock(runtime, element) { getStepLabel: function() { return $('.sb-step', element).data('next-button-label'); + }, + + hasQuestion: function() { + return $('.sb-step', element).data('has-question') } }; diff --git a/problem_builder/questionnaire.py b/problem_builder/questionnaire.py index 40cf9240..7e846809 100644 --- a/problem_builder/questionnaire.py +++ b/problem_builder/questionnaire.py @@ -90,6 +90,7 @@ class QuestionnaireAbstractBlock( ) editable_fields = ('question', 'message', 'weight', 'display_name', 'show_title') has_children = True + answerable = True @lazy def html_id(self): diff --git a/problem_builder/step.py b/problem_builder/step.py index 77b1bd8c..43a351b3 100644 --- a/problem_builder/step.py +++ b/problem_builder/step.py @@ -133,6 +133,10 @@ def allowed_nested_blocks(self): AnswerRecapBlock, MentoringTableBlock, ] + @property + def has_question(self): + return any(getattr(child, 'answerable', False) for child in self.steps) + @XBlock.json_handler def submit(self, submissions, suffix=''): log.info(u'Received submissions: {}'.format(submissions)) diff --git a/problem_builder/templates/html/step.html b/problem_builder/templates/html/step.html index 8fd325d4..096dd0d7 100644 --- a/problem_builder/templates/html/step.html +++ b/problem_builder/templates/html/step.html @@ -1,4 +1,4 @@ -