Commit ec4507df by Vik Paruchuri

fixed ajax value passing to function

parent 1c2ec275
......@@ -9,23 +9,12 @@ $(document).on('click', 'section.sa-wrapper input#show', ( ->
));
$(document).on('click', 'section.sa-wrapper input#save', ( ->
answer=$('section.sa-wrapper input#answer').val()
assessment=0
assessment_correct=$('section.sa-wrapper #assessment').find(':selected').text()
alert(assessment_correct)
root = location.protocol + "//" + location.host
post_url=$('section.sa-wrapper input#show').attr('url')
final_url="/courses/MITx/6.002x/2012_Fall/modx/#{post_url}/sa_save"
$('section.sa-wrapper input#assessment option').each( ->
if (this.selected)
alert('this option is selected')
else
alert('this is not')
);
$.post final_url, answer, (response) ->
$.post final_url, assessment_correct, (response) ->
if response.success
$('section.sa_wrapper p#save_message').replace(response.message)
......
......@@ -72,7 +72,7 @@ class SelfAssessmentModule(XModule):
self.problem=''.join([self.problem,problem_form])
self.rubric=''.join([self.rubric,rubric_form])
self.html = self.problem
self.answers={}
self.answer=""
self.score=0
self.top_score=1
......@@ -124,22 +124,23 @@ class SelfAssessmentModule(XModule):
})
return json.dumps(d, cls=ComplexEncoder)
def show_rubric(self,get):
self.answer=get.keys()[0]
return {'success': True, 'rubric' : self.rubric}
def save_problem(self, get):
'''
Save the passed in answers.
Returns a dict { 'success' : bool, ['error' : error-msg]},
with the error key only present if success is False.
'''
correctness=get.keys()[0]
log.debug(correctness)
event_info = dict()
event_info['state'] = {'seed': 1,
'student_answers': self.answers,
'correct_map': {'self_assess' : {'correctness': False,
'correct_map': {'self_assess' : {'correctness': correctness,
'npoints': 0,
'msg': "",
'hint': "",
......@@ -150,37 +151,12 @@ class SelfAssessmentModule(XModule):
event_info['problem_id'] = self.location.url()
answers = self.make_dict_of_responses(get)
log.debug(answers)
event_info['answers'] = answers
event_info['answers'] = self.answer
self.system.track_function('save_problem_succeed', event_info)
return {'success': True, 'message' : "Save Succcesful. Thanks for participating!"}
@staticmethod
def make_dict_of_responses(get):
'''Make dictionary of student responses (aka "answers")
get is POST dictionary.
'''
answers = dict()
for key in get:
# e.g. input_resistor_1 ==> resistor_1
_, _, name = key.partition('_')
# This allows for answers which require more than one value for
# the same form input (e.g. checkbox inputs). The convention is that
# if the name ends with '[]' (which looks like an array), then the
# answer will be an array.
if not name.endswith('[]'):
answers[name] = get[key]
else:
name = name[:-2]
answers[name] = get.getlist(key)
return answers
class SelfAssessmentDescriptor(XmlDescriptor, EditingDescriptor):
"""
Module for putting raw html in a course
......
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