Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
947e6e6e
Commit
947e6e6e
authored
Oct 31, 2012
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on ajax calls
parent
74e6834c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
128 deletions
+44
-128
common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee
+16
-128
common/lib/xmodule/xmodule/self_assessment_module.py
+28
-0
No files found.
common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee
View file @
947e6e6e
...
@@ -11,11 +11,9 @@ class @Problem
...
@@ -11,11 +11,9 @@ class @Problem
$
(
selector
,
@
el
)
$
(
selector
,
@
el
)
bind
:
=>
bind
:
=>
problem_prefix
=
@
element_id
.
replace
(
/
problem
_/
,
''
)
problem_prefix
=
@
element_id
.
replace
(
/
sa
_/
,
''
)
@
inputs
=
@
$
(
"[id^=input_
#{
problem_prefix
}
_]"
)
@
inputs
=
@
$
(
"[id^=input_
#{
problem_prefix
}
_]"
)
@
$
(
'section.action input:button'
).
click
@
refreshAnswers
@
$
(
'section.action input.check'
).
click
@
check
@
$
(
'section.action input.show'
).
click
@
show
@
$
(
'section.action input.show'
).
click
@
show
@
$
(
'section.action input.save'
).
click
@
save
@
$
(
'section.action input.save'
).
click
@
save
...
@@ -26,7 +24,7 @@ class @Problem
...
@@ -26,7 +24,7 @@ class @Problem
@
setupInputTypes
()
@
setupInputTypes
()
@
bind
()
@
bind
()
else
else
$
.
postWithPrefix
"
#{
@
url
}
/
problem
_get"
,
(
response
)
=>
$
.
postWithPrefix
"
#{
@
url
}
/
sa
_get"
,
(
response
)
=>
@
el
.
html
(
response
.
html
)
@
el
.
html
(
response
.
html
)
JavascriptLoader
.
executeModuleScripts
@
el
,
()
=>
JavascriptLoader
.
executeModuleScripts
@
el
,
()
=>
@
setupInputTypes
()
@
setupInputTypes
()
...
@@ -36,86 +34,21 @@ class @Problem
...
@@ -36,86 +34,21 @@ class @Problem
# TODO add hooks for problem types here by inspecting response.html and doing
# TODO add hooks for problem types here by inspecting response.html and doing
# stuff if a div w a class is found
# stuff if a div w a class is found
setupInputTypes
:
=>
show
:
=>
@
inputtypeDisplays
=
{}
Logger
.
log
'sa_show'
,
problem
:
@
id
@
el
.
find
(
".capa_inputtype"
).
each
(
index
,
inputtype
)
=>
$
.
postWithPrefix
"
#{
@
url
}
/sa_show"
,
(
response
)
=>
classes
=
$
(
inputtype
).
attr
(
'class'
).
split
(
' '
)
answers
=
response
.
answers
id
=
$
(
inputtype
).
attr
(
'id'
)
$
.
each
answers
,
(
key
,
value
)
=>
for
cls
in
classes
if
$
.
isArray
(
value
)
setupMethod
=
@
inputtypeSetupMethods
[
cls
]
for
choice
in
value
if
setupMethod
?
@
$
(
"label[for='input_
#{
key
}
_
#{
choice
}
']"
).
attr
correct_answer
:
'true'
@
inputtypeDisplays
[
id
]
=
setupMethod
(
inputtype
)
check
:
=>
Logger
.
log
'problem_check'
,
@
answers
$
.
postWithPrefix
"
#{
@
url
}
/problem_check"
,
@
answers
,
(
response
)
=>
switch
response
.
success
when
'incorrect'
,
'correct'
@
render
(
response
.
contents
)
@
updateProgress
response
if
@
el
.
hasClass
'showed'
@
el
.
removeClass
'showed'
else
else
@
gentle_alert
response
.
success
answer
=
@
$
(
"#answer_
#{
key
}
, #solution_
#{
key
}
"
)
answer
.
html
(
value
)
Collapsible
.
setCollapsibles
(
answer
)
reset
:
=>
@
$
(
'.show'
).
val
'Hide Answer'
Logger
.
log
'problem_reset'
,
@
answers
@
el
.
addClass
'showed'
$
.
postWithPrefix
"
#{
@
url
}
/problem_reset"
,
id
:
@
id
,
(
response
)
=>
@
render
(
response
.
html
)
@
updateProgress
response
# TODO this needs modification to deal with javascript responses; perhaps we
# need something where responsetypes can define their own behavior when show
# is called.
show
:
=>
if
!
@
el
.
hasClass
'showed'
Logger
.
log
'problem_show'
,
problem
:
@
id
$
.
postWithPrefix
"
#{
@
url
}
/problem_show"
,
(
response
)
=>
answers
=
response
.
answers
$
.
each
answers
,
(
key
,
value
)
=>
if
$
.
isArray
(
value
)
for
choice
in
value
@
$
(
"label[for='input_
#{
key
}
_
#{
choice
}
']"
).
attr
correct_answer
:
'true'
else
answer
=
@
$
(
"#answer_
#{
key
}
, #solution_
#{
key
}
"
)
answer
.
html
(
value
)
Collapsible
.
setCollapsibles
(
answer
)
# TODO remove the above once everything is extracted into its own
# inputtype functions.
@
el
.
find
(
".capa_inputtype"
).
each
(
index
,
inputtype
)
=>
classes
=
$
(
inputtype
).
attr
(
'class'
).
split
(
' '
)
for
cls
in
classes
display
=
@
inputtypeDisplays
[
$
(
inputtype
).
attr
(
'id'
)]
showMethod
=
@
inputtypeShowAnswerMethods
[
cls
]
showMethod
(
inputtype
,
display
,
answers
)
if
showMethod
?
@
el
.
find
(
'.problem > div'
).
each
(
index
,
element
)
=>
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
element
]
@
$
(
'.show'
).
val
'Hide Answer'
@
el
.
addClass
'showed'
@
updateProgress
response
else
@
$
(
'[id^=answer_], [id^=solution_]'
).
text
''
@
$
(
'[correct_answer]'
).
attr
correct_answer
:
null
@
el
.
removeClass
'showed'
@
$
(
'.show'
).
val
'Show Answer'
@
el
.
find
(
".capa_inputtype"
).
each
(
index
,
inputtype
)
=>
display
=
@
inputtypeDisplays
[
$
(
inputtype
).
attr
(
'id'
)]
classes
=
$
(
inputtype
).
attr
(
'class'
).
split
(
' '
)
for
cls
in
classes
hideMethod
=
@
inputtypeHideAnswerMethods
[
cls
]
hideMethod
(
inputtype
,
display
)
if
hideMethod
?
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
)
save
:
=>
save
:
=>
Logger
.
log
'problem_save'
,
@
answers
Logger
.
log
'problem_save'
,
@
answers
...
@@ -125,51 +58,6 @@ class @Problem
...
@@ -125,51 +58,6 @@ class @Problem
@
gentle_alert
saveMessage
@
gentle_alert
saveMessage
@
updateProgress
response
@
updateProgress
response
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
:
inputtypeShowAnswerMethods
:
choicegroup
:
(
element
,
display
,
answers
)
=>
choicegroup
:
(
element
,
display
,
answers
)
=>
element
=
$
(
element
)
element
=
$
(
element
)
...
...
common/lib/xmodule/xmodule/self_assessment_module.py
View file @
947e6e6e
...
@@ -70,6 +70,34 @@ class SelfAssessmentModule(XModule):
...
@@ -70,6 +70,34 @@ class SelfAssessmentModule(XModule):
self
.
html
=
self
.
problem
self
.
html
=
self
.
problem
def
handle_ajax
(
self
,
dispatch
,
get
):
'''
This is called by courseware.module_render, to handle an AJAX call.
"get" is request.POST.
Returns a json dictionary:
{ 'progress_changed' : True/False,
'progress' : 'none'/'in_progress'/'done',
<other request-specific values here > }
'''
handlers
=
{
'sa_get'
:
self
.
show_problem
'sa_show'
:
self
.
show_rubric
,
'sa_save'
:
self
.
save_problem
,
}
if
dispatch
not
in
handlers
:
return
'Error'
before
=
self
.
get_progress
()
d
=
handlers
[
dispatch
](
get
)
after
=
self
.
get_progress
()
d
.
update
({
'progress_changed'
:
after
!=
before
,
'progress_status'
:
Progress
.
to_js_status_str
(
after
),
})
return
json
.
dumps
(
d
,
cls
=
ComplexEncoder
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment