diff --git a/freetextresponse/freetextresponse.py b/freetextresponse/freetextresponse.py index a71febe0..82baf92a 100644 --- a/freetextresponse/freetextresponse.py +++ b/freetextresponse/freetextresponse.py @@ -279,7 +279,6 @@ def student_view(self, context={}): (Fragment): The HTML Fragment for this XBlock, which determines the general frame of the FreeTextResponse Question. """ - self.runtime.service(self, 'i18n') context.update( { @@ -294,7 +293,7 @@ def student_view(self, context={}): 'visibility_class': self._get_indicator_visibility_class(), 'word_count_message': self._get_word_count_message(), 'display_other_responses': self.display_other_student_responses, - 'other_responses': [], + 'other_responses': self.get_other_answers(), } ) template = get_template('freetextresponse_view.html') @@ -602,7 +601,7 @@ def submit(self, data, suffix=''): 'user_alert': self._get_user_alert( ignore_attempts=True, ), - 'other_responses': self.get_other_answers(self.get_student_id()), + 'other_responses': self.get_other_answers(), 'display_other_responses': self.display_other_student_responses, 'visibility_class': self._get_indicator_visibility_class(), } @@ -654,12 +653,19 @@ def store_student_response(self): # MAX_RESPONSES answers if their answer is in the pool. self.displayable_answers = self.displayable_answers[-(MAX_RESPONSES+1):] - def get_other_answers(self, student_id): + def get_other_answers(self): """ Returns at most MAX_RESPONSES answers from the pool. Does not return answers the student had submitted. """ + student_id = self.get_student_id() + display_other_responses = self.display_other_student_responses + shouldnt_show_other_responses = not display_other_responses + student_answer_incorrect = self._determine_credit() == Credit.zero + if student_answer_incorrect or shouldnt_show_other_responses: + return [] + return_list = [ response for response in self.displayable_answers diff --git a/freetextresponse/public/view.css b/freetextresponse/public/view.css index fe0c61c5..2ad15442 100644 --- a/freetextresponse/public/view.css +++ b/freetextresponse/public/view.css @@ -104,12 +104,14 @@ } .freetextresponse .responses-box { - display: none; margin-top: 10px; padding: 10px; background: #fbfbfb; border: 1px solid #ddd; } +.freetextresponse .responses-box.hidden { + display: none; +} .freetextresponse .responses-title { margin-left: 15px; diff --git a/freetextresponse/public/view.js b/freetextresponse/public/view.js index a2fba14b..54c1d299 100644 --- a/freetextresponse/public/view.js +++ b/freetextresponse/public/view.js @@ -68,13 +68,7 @@ function FreeTextResponseView(runtime, element) { userAlertMessage.text(response.user_alert); buttonSave.addClass(response.nodisplay_class); setClassForTextAreaParent(response.indicator_class); - if (!response.user_alert && response.display_other_responses) { - var responseHTML = get_student_responses_html(response.other_responses); - if (responseHTML) { - responseList.html(responseHTML); - } - $element.find('.responses-box').show(); - } + displayResponsesIfAnswered(response); $xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val()); $xblocksContainer.data(problemProgressId, response.problem_progress); @@ -91,17 +85,29 @@ function FreeTextResponseView(runtime, element) { return false; }); - function get_student_responses_html(responses) { + function getStudentResponsesHtml(responses) { /* Convert list of responses to a html string to add to the page */ var html = ''; + var noResponsesText = responseList.data('noresponse'); responses.forEach(function(item) { html += '
  • ' + item.answer + '
  • '; }); + html = html || '
  • ' + noResponsesText + '
  • '; return html; } + function displayResponsesIfAnswered(response) { + if (!response.display_other_responses) { + $element.find('.responses-box').addClass('hidden'); + return; + } + var responseHTML = getStudentResponsesHtml(response.other_responses); + responseList.html(responseHTML); + $element.find('.responses-box').removeClass('hidden'); + } + buttonSave.on('click', function () { buttonSave.text(buttonSave[0].dataset.checking); runtime.notify('save', { diff --git a/freetextresponse/templates/freetextresponse_view.html b/freetextresponse/templates/freetextresponse_view.html index eea4e252..99bb5de4 100644 --- a/freetextresponse/templates/freetextresponse_view.html +++ b/freetextresponse/templates/freetextresponse_view.html @@ -30,7 +30,7 @@

    {{ display_name }}

    {{ user_alert }}
    {% if display_other_responses %} -
    +

    Submissions by others

    {% endif %}