Commit 385a62d7 by Diana Huang

Handle multiple inputs properly for ajax handling.

parent 6f535d9e
...@@ -146,6 +146,8 @@ class LoncapaProblem(object): ...@@ -146,6 +146,8 @@ class LoncapaProblem(object):
if not self.student_answers: # True when student_answers is an empty dict if not self.student_answers: # True when student_answers is an empty dict
self.set_initial_display() self.set_initial_display()
self.inputs = {}
self.extracted_tree = self._extract_html(self.tree) self.extracted_tree = self._extract_html(self.tree)
...@@ -337,12 +339,18 @@ class LoncapaProblem(object): ...@@ -337,12 +339,18 @@ class LoncapaProblem(object):
It also parses out the dispatch from the get so that it can be passed onto the input type nicely It also parses out the dispatch from the get so that it can be passed onto the input type nicely
''' '''
if self.input:
# pull out the id
problem_id = get['problem_id']
if self.inputs[problem_id]:
dispatch = get['dispatch'] dispatch = get['dispatch']
return self.input.handle_ajax(dispatch, get) return self.inputs[problem_id].handle_ajax(dispatch, get)
else:
log.warning("Could not find matching input for id: %s" % problem_id)
return {} return {}
# ======= Private Methods Below ======== # ======= Private Methods Below ========
def _process_includes(self): def _process_includes(self):
...@@ -526,8 +534,8 @@ class LoncapaProblem(object): ...@@ -526,8 +534,8 @@ class LoncapaProblem(object):
input_type_cls = inputtypes.registry.get_class_for_tag(problemtree.tag) input_type_cls = inputtypes.registry.get_class_for_tag(problemtree.tag)
# save the input type so that we can make ajax calls on it if we need to # save the input type so that we can make ajax calls on it if we need to
self.input = input_type_cls(self.system, problemtree, state) self.inputs[problemid] = input_type_cls(self.system, problemtree, state)
return self.input.get_html() return self.inputs[problemid].get_html()
# let each Response render itself # let each Response render itself
if problemtree in self.responders: if problemtree in self.responders:
......
...@@ -79,8 +79,9 @@ class @Problem ...@@ -79,8 +79,9 @@ class @Problem
# Use this if you want to make an ajax call on the input type object # Use this if you want to make an ajax call on the input type object
# static method so you don't have to instantiate a Problem in order to use it # static method so you don't have to instantiate a Problem in order to use it
@inputAjax: (url, dispatch, data, callback) -> @inputAjax: (url, problem_id, dispatch, data, callback) ->
data['dispatch'] = dispatch data['dispatch'] = dispatch
data['problem_id'] = problem_id
$.postWithPrefix "#{url}/input_ajax", data, callback $.postWithPrefix "#{url}/input_ajax", data, callback
......
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