Commit 6ef8713c by Vik Paruchuri

JS state tracking

parent 91a9962b
......@@ -131,6 +131,7 @@ class CombinedOpenEndedModule(XModule):
'items': [{'content' : task_html}],
'ajax_url': self.system.ajax_url,
'allow_reset': True,
'state' : self.state,
}
html = self.system.render_template('combined_open_ended.html', context)
......@@ -201,12 +202,32 @@ class CombinedOpenEndedModule(XModule):
return self.update_task_states_ajax(return_html)
def next_problem(self):
pass
self.setup_next_task()
return {'success' : True}
def reset(self):
pass
"""
If resetting is allowed, reset the state.
Returns {'success': bool, 'error': msg}
(error only present if not success)
"""
if self.state != self.DONE:
return self.out_of_sync_error(get)
if self.attempts > self.max_attempts:
return {
'success': False,
'error': 'Too many attempts.'
}
self.state=self.INITIAL
self.current_task_number=0
self.setup_next_task()
self.current_task.reset(self.system)
return {'success': True}
def get_instance_state(self):
def get_instance_state(self):
"""
Get the current score and state
"""
......
......@@ -59,6 +59,7 @@ class @CombinedOpenEnded
@submit_button.hide()
if !@state == 'done'
@next_problem_button.show()
if @state == 'done'
if @allow_reset
@reset_button.show()
else
......@@ -127,7 +128,7 @@ class @CombinedOpenEnded
reset: (event) =>
event.preventDefault()
@errors_area.html('Problem state got out of sync. Try reloading the page.')
if @child_state == 'done'
if @state == 'done'
$.postWithPrefix "#{@ajax_url}/reset", {}, (response) =>
if response.success
@answer_area.val('')
......@@ -142,7 +143,7 @@ class @CombinedOpenEnded
else
@errors_area.html('Problem state got out of sync. Try reloading the page.')
next_problem (event) =>
next_problem: (event) =>
event.preventDefault()
@errors_area.html('Problem state got out of sync. Try reloading the page.')
if @child_state == 'done'
......
......@@ -459,7 +459,7 @@ class SelfAssessmentModule():
'allow_reset': self._allow_reset()}
def reset(self, get, system):
def reset(self, system):
"""
If resetting is allowed, reset the state.
......
<section id="combined-open-ended" class="combined-open-ended" data-ajax-url="${ajax_url}" data-allow_reset="${allow_reset}">
<section id="combined-open-ended" class="combined-open-ended" data-ajax-url="${ajax_url}" data-allow_reset="${allow_reset}" data-state="${state}">
% for item in items:
<div class="item">${item['content'] | n}</div>
......
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