From 9b640aa06b6b28cddfeebece6e116cec81e4dfb1 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Tue, 5 Mar 2013 13:24:38 -0500 Subject: [PATCH] Add more documentation and fix naming. --- common/lib/capa/capa/capa_problem.py | 20 +++++++++---------- common/lib/capa/capa/inputtypes.py | 2 +- .../xmodule/js/src/capa/display.coffee | 13 ++++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index a7a362d51e..d6356c1585 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -335,16 +335,16 @@ class LoncapaProblem(object): def handle_input_ajax(self, get): ''' - This passes any specialized input ajax onto the input class + InputTypes can support specialized AJAX calls. Find the correct input and pass along the correct data - It also parses out the dispatch from the get so that it can be passed onto the input type nicely + Also, parse out the dispatch from the get so that it can be passed onto the input type nicely ''' # pull out the id - problem_id = get['problem_id'] - if self.inputs[problem_id]: + input_id = get['input_id'] + if self.inputs[input_id]: dispatch = get['dispatch'] - return self.inputs[problem_id].handle_ajax(dispatch, get) + return self.inputs[input_id].handle_ajax(dispatch, get) else: log.warning("Could not find matching input for id: %s" % problem_id) return {} @@ -512,8 +512,9 @@ class LoncapaProblem(object): msg = '' hint = '' hintmode = None + input_id = problemtree.get('id') if problemid in self.correct_map: - pid = problemtree.get('id') + pid = input_id status = self.correct_map.get_correctness(pid) msg = self.correct_map.get_msg(pid) hint = self.correct_map.get_hint(pid) @@ -524,18 +525,17 @@ class LoncapaProblem(object): value = self.student_answers[problemid] # do the rendering - state = {'value': value, 'status': status, - 'id': problemtree.get('id'), + 'id': input_id, 'feedback': {'message': msg, 'hint': hint, 'hintmode': hintmode, }} 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 - self.inputs[problemid] = input_type_cls(self.system, problemtree, state) - return self.inputs[problemid].get_html() + self.inputs[input_id] = input_type_cls(self.system, problemtree, state) + return self.inputs[input_id].get_html() # let each Response render itself if problemtree in self.responders: diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 1a141338b7..1d6c340f37 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -224,7 +224,7 @@ class InputTypeBase(object): get: a dictionary containing the data that was sent with the ajax call Output: - a dictionary object that will then get sent back to the Javascript + a dictionary object that can be serialized into JSON. This will be sent back to the Javascript. """ pass diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 15211ca1bb..158c2b98d0 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -79,9 +79,18 @@ class @Problem # 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 - @inputAjax: (url, problem_id, dispatch, data, callback) -> + # Input: + # url: the AJAX url of the problem + # input_id: the input_id of the input you would like to make the call on + # NOTE: the id is the ${id} part of "input_${id}" during rendering + # If this function is passed the entire prefixed id, the backend may have trouble + # finding the correct input + # dispatch: string that indicates how this data should be handled by the inputtype + # callback: the function that will be called once the AJAX call has been completed. + # It will be passed a response object + @inputAjax: (url, input_id, dispatch, data, callback) -> data['dispatch'] = dispatch - data['problem_id'] = problem_id + data['input_id'] = input_id $.postWithPrefix "#{url}/input_ajax", data, callback