working on save functionality to select only one
This commit is contained in:
@@ -209,7 +209,6 @@ class @Problem
|
||||
show: =>
|
||||
if !@el.hasClass 'showed'
|
||||
Logger.log 'problem_show', problem: @id
|
||||
alert(@url)
|
||||
$.postWithPrefix "#{@url}/problem_show", (response) =>
|
||||
answers = response.answers
|
||||
$.each answers, (key, value) =>
|
||||
|
||||
@@ -3,6 +3,8 @@ $(document).on('click', 'section.sa-wrapper input#show', ( ->
|
||||
post_url=$('section.sa-wrapper input#show').attr('url')
|
||||
final_url="/courses/MITx/6.002x/2012_Fall/modx/#{post_url}/sa_show"
|
||||
answer=$('section.sa-wrapper input#answer').val()
|
||||
alert(answer)
|
||||
alert(final_url)
|
||||
|
||||
$.post final_url, answer, (response) ->
|
||||
alert("posted")
|
||||
@@ -15,20 +17,25 @@ $(document).on('click', 'section.sa-wrapper input#save', ( ->
|
||||
answer=$('section.sa-wrapper input#answer').val()
|
||||
alert(answer)
|
||||
assessment=0
|
||||
assessment_correct=$('section.sa-wrapper input#assessment_correct').val()
|
||||
assessment_correct=$('section.sa-wrapper input#assessment_correct').selected()
|
||||
alert(assessment_correct)
|
||||
assessment_incorrect=$('section.sa-wrapper input#assessment_incorrect').val()
|
||||
assessment_incorrect=$('section.sa-wrapper input#assessment_incorrect').selected()
|
||||
alert(assessment_incorrect)
|
||||
|
||||
root = location.protocol + "//" + location.host
|
||||
post_url=$('section.sa-wrapper input#show').attr('url')
|
||||
alert(post_url)
|
||||
final_url="/courses/MITx/6.002x/2012_Fall/modx/#{post_url}/sa_save"
|
||||
alert(final_url)
|
||||
|
||||
$('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) ->
|
||||
if response.success
|
||||
$('p.rubric').replace(response.rubric)
|
||||
$('section.sa_wrapper p#save_message').replace(response.message)
|
||||
|
||||
alert("save")
|
||||
));
|
||||
|
||||
@@ -21,9 +21,9 @@ from xmodule.contentstore.content import XASSET_SRCREF_PREFIX, StaticContent
|
||||
|
||||
log = logging.getLogger("mitx.courseware")
|
||||
|
||||
rubric_form=('<section class="sa-wrapper"><input type="radio" name="assessment" id="assessment_correct" value="correct"/>Correct<br/>'
|
||||
'<input type="radio" id="assessment_incorrect" name="assessment" value="incorrect">'
|
||||
'Incorrect<br/><input type="button" value="Save" id="save" name="save"/></section>')
|
||||
rubric_form=('<section class="sa-wrapper"><input type="radio" name="assessment" id="assessment" value="correct"/>Correct<br/>'
|
||||
'<input type="radio" id="assessment" name="assessment" value="incorrect">'
|
||||
'Incorrect<br/><input type="button" value="Save" id="save" name="save"/><p id="save_message"></p></section><br/><br/>')
|
||||
|
||||
def only_one(lst, default="", process=lambda x: x):
|
||||
"""
|
||||
@@ -61,7 +61,7 @@ class SelfAssessmentModule(XModule):
|
||||
instance_state=None, shared_state=None, **kwargs):
|
||||
XModule.__init__(self, system, location, definition, descriptor,
|
||||
instance_state, shared_state, **kwargs)
|
||||
|
||||
|
||||
dom2=etree.fromstring("<selfassessment>" + self.definition['data'] + "</selfassessment>")
|
||||
self.rubric=''.join([etree.tostring(child) for child in only_one(dom2.xpath('rubric'))])
|
||||
self.problem=''.join([etree.tostring(child) for child in only_one(dom2.xpath('problem'))])
|
||||
@@ -127,7 +127,7 @@ class SelfAssessmentModule(XModule):
|
||||
|
||||
|
||||
def show_rubric(self,get):
|
||||
return {'success': True, 'rubric':self.rubric}
|
||||
return {'success': True, 'rubric' : self.rubric}
|
||||
|
||||
|
||||
def save_problem(self, get):
|
||||
@@ -155,7 +155,29 @@ class SelfAssessmentModule(XModule):
|
||||
|
||||
self.system.track_function('save_problem_succeed', event_info)
|
||||
|
||||
return {'success': True}
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user