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
1abe15d4
Commit
1abe15d4
authored
May 10, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite Problem module
parent
8e7bf4c1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
90 additions
and
126 deletions
+90
-126
djangoapps/courseware/modules/capa_module.py
+2
-8
static/coffee/spec/courseware_spec.coffee
+1
-1
static/coffee/spec/courseware_spec.js
+1
-1
static/coffee/src/courseware.coffee
+4
-1
static/sass/courseware/_courseware.scss
+7
-0
templates/coffee/src/modules/problem.coffee
+57
-0
templates/coffee/src/modules/sequence.coffee
+1
-1
templates/problem.html
+16
-17
templates/problem.js
+0
-96
templates/problem_ajax.html
+1
-1
No files found.
djangoapps/courseware/modules/capa_module.py
View file @
1abe15d4
...
@@ -61,12 +61,6 @@ class Module(XModule):
...
@@ -61,12 +61,6 @@ class Module(XModule):
'ajax_url'
:
self
.
ajax_url
,
'ajax_url'
:
self
.
ajax_url
,
})
})
def
get_init_js
(
self
):
return
render_to_string
(
'problem.js'
,
{
'id'
:
self
.
item_id
,
'ajax_url'
:
self
.
ajax_url
,
})
def
get_problem_html
(
self
,
encapsulate
=
True
):
def
get_problem_html
(
self
,
encapsulate
=
True
):
html
=
self
.
lcp
.
get_html
()
html
=
self
.
lcp
.
get_html
()
content
=
{
'name'
:
self
.
name
,
content
=
{
'name'
:
self
.
name
,
...
@@ -130,8 +124,8 @@ class Module(XModule):
...
@@ -130,8 +124,8 @@ class Module(XModule):
html
=
render_to_string
(
'problem.html'
,
context
)
html
=
render_to_string
(
'problem.html'
,
context
)
if
encapsulate
:
if
encapsulate
:
html
=
'<div id="
main_{id
}">'
.
format
(
id
=
self
.
item_id
)
+
html
+
"</div>"
html
=
'<div id="
problem_{id}" class="problem" data-url="{ajax_url
}">'
.
format
(
id
=
self
.
item_id
)
+
html
+
"</div>"
return
html
return
html
def
__init__
(
self
,
system
,
xml
,
item_id
,
state
=
None
):
def
__init__
(
self
,
system
,
xml
,
item_id
,
state
=
None
):
...
...
static/coffee/spec/courseware_spec.coffee
View file @
1abe15d4
...
@@ -27,7 +27,7 @@ describe 'Courseware', ->
...
@@ -27,7 +27,7 @@ describe 'Courseware', ->
it
'binds the sequential content change event'
,
->
it
'binds the sequential content change event'
,
->
@
courseware
.
bind
()
@
courseware
.
bind
()
expect
(
$
(
'#seq_content'
)).
toHandleWith
'c
hange
'
,
@
courseware
.
render
expect
(
$
(
'#seq_content'
)).
toHandleWith
'c
ontentChanged
'
,
@
courseware
.
render
describe
'render'
,
->
describe
'render'
,
->
beforeEach
->
beforeEach
->
...
...
static/coffee/spec/courseware_spec.js
View file @
1abe15d4
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
});
});
return
it
(
'binds the sequential content change event'
,
function
()
{
return
it
(
'binds the sequential content change event'
,
function
()
{
this
.
courseware
.
bind
();
this
.
courseware
.
bind
();
return
expect
(
$
(
'#seq_content'
)).
toHandleWith
(
'c
hange
'
,
this
.
courseware
.
render
);
return
expect
(
$
(
'#seq_content'
)).
toHandleWith
(
'c
ontentChanged
'
,
this
.
courseware
.
render
);
});
});
});
});
return
describe
(
'render'
,
function
()
{
return
describe
(
'render'
,
function
()
{
...
...
static/coffee/src/courseware.coffee
View file @
1abe15d4
...
@@ -12,9 +12,12 @@ class @Courseware
...
@@ -12,9 +12,12 @@ class @Courseware
bind
:
->
bind
:
->
if
$
(
'#seq_content'
).
length
if
$
(
'#seq_content'
).
length
$
(
'#seq_content'
).
change
@
render
$
(
'#seq_content'
).
bind
'contentChanged'
,
@
render
render
:
->
render
:
->
$
(
'.course-content .video'
).
each
->
$
(
'.course-content .video'
).
each
->
id
=
$
(
this
).
attr
(
'id'
).
replace
(
/video_/
,
''
)
id
=
$
(
this
).
attr
(
'id'
).
replace
(
/video_/
,
''
)
new
Video
id
,
$
(
this
).
data
(
'streams'
)
new
Video
id
,
$
(
this
).
data
(
'streams'
)
$
(
'.course-content .problems-wrapper'
).
each
->
id
=
$
(
this
).
attr
(
'id'
).
replace
(
/problem_/
,
''
)
new
Problem
id
,
$
(
this
).
data
(
'url'
)
static/sass/courseware/_courseware.scss
View file @
1abe15d4
...
@@ -54,6 +54,13 @@ div.course-wrapper {
...
@@ -54,6 +54,13 @@ div.course-wrapper {
display
:
table-cell
;
display
:
table-cell
;
vertical-align
:
top
;
vertical-align
:
top
;
&
.problem-header
{
section
.staff
{
margin-top
:
30px
;
font-size
:
80%
;
}
}
@media
screen
and
(
max-width
:
1120px
)
{
@media
screen
and
(
max-width
:
1120px
)
{
display
:
block
;
display
:
block
;
width
:
auto
;
width
:
auto
;
...
...
templates/coffee/src/modules/problem.coffee
0 → 100644
View file @
1abe15d4
class
@
Problem
constructor
:
(
@
id
,
url
)
->
@
element
=
$
(
"#problem_
#{
id
}
"
)
@
content_url
=
"
#{
url
}
problem_get?id=
#{
@
id
}
"
@
render
()
$
:
(
selector
)
->
$
(
selector
,
@
element
)
bind
:
=>
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
]
window
.
update_schematics
()
@
$
(
'section.action input:button'
).
click
@
refreshAnswers
@
$
(
'section.action input.check'
).
click
@
check
@
$
(
'section.action input.reset'
).
click
@
reset
@
$
(
'section.action input.show'
).
click
@
show
@
$
(
'section.action input.save'
).
click
@
save
render
:
(
content
)
->
if
content
@
element
.
html
(
content
)
@
bind
()
else
@
element
.
load
@
content_url
,
@
bind
check
:
=>
Logger
.
log
'problem_check'
,
@
answers
$
.
post
"/modx/problem/
#{
@
id
}
/problem_check"
,
@
answers
,
(
response
)
=>
switch
response
.
success
when
'incorrect'
,
'correct'
@
render
(
response
.
contents
)
else
alert
(
response
.
success
)
reset
:
=>
Logger
.
log
'problem_reset'
,
@
answers
$
.
post
"/modx/problem/
#{
@
id
}
/problem_reset"
,
id
:
@
id
,
(
content
)
=>
@
render
(
content
)
show
:
=>
Logger
.
log
'problem_show'
,
problem
:
@
id
$
.
post
"/modx/problem/
#{
@
id
}
/problem_show"
,
(
response
)
=>
$
.
each
response
,
(
key
,
value
)
=>
@
$
(
"#answer_
#{
key
}
"
).
text
(
value
)
save
:
=>
Logger
.
log
'problem_save'
,
@
answers
$
.
post
"/modx/problem/
#{
@
id
}
/problem_save"
,
@
answers
,
(
response
)
=>
if
response
.
success
alert
'Saved'
refreshAnswers
:
=>
@
answers
=
{}
@
$
(
'input.schematic'
).
each
(
index
,
element
)
->
element
.
schematic
.
update_value
()
$
.
each
@
$
(
"[id^=input_
#{
@
id
}
_]"
),
(
index
,
input
)
=>
@
answers
[
$
(
input
).
attr
(
'id'
)]
=
$
(
input
).
val
()
templates/coffee/src/modules/sequence.coffee
View file @
1abe15d4
...
@@ -39,7 +39,7 @@ class window.Sequence
...
@@ -39,7 +39,7 @@ class window.Sequence
MathJax
.
Hub
.
Queue
([
"Typeset"
,
MathJax
.
Hub
])
MathJax
.
Hub
.
Queue
([
"Typeset"
,
MathJax
.
Hub
])
@
position
=
new_position
@
position
=
new_position
$
(
'#seq_content'
).
change
()
$
(
'#seq_content'
).
trigger
'contentChanged'
goto
:
(
event
)
=>
goto
:
(
event
)
=>
event
.
preventDefault
()
event
.
preventDefault
()
...
...
templates/problem.html
View file @
1abe15d4
<
%
namespace
name=
'static'
file=
'static_content.html'
/>
<
%
namespace
name=
'static'
file=
'static_content.html'
/>
<h2
class=
"problem-header"
>
${ problem['name'] }
<h2
class=
"problem-header"
>
% if problem['weight']:
${ problem['name'] }
: ${ problem['weight'] } points
% if problem['weight']:
% endif
: ${ problem['weight'] } points
% if settings.QUICKEDIT:
% endif
<span
class=
"staff"
>
<br/>
% if settings.QUICKEDIT:
<br/>
<section
class=
"staff"
>
<br/>
<a
href=
${MITX_ROOT_URL}/quickedit/${id}
>
Quick Edit Problem
</a>
<br/>
</section>
<font
size=
-2
><a
href=
${MITX_ROOT_URL}/quickedit/${id}
>
Quick
% endif
Edit Problem
</a></font></span>
% endif
</h2>
</h2>
<section
class=
"problem"
>
<section
class=
"problem"
>
...
@@ -21,16 +19,16 @@ Edit Problem</a></font></span>
...
@@ -21,16 +19,16 @@ Edit Problem</a></font></span>
<input
type=
"hidden"
name=
"problem_id"
value=
"${ problem['name'] }"
>
<input
type=
"hidden"
name=
"problem_id"
value=
"${ problem['name'] }"
>
% if check_button:
% if check_button:
<input
id=
"check_${ id }"
type=
"button"
value=
"${ check_button }"
>
<input
class=
"check"
type=
"button"
value=
"${ check_button }"
>
% endif
% endif
% if reset_button:
% if reset_button:
<input
id=
"reset_${ id }"
type=
"button"
value=
"Reset"
>
<input
class=
"reset"
type=
"button"
value=
"Reset"
>
% endif
% endif
% if save_button:
% if save_button:
<input
id=
"save_${ id }"
type=
"button"
value=
"Save"
>
<input
class=
"save"
type=
"button"
value=
"Save"
>
% endif
% endif
% if answer_available:
% if answer_available:
<input
id=
"show_${ id }"
type=
"button"
value=
"Show Answer"
>
<input
class=
"show"
type=
"button"
value=
"Show Answer"
>
% endif
% endif
% if explain :
% if explain :
<a
href=
"/courseware/6.002_Spring_2012/${ explain }"
class=
"new-page"
>
Explanation
</a>
<a
href=
"/courseware/6.002_Spring_2012/${ explain }"
class=
"new-page"
>
Explanation
</a>
...
@@ -42,3 +40,4 @@ Edit Problem</a></font></span>
...
@@ -42,3 +40,4 @@ Edit Problem</a></font></span>
% endif
% endif
</section>
</section>
</section>
</section>
templates/problem.js
deleted
100644 → 0
View file @
8e7bf4c1
function
$
{
id
}
_content_updated
()
{
MathJax
.
Hub
.
Queue
([
"Typeset"
,
MathJax
.
Hub
]);
update_schematics
();
$
(
'#check_${ id }'
).
unbind
(
'click'
).
click
(
function
()
{
$
(
"input.schematic"
).
each
(
function
(
index
,
element
){
element
.
schematic
.
update_value
();
});
$
(
".CodeMirror"
).
each
(
function
(
index
,
element
){
if
(
element
.
CodeMirror
.
save
)
element
.
CodeMirror
.
save
();
});
var
submit_data
=
{};
$
.
each
(
$
(
"[id^=input_${ id }_]"
),
function
(
index
,
value
){
if
(
value
.
type
===
"checkbox"
){
if
(
value
.
checked
)
{
if
(
typeof
submit_data
[
value
.
name
]
==
'undefined'
){
submit_data
[
value
.
name
]
=
[];
}
submit_data
[
value
.
name
].
push
(
value
.
value
);
}
}
if
(
value
.
type
===
"radio"
){
if
(
value
.
checked
)
{
submit_data
[
value
.
name
]
=
value
.
value
;
}
}
else
{
submit_data
[
value
.
id
]
=
value
.
value
;
}
});
postJSON
(
'${ MITX_ROOT_URL }/modx/problem/${ id }/problem_check'
,
submit_data
,
function
(
json
)
{
switch
(
json
.
success
)
{
case
'incorrect'
:
// Worked, but answer not
case
'correct'
:
$
(
'#main_${ id }'
).
html
(
json
.
contents
);
$
{
id
}
_content_updated
();
break
;
default
:
alert
(
json
.
success
);
}}
);
log_event
(
'problem_check'
,
submit_data
);
});
$
(
'#reset_${ id }'
).
unbind
(
'click'
).
click
(
function
()
{
var
submit_data
=
{};
$
.
each
(
$
(
"[id^=input_${ id }_]"
),
function
(
index
,
value
){
submit_data
[
value
.
id
]
=
value
.
value
;
});
postJSON
(
'${ MITX_ROOT_URL }/modx/problem/${ id }/problem_reset'
,
{
'id'
:
'${ id }'
},
function
(
html_as_json
)
{
$
(
'#main_${ id }'
).
html
(
html_as_json
);
$
{
id
}
_content_updated
();
});
log_event
(
'problem_reset'
,
submit_data
);
});
// show answer button
// TODO: the button should turn into "hide answer" afterwards
$
(
'#show_${ id }'
).
unbind
(
'click'
).
click
(
function
()
{
postJSON
(
'${ MITX_ROOT_URL }/modx/problem/${ id }/problem_show'
,
{},
function
(
data
)
{
for
(
var
key
in
data
)
{
if
(
$
.
isArray
(
data
[
key
])){
for
(
var
ans_index
in
data
[
key
]){
var
choice_id
=
'input_'
+
key
+
'_'
+
data
[
key
][
ans_index
];
$
(
"label[for="
+
choice_id
+
"]"
).
attr
(
"correct_answer"
,
"true"
);
}
}
$
(
"#answer_"
+
key
).
text
(
data
[
key
]);
}
});
log_event
(
'problem_show'
,
{
'problem'
:
'${ id }'
});
});
$
(
'#save_${ id }'
).
unbind
(
'click'
).
click
(
function
()
{
$
(
"input.schematic"
).
each
(
function
(
index
,
element
){
element
.
schematic
.
update_value
();
});
var
submit_data
=
{};
$
.
each
(
$
(
"[id^=input_${ id }_]"
),
function
(
index
,
value
)
{
submit_data
[
value
.
id
]
=
value
.
value
;
});
postJSON
(
'${ MITX_ROOT_URL }/modx/problem/${ id }/problem_save'
,
submit_data
,
function
(
data
)
{
if
(
data
.
success
)
{
alert
(
'Saved'
);
}});
log_event
(
'problem_save'
,
submit_data
);
});
}
function
$
{
id
}
_load
()
{
$
(
'#main_${ id }'
).
load
(
'${ ajax_url }problem_get?id=${ id }'
,
$
{
id
}
_content_updated
);
}
$
(
function
()
{
$
{
id
}
_load
();
});
templates/problem_ajax.html
View file @
1abe15d4
<section
id=
"
main_${id}"
class=
"problems-wrapper
"
></section>
<section
id=
"
problem_${id}"
class=
"problems-wrapper"
data-url=
"${ajax_url}
"
></section>
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