Commit 54687d45 by Vik Paruchuri

fixing javascript ajax path issues

parent b263117c
...@@ -209,6 +209,7 @@ class @Problem ...@@ -209,6 +209,7 @@ class @Problem
show: => show: =>
if !@el.hasClass 'showed' if !@el.hasClass 'showed'
Logger.log 'problem_show', problem: @id Logger.log 'problem_show', problem: @id
alert(@url)
$.postWithPrefix "#{@url}/problem_show", (response) => $.postWithPrefix "#{@url}/problem_show", (response) =>
answers = response.answers answers = response.answers
$.each answers, (key, value) => $.each answers, (key, value) =>
......
class @SelfAssessment
constructor: (element) -> #@$('section.action input.check').click @check
@el = $(element).find('.sa-wrapper') $('input#show').click(@show)
@id = @el.data('sa-id') #$('#save').click(function -> alert('save'))
@element_id = @el.attr('id')
@url = @el.data('url')
@render()
$: (selector) -> $(document).on('click', 'input#save', ( ->
$(selector, @el) answer=$('#answer').text()
$.postWithPrefix "modx/6.002x/sa_save", answer, (response) ->
if response.success
$('p.rubric').replace(response.rubric)
bind: => alert("save")
));
window.update_schematics() show: =>
alert("show")
#$.postWithPrefix "/sa_show", (response) =>
# answers = response.answers
# @el.addClass 'showed'
problem_prefix = @element_id.replace(/sa_/,'') save: =>
@inputs = @$("[id^=input_#{problem_prefix}_]") alert("save")
@$('input:button').click @refreshAnswers
#@$('section.action input.check').click @check
@$('input.show').click @show
@$('input.save').click @save
# Collapsibles
Collapsible.setCollapsibles(@el)
# Dynamath
@$('input.math').keyup(@refreshMath)
@$('input.math').each (index, element) =>
MathJax.Hub.Queue [@refreshMath, null, element]
updateProgress: (response) =>
if response.progress_changed
@el.attr progress: response.progress_status
@el.trigger('progressChanged')
show: =>
$.postWithPrefix "#{@url}/sa_show", (response) =>
answers = response.answers
@el.addClass 'showed'
save: =>
$.postWithPrefix "/sa_save", @answers, (response) =>
if response.success
@$('p.rubric').replace(response.rubric)
render: (content) ->
if content
@el.html(content)
JavascriptLoader.executeModuleScripts @el, () =>
@setupInputTypes()
@bind()
else
$.postWithPrefix "#{@url}/problem_get", (response) =>
@el.html(response.html)
JavascriptLoader.executeModuleScripts @el, () =>
@setupInputTypes()
@bind()
setupInputTypes: =>
@inputtypeDisplays = {}
@el.find(".capa_inputtype").each (index, inputtype) =>
classes = $(inputtype).attr('class').split(' ')
id = $(inputtype).attr('id')
for cls in classes
setupMethod = @inputtypeSetupMethods[cls]
if setupMethod?
@inputtypeDisplays[id] = setupMethod(inputtype)
gentle_alert: (msg) =>
if @el.find('.capa_alert').length
@el.find('.capa_alert').remove()
alert_elem = "<div class='capa_alert'>" + msg + "</div>"
@el.find('.action').after(alert_elem)
@el.find('.capa_alert').css(opacity: 0).animate(opacity: 1, 700)
refreshAnswers: =>
@$('input.schematic').each (index, element) ->
element.schematic.update_value()
@$(".CodeMirror").each (index, element) ->
element.CodeMirror.save() if element.CodeMirror.save
@answers = @inputs.serialize()
inputtypeSetupMethods:
'text-input-dynamath': (element) =>
###
Return: function (eqn) -> eqn that preprocesses the user formula input before
it is fed into MathJax. Return 'false' if no preprocessor specified
###
data = $(element).find('.text-input-dynamath_data')
preprocessorClassName = data.data('preprocessor')
preprocessorClass = window[preprocessorClassName]
if not preprocessorClass?
return false
else
preprocessor = new preprocessorClass()
return preprocessor.fn
javascriptinput: (element) =>
data = $(element).find(".javascriptinput_data")
params = data.data("params")
submission = data.data("submission")
evaluation = data.data("evaluation")
problemState = data.data("problem_state")
displayClass = window[data.data('display_class')]
if evaluation == ''
evaluation = null
container = $(element).find(".javascriptinput_container")
submissionField = $(element).find(".javascriptinput_input")
display = new displayClass(problemState, submission, evaluation, container, submissionField, params)
display.render()
return display
inputtypeShowAnswerMethods:
choicegroup: (element, display, answers) =>
element = $(element)
element.find('input').attr('disabled', 'disabled')
input_id = element.attr('id').replace(/inputtype_/,'')
answer = answers[input_id]
for choice in answer
element.find("label[for='input_#{input_id}_#{choice}']").addClass 'choicegroup_correct'
javascriptinput: (element, display, answers) =>
answer_id = $(element).attr('id').split("_")[1...].join("_")
answer = JSON.parse(answers[answer_id])
display.showAnswer(answer)
inputtypeHideAnswerMethods:
choicegroup: (element, display) =>
element = $(element)
element.find('input').attr('disabled', null)
element.find('label').removeClass('choicegroup_correct')
javascriptinput: (element, display) =>
display.hideAnswer()
alert($('input#save').attr('url'))
...@@ -19,9 +19,6 @@ from xmodule.contentstore.content import XASSET_SRCREF_PREFIX, StaticContent ...@@ -19,9 +19,6 @@ from xmodule.contentstore.content import XASSET_SRCREF_PREFIX, StaticContent
log = logging.getLogger("mitx.courseware") log = logging.getLogger("mitx.courseware")
problem_form=('<section class="sa-wrapper" sa_id="one"><input type="text" name="answer" '
'id="answer"/><br/><input type="button" value="Check" id ="save" name="save"/><p id="rubric"></p></section>')
rubric_form=('<section class="sa-wrapper" sa_id="two"><input type="radio" name="assessment" value="correct"/>Correct<br/>' rubric_form=('<section class="sa-wrapper" sa_id="two"><input type="radio" name="assessment" value="correct"/>Correct<br/>'
'<input type="radio" name="assessment" value="incorrect">' '<input type="radio" name="assessment" value="incorrect">'
'Incorrect<br/><input type="button" value="Save" id="show" name="show"/></section>') 'Incorrect<br/><input type="button" value="Save" id="show" name="show"/></section>')
...@@ -61,6 +58,11 @@ class SelfAssessmentModule(XModule): ...@@ -61,6 +58,11 @@ class SelfAssessmentModule(XModule):
self.rubric=''.join([etree.tostring(child) for child in only_one(dom2.xpath('rubric'))]) 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'))]) self.problem=''.join([etree.tostring(child) for child in only_one(dom2.xpath('problem'))])
problem_form=('<section class="sa-wrapper" sa_id="one"><input type="text" name="answer" '
'id="answer"/><br/>'
'<input type="button" value="Check" id ="save" name="save" url="{0}"/>'
'<p id="rubric"></p></section>').format(self.location)
self.problem=''.join([self.problem,problem_form]) self.problem=''.join([self.problem,problem_form])
self.rubric=''.join([self.rubric,rubric_form]) self.rubric=''.join([self.rubric,rubric_form])
...@@ -70,6 +72,9 @@ class SelfAssessmentModule(XModule): ...@@ -70,6 +72,9 @@ class SelfAssessmentModule(XModule):
self.html = self.problem self.html = self.problem
self.answers={}
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
''' '''
This is called by courseware.module_render, to handle an AJAX call. This is called by courseware.module_render, to handle an AJAX call.
...@@ -106,14 +111,25 @@ class SelfAssessmentModule(XModule): ...@@ -106,14 +111,25 @@ class SelfAssessmentModule(XModule):
with the error key only present if success is False. with the error key only present if success is False.
''' '''
event_info = dict() event_info = dict()
event_info['state'] = self.lcp.get_state() event_info['state'] = {'seed': 1,
event_info['problem_id'] = self.location.url() 'student_answers': self.answers,
'correct_map': {'self_assess' : {'correctness': False,
return {'success': True, 'rubric' : self.rubric} 'npoints': 0,
'msg': "",
'hint': "",
'hintmode': "",
'queuestate': "",
}},
'done': True}
event_info['problem_id'] = self.location.url()
answers = self.make_dict_of_responses(get)
event_info['answers'] = answers
self.system.track_function('save_problem_succeed', event_info)
return {'success': True, 'rubric' : self.rubric}
class SelfAssessmentDescriptor(XmlDescriptor, EditingDescriptor): class SelfAssessmentDescriptor(XmlDescriptor, EditingDescriptor):
......
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