From b8d49511e1415d51270befef773e8f273c9f732b Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Thu, 3 Jan 2013 18:14:43 -0500 Subject: [PATCH] Fixing javascript display bugs --- .../xmodule/combined_open_ended_module.py | 5 +-- .../js/src/combinedopenended/display.coffee | 39 +++++++++++-------- .../js/src/selfassessment/display.coffee | 3 -- .../xmodule/xmodule/self_assessment_module.py | 3 -- lms/templates/combined_open_ended.html | 4 +- lms/templates/self_assessment_prompt.html | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee diff --git a/common/lib/xmodule/xmodule/combined_open_ended_module.py b/common/lib/xmodule/xmodule/combined_open_ended_module.py index e77cd254e2..c75de86b02 100644 --- a/common/lib/xmodule/xmodule/combined_open_ended_module.py +++ b/common/lib/xmodule/xmodule/combined_open_ended_module.py @@ -112,9 +112,8 @@ class CombinedOpenEndedModule(XModule): self.state=self.ASSESSING elif current_task_state is None and self.current_task_number>0: last_response=self.get_last_response(self.current_task_number-1) - current_task_state = ('{"state": "assessing", "version": 1, "max_score": {max_score}, ' - '"attempts": 0, "history": [{"answer": "{answer}"}]}' - .format(max_score=self._max_score, answer=last_response)) + current_task_state = ("{'state': 'assessing', 'version': 1, 'max_score': {" + str(self._max_score) + "}, " + + "'attempts': 0, 'history': [{'answer': '{" + str(last_response) + "}'}]}") self.current_task=self_assessment_module.SelfAssessmentModule(self.system, self.location, self.current_task_parsed_xml, self.current_task_descriptor, instance_state=current_task_state) self.task_states.append(self.current_task.get_instance_state()) self.state=self.ASSESSING diff --git a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee index 897d5f1b67..ebb440b996 100644 --- a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee @@ -1,13 +1,16 @@ class @CombinedOpenEnded constructor: (element) -> - @el = $(element).find('section.self-assessment') + @el = $(element).find('section.combined-open-ended') @id = @el.data('id') @ajax_url = @el.data('ajax-url') @state = @el.data('state') @allow_reset = @el.data('allow_reset') + @reset_button = @$('.reset-button') + @reset_button.click @reset # valid states: 'initial', 'assessing', 'request_hint', 'done' # Where to put the rubric once we load it + @el = $(element).find('section.open-ended-child') @errors_area = @$('.error') @answer_area = @$('textarea.answer') @@ -15,9 +18,7 @@ class @CombinedOpenEnded @hint_wrapper = @$('.hint-wrapper') @message_wrapper = @$('.message-wrapper') @submit_button = @$('.submit-button') - - @reset_button = @$('.reset-button') - @reset_button.click @reset + @child_state = @el.data('state') @find_assessment_elements() @find_hint_elements() @@ -32,23 +33,28 @@ class @CombinedOpenEnded # rebind to the appropriate function for the current state @submit_button.unbind('click') @submit_button.show() + @reset_button.hide() @hint_area.attr('disabled', false) - if @state == 'initial' + if @child_state == 'initial' @answer_area.attr("disabled", false) @submit_button.prop('value', 'Submit') @submit_button.click @save_answer - else if @state == 'assessing' + else if @child_state == 'assessing' @answer_area.attr("disabled", true) @submit_button.prop('value', 'Submit assessment') @submit_button.click @save_assessment - else if @state == 'request_hint' + else if @child_state == 'request_hint' @answer_area.attr("disabled", true) @submit_button.prop('value', 'Submit hint') @submit_button.click @save_hint - else if @state == 'done' + else if @child_state == 'done' @answer_area.attr("disabled", true) @hint_area.attr('disabled', true) @submit_button.hide() + if @allow_reset + @reset_button.show() + else + @reset_button.hide() find_assessment_elements: -> @assessment = @$('select.assessment') @@ -58,12 +64,12 @@ class @CombinedOpenEnded save_answer: (event) => event.preventDefault() - if @state == 'initial' + if @child_state == 'initial' data = {'student_answer' : @answer_area.val()} $.postWithPrefix "#{@ajax_url}/save_answer", data, (response) => if response.success @rubric_wrapper.html(response.rubric_html) - @state = 'assessing' + @child_state = 'assessing' @find_assessment_elements() @rebind() else @@ -73,16 +79,16 @@ class @CombinedOpenEnded save_assessment: (event) => event.preventDefault() - if @state == 'assessing' + if @child_state == 'assessing' data = {'assessment' : @assessment.find(':selected').text()} $.postWithPrefix "#{@ajax_url}/save_assessment", data, (response) => if response.success - @state = response.state + @child_state = response.state - if @state == 'request_hint' + if @child_state == 'request_hint' @hint_wrapper.html(response.hint_html) @find_hint_elements() - else if @state == 'done' + else if @child_state == 'done' @message_wrapper.html(response.message_html) @allow_reset = response.allow_reset @@ -95,13 +101,13 @@ class @CombinedOpenEnded save_hint: (event) => event.preventDefault() - if @state == 'request_hint' + if @child_state == 'request_hint' data = {'hint' : @hint_area.val()} $.postWithPrefix "#{@ajax_url}/save_hint", data, (response) => if response.success @message_wrapper.html(response.message_html) - @state = 'done' + @child_state = 'done' @allow_reset = response.allow_reset @rebind() else @@ -112,6 +118,7 @@ class @CombinedOpenEnded reset: (event) => event.preventDefault() + @errors_area.html('Problem state got out of sync. Try reloading the page.') if @state == 'done' $.postWithPrefix "#{@ajax_url}/reset", {}, (response) => if response.success diff --git a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee deleted file mode 100644 index 30024478b1..0000000000 --- a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee +++ /dev/null @@ -1,3 +0,0 @@ -class @SelfAssessment - constructor: (element) -> - diff --git a/common/lib/xmodule/xmodule/self_assessment_module.py b/common/lib/xmodule/xmodule/self_assessment_module.py index 0c37384c16..a3b4b56e35 100644 --- a/common/lib/xmodule/xmodule/self_assessment_module.py +++ b/common/lib/xmodule/xmodule/self_assessment_module.py @@ -61,9 +61,6 @@ class SelfAssessmentModule(): REQUEST_HINT = 'request_hint' DONE = 'done' - js = {'coffee': [resource_string(__name__, 'js/src/selfassessment/display.coffee')]} - js_module_name = "SelfAssessment" - def __init__(self, system, location, definition, descriptor, instance_state=None, shared_state=None, **kwargs): """ diff --git a/lms/templates/combined_open_ended.html b/lms/templates/combined_open_ended.html index 76c28b0e31..65a57b98eb 100644 --- a/lms/templates/combined_open_ended.html +++ b/lms/templates/combined_open_ended.html @@ -1,9 +1,9 @@ -
+
% for item in items:
${item['content'] | n}
% endfor -
+ diff --git a/lms/templates/self_assessment_prompt.html b/lms/templates/self_assessment_prompt.html index e54864c988..91223fdaa1 100644 --- a/lms/templates/self_assessment_prompt.html +++ b/lms/templates/self_assessment_prompt.html @@ -1,4 +1,4 @@ -