Commit 6ef8713c by Vik Paruchuri

JS state tracking

parent 91a9962b
...@@ -131,6 +131,7 @@ class CombinedOpenEndedModule(XModule): ...@@ -131,6 +131,7 @@ class CombinedOpenEndedModule(XModule):
'items': [{'content' : task_html}], 'items': [{'content' : task_html}],
'ajax_url': self.system.ajax_url, 'ajax_url': self.system.ajax_url,
'allow_reset': True, 'allow_reset': True,
'state' : self.state,
} }
html = self.system.render_template('combined_open_ended.html', context) html = self.system.render_template('combined_open_ended.html', context)
...@@ -201,12 +202,32 @@ class CombinedOpenEndedModule(XModule): ...@@ -201,12 +202,32 @@ class CombinedOpenEndedModule(XModule):
return self.update_task_states_ajax(return_html) return self.update_task_states_ajax(return_html)
def next_problem(self): def next_problem(self):
pass self.setup_next_task()
return {'success' : True}
def reset(self): 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 Get the current score and state
""" """
......
...@@ -59,6 +59,7 @@ class @CombinedOpenEnded ...@@ -59,6 +59,7 @@ class @CombinedOpenEnded
@submit_button.hide() @submit_button.hide()
if !@state == 'done' if !@state == 'done'
@next_problem_button.show() @next_problem_button.show()
if @state == 'done'
if @allow_reset if @allow_reset
@reset_button.show() @reset_button.show()
else else
...@@ -127,7 +128,7 @@ class @CombinedOpenEnded ...@@ -127,7 +128,7 @@ class @CombinedOpenEnded
reset: (event) => reset: (event) =>
event.preventDefault() event.preventDefault()
@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.')
if @child_state == 'done' if @state == 'done'
$.postWithPrefix "#{@ajax_url}/reset", {}, (response) => $.postWithPrefix "#{@ajax_url}/reset", {}, (response) =>
if response.success if response.success
@answer_area.val('') @answer_area.val('')
...@@ -142,7 +143,7 @@ class @CombinedOpenEnded ...@@ -142,7 +143,7 @@ class @CombinedOpenEnded
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.')
next_problem (event) => next_problem: (event) =>
event.preventDefault() event.preventDefault()
@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.')
if @child_state == 'done' if @child_state == 'done'
......
...@@ -459,7 +459,7 @@ class SelfAssessmentModule(): ...@@ -459,7 +459,7 @@ class SelfAssessmentModule():
'allow_reset': self._allow_reset()} 'allow_reset': self._allow_reset()}
def reset(self, get, system): def reset(self, system):
""" """
If resetting is allowed, reset the state. 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: % for item in items:
<div class="item">${item['content'] | n}</div> <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