Commit 4922ab33 by Victor Shnayder

hook up reset button

parent 0ec7043e
...@@ -4,6 +4,7 @@ class @SelfAssessment ...@@ -4,6 +4,7 @@ class @SelfAssessment
@id = @el.data('id') @id = @el.data('id')
@ajax_url = @el.data('ajax-url') @ajax_url = @el.data('ajax-url')
@state = @el.data('state') @state = @el.data('state')
allow_reset = @el.data('allow_reset')
# valid states: 'initial', 'assessing', 'request_hint', 'done' # valid states: 'initial', 'assessing', 'request_hint', 'done'
# Where to put the rubric once we load it # Where to put the rubric once we load it
...@@ -14,17 +15,24 @@ class @SelfAssessment ...@@ -14,17 +15,24 @@ class @SelfAssessment
@hint_wrapper = @$('.hint-wrapper') @hint_wrapper = @$('.hint-wrapper')
@message_wrapper = @$('.message-wrapper') @message_wrapper = @$('.message-wrapper')
@check_button = @$('.submit-button') @check_button = @$('.submit-button')
@reset_button = @$('.reset-button')
@reset_button.click @reset
@find_assessment_elements() @find_assessment_elements()
@find_hint_elements() @find_hint_elements()
@bind() if allow_reset
@reset_button.show()
else
@reset_button.hide()
@rebind()
# locally scoped jquery. # locally scoped jquery.
$: (selector) -> $: (selector) ->
$(selector, @el) $(selector, @el)
bind: () => rebind: () =>
# rebind to the appropriate function for the current state # rebind to the appropriate function for the current state
@check_button.unbind('click') @check_button.unbind('click')
if @state == 'initial' if @state == 'initial'
...@@ -51,7 +59,7 @@ class @SelfAssessment ...@@ -51,7 +59,7 @@ class @SelfAssessment
@rubric_wrapper.html(response.rubric_html) @rubric_wrapper.html(response.rubric_html)
@state = 'assessing' @state = 'assessing'
@find_assessment_elements() @find_assessment_elements()
@bind() @rebind()
else else
@errors_area.html(response.message) @errors_area.html(response.message)
else else
...@@ -66,7 +74,7 @@ class @SelfAssessment ...@@ -66,7 +74,7 @@ class @SelfAssessment
@hint_wrapper.html(response.hint_html) @hint_wrapper.html(response.hint_html)
@state = 'request_hint' @state = 'request_hint'
@find_hint_elements() @find_hint_elements()
@bind() @rebind()
else else
@errors_area.html(response.message) @errors_area.html(response.message)
else else
...@@ -82,9 +90,27 @@ class @SelfAssessment ...@@ -82,9 +90,27 @@ class @SelfAssessment
if response.success if response.success
@message_wrapper.html(response.message_html) @message_wrapper.html(response.message_html)
@state = 'done' @state = 'done'
@bind() @rebind()
if response.allow_reset
@reset_button.show()
else else
@errors_area.html(response.message) @errors_area.html(response.message)
else else
@errors_area.html('Problem state got out of sync. Try reloading the page.') @errors_area.html('Problem state got out of sync. Try reloading the page.')
reset: (event) =>
event.preventDefault()
if @state == 'done'
$.postWithPrefix "#{@ajax_url}/reset", {}, (response) =>
if response.success
@rubric_wrapper.html('')
@hint_wrapper.html('')
@message_wrapper.html('')
@state = 'initial'
@rebind()
@reset_button.hide()
else
@errors_area.html(response.message)
else
@errors_area.html('Problem state got out of sync. Try reloading the page.')
...@@ -121,6 +121,7 @@ class SelfAssessmentModule(XModule): ...@@ -121,6 +121,7 @@ class SelfAssessmentModule(XModule):
#set context variables and render template #set context variables and render template
previous_answer = self.student_answers[-1] if self.student_answers else '' previous_answer = self.student_answers[-1] if self.student_answers else ''
allow_reset = self.state == self.DONE and self.attempts < self.max_attempts
context = { context = {
'prompt': self.prompt, 'prompt': self.prompt,
'previous_answer': previous_answer, 'previous_answer': previous_answer,
...@@ -129,6 +130,7 @@ class SelfAssessmentModule(XModule): ...@@ -129,6 +130,7 @@ class SelfAssessmentModule(XModule):
'initial_hint': self.get_hint_html(), 'initial_hint': self.get_hint_html(),
'initial_message': self.get_message_html(), 'initial_message': self.get_message_html(),
'state': self.state, 'state': self.state,
'allow_reset': allow_reset,
} }
html = self.system.render_template('self_assessment_prompt.html', context) html = self.system.render_template('self_assessment_prompt.html', context)
...@@ -297,7 +299,8 @@ class SelfAssessmentModule(XModule): ...@@ -297,7 +299,8 @@ class SelfAssessmentModule(XModule):
Save the hint. Save the hint.
Returns a dict { 'success': bool, Returns a dict { 'success': bool,
'message_html': message_html, 'message_html': message_html,
'error': error-msg}, 'error': error-msg,
'allow_reset': bool},
with the error key only present if success is False and message_html with the error key only present if success is False and message_html
only if True. only if True.
''' '''
...@@ -325,7 +328,8 @@ class SelfAssessmentModule(XModule): ...@@ -325,7 +328,8 @@ class SelfAssessmentModule(XModule):
self.system.track_function('save_hint', event_info) self.system.track_function('save_hint', event_info)
return {'success': True, return {'success': True,
'message_html': self.get_message_html()} 'message_html': self.get_message_html(),
'allow_reset': self.attempts < self.max_attempts}
def reset(self, get): def reset(self, get):
...@@ -335,8 +339,9 @@ class SelfAssessmentModule(XModule): ...@@ -335,8 +339,9 @@ class SelfAssessmentModule(XModule):
Returns {'success': bool, 'error': msg} Returns {'success': bool, 'error': msg}
(error only present if not success) (error only present if not success)
""" """
if self.state != DONE: if self.state != self.DONE:
return self.out_of_sync_error(get) return self.out_of_sync_error(get)
if self.attempts > self.max_attempts: if self.attempts > self.max_attempts:
return { return {
'success': False, 'success': False,
......
<section id="self_assessment_${id}" class="self-assessment" data-ajax-url="${ajax_url}" <section id="self_assessment_${id}" class="self-assessment" data-ajax-url="${ajax_url}"
data-id="${id}" data-state="${state}"> data-id="${id}" data-state="${state}" data-allow_reset="${allow_reset}">
<div class="error"></div> <div class="error"></div>
<div class="prompt"> <div class="prompt">
${prompt} ${prompt}
...@@ -16,4 +16,5 @@ ...@@ -16,4 +16,5 @@
<div class="message-wrapper">${initial_message}</div> <div class="message-wrapper">${initial_message}</div>
<input type="button" value="Submit" class="submit-button" name="show"/> <input type="button" value="Submit" class="submit-button" name="show"/>
<input type="button" value="Reset" class="reset-button" name="reset"/>
</section> </section>
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