Commit 4922ab33 by Victor Shnayder

hook up reset button

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