Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
OpenEdx
problem-builder
Commits
bb863a3e
Commit
bb863a3e
authored
Feb 28, 2014
by
Xavier Antoviaque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
light-children: Add support for JS handling of children
parent
cb569289
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
11 deletions
+54
-11
mentoring/html.py
+2
-1
mentoring/light_children.py
+17
-2
mentoring/mentoring.py
+1
-1
mentoring/quizz.py
+2
-3
static/js/mentoring.js
+32
-4
No files found.
mentoring/html.py
View file @
bb863a3e
...
@@ -50,7 +50,8 @@ class HTMLBlock(LightChild):
...
@@ -50,7 +50,8 @@ class HTMLBlock(LightChild):
block
.
light_children
=
[]
block
.
light_children
=
[]
node
.
tag
=
'div'
node
.
tag
=
'div'
block
.
content
=
etree
.
tostring
(
node
)
block
.
content
=
unicode
(
etree
.
tostring
(
node
))
node
.
tag
=
'html'
return
block
return
block
...
...
mentoring/light_children.py
View file @
bb863a3e
...
@@ -84,7 +84,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
...
@@ -84,7 +84,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
def
add_node_as_child
(
cls
,
block
,
xml_child
,
child_id
):
def
add_node_as_child
(
cls
,
block
,
xml_child
,
child_id
):
# Instantiate child
# Instantiate child
child_class
=
cls
.
get_class_by_element
(
xml_child
.
tag
)
child_class
=
cls
.
get_class_by_element
(
xml_child
.
tag
)
child
=
child_class
()
child
=
child_class
(
block
.
runtime
)
child
.
name
=
u'{}_{}'
.
format
(
block
.
name
,
child_id
)
child
.
name
=
u'{}_{}'
.
format
(
block
.
name
,
child_id
)
# Add any children the child may itself have
# Add any children the child may itself have
...
@@ -123,7 +123,10 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
...
@@ -123,7 +123,10 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
"""
"""
Replacement for ```self.runtime.render_child()```
Replacement for ```self.runtime.render_child()```
"""
"""
return
getattr
(
child
,
view_name
)(
context
)
frag
=
getattr
(
child
,
view_name
)(
context
)
frag
.
content
=
u'<div class="xblock-light-child" name="{}" data-type="{}">{}</div>'
.
format
(
child
.
name
,
child
.
__class__
.
__name__
,
frag
.
content
)
return
frag
def
get_children_fragment
(
self
,
context
,
view_name
=
'student_view'
,
instance_of
=
None
,
def
get_children_fragment
(
self
,
context
,
view_name
=
'student_view'
,
instance_of
=
None
,
not_instance_of
=
None
):
not_instance_of
=
None
):
...
@@ -155,6 +158,12 @@ class LightChild(Plugin, LightChildrenMixin):
...
@@ -155,6 +158,12 @@ class LightChild(Plugin, LightChildrenMixin):
"""
"""
entry_point
=
'xblock.light_children'
entry_point
=
'xblock.light_children'
def
__init__
(
self
,
runtime
):
self
.
runtime
=
runtime
def
save
(
self
):
pass
class
LightChildField
(
object
):
class
LightChildField
(
object
):
"""
"""
...
@@ -168,9 +177,15 @@ class LightChildField(object):
...
@@ -168,9 +177,15 @@ class LightChildField(object):
class
String
(
LightChildField
):
class
String
(
LightChildField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
value
=
kwargs
.
get
(
'default'
,
''
)
or
''
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
value
return
self
.
value
def
split
(
self
,
*
args
,
**
kwargs
):
return
self
.
value
.
split
(
*
args
,
**
kwargs
)
class
Boolean
(
LightChildField
):
class
Boolean
(
LightChildField
):
pass
pass
...
...
mentoring/mentoring.py
View file @
bb863a3e
...
@@ -65,7 +65,6 @@ class MentoringBlock(XBlockWithLightChildren):
...
@@ -65,7 +65,6 @@ class MentoringBlock(XBlockWithLightChildren):
has_children
=
True
has_children
=
True
def
student_view
(
self
,
context
):
def
student_view
(
self
,
context
):
log
.
warn
(
'xml_content => {}'
.
format
(
self
.
xml_content
))
fragment
,
named_children
=
self
.
get_children_fragment
(
context
,
view_name
=
'mentoring_view'
,
fragment
,
named_children
=
self
.
get_children_fragment
(
context
,
view_name
=
'mentoring_view'
,
not_instance_of
=
MentoringMessageBlock
)
not_instance_of
=
MentoringMessageBlock
)
...
@@ -129,6 +128,7 @@ class MentoringBlock(XBlockWithLightChildren):
...
@@ -129,6 +128,7 @@ class MentoringBlock(XBlockWithLightChildren):
elif
completed
and
self
.
next_step
==
self
.
url_name
:
elif
completed
and
self
.
next_step
==
self
.
url_name
:
self
.
next_step
=
self
.
followed_by
self
.
next_step
=
self
.
followed_by
log
.
warn
(
submit_results
);
self
.
completed
=
bool
(
completed
)
self
.
completed
=
bool
(
completed
)
return
{
return
{
'submitResults'
:
submit_results
,
'submitResults'
:
submit_results
,
...
...
mentoring/quizz.py
View file @
bb863a3e
...
@@ -144,9 +144,8 @@ class QuizzBlock(LightChild):
...
@@ -144,9 +144,8 @@ class QuizzBlock(LightChild):
Returns the tips contained in this block
Returns the tips contained in this block
"""
"""
tips
=
[]
tips
=
[]
for
child_id
in
self
.
children
:
# pylint: disable=E1101
for
child
in
self
.
get_children_objects
():
child
=
self
.
runtime
.
get_block
(
child_id
)
if
isinstance
(
child
,
QuizzTipBlock
):
if
child
.
xml_element_name
()
==
'tip'
:
tips
.
append
(
child
)
tips
.
append
(
child
)
return
tips
return
tips
...
...
static/js/mentoring.js
View file @
bb863a3e
...
@@ -7,7 +7,7 @@ function MentoringBlock(runtime, element) {
...
@@ -7,7 +7,7 @@ function MentoringBlock(runtime, element) {
}
}
function
callIfExists
(
obj
,
fn
)
{
function
callIfExists
(
obj
,
fn
)
{
if
(
typeof
obj
[
fn
]
==
'function'
)
{
if
(
typeof
obj
!==
'undefined'
&&
typeof
obj
[
fn
]
==
'function'
)
{
return
obj
[
fn
].
apply
(
obj
,
Array
.
prototype
.
slice
.
call
(
arguments
,
2
));
return
obj
[
fn
].
apply
(
obj
,
Array
.
prototype
.
slice
.
call
(
arguments
,
2
));
}
else
{
}
else
{
return
undefined
;
return
undefined
;
...
@@ -19,8 +19,9 @@ function MentoringBlock(runtime, element) {
...
@@ -19,8 +19,9 @@ function MentoringBlock(runtime, element) {
$
.
each
(
results
.
submitResults
||
[],
function
(
index
,
submitResult
)
{
$
.
each
(
results
.
submitResults
||
[],
function
(
index
,
submitResult
)
{
var
input
=
submitResult
[
0
],
var
input
=
submitResult
[
0
],
result
=
submitResult
[
1
];
result
=
submitResult
[
1
],
callIfExists
(
runtime
.
childMap
(
element
,
input
),
'handleSubmit'
,
result
);
child
=
getChildByName
(
element
,
input
);
callIfExists
(
child
,
'handleSubmit'
,
result
);
});
});
$
(
'.progress'
,
element
).
data
(
'completed'
,
results
.
completed
?
'True'
:
'False'
)
$
(
'.progress'
,
element
).
data
(
'completed'
,
results
.
completed
?
'True'
:
'False'
)
...
@@ -30,9 +31,36 @@ function MentoringBlock(runtime, element) {
...
@@ -30,9 +31,36 @@ function MentoringBlock(runtime, element) {
$
(
'.messages'
,
element
).
append
(
results
.
message
);
$
(
'.messages'
,
element
).
append
(
results
.
message
);
}
}
function
getChildren
(
element
)
{
var
children_dom
=
$
(
'.xblock-light-child'
,
element
),
children
=
[];
$
.
each
(
children_dom
,
function
(
index
,
child_dom
)
{
var
child_type
=
$
(
child_dom
).
attr
(
'data-type'
),
child
=
window
[
child_type
];
if
(
typeof
child
!==
'undefined'
)
{
child
=
child
(
runtime
,
child_dom
);
child
.
name
=
$
(
child_dom
).
attr
(
'name'
);
children
.
push
(
child
);
}
});
return
children
;
}
function
getChildByName
(
element
,
name
)
{
var
children
=
getChildren
(
element
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
child
=
children
[
i
];
if
(
child
.
name
===
name
)
{
return
child
;
}
}
}
$
(
element
).
find
(
'.submit'
).
bind
(
'click'
,
function
()
{
$
(
element
).
find
(
'.submit'
).
bind
(
'click'
,
function
()
{
var
data
=
{};
var
data
=
{};
var
children
=
runtime
.
c
hildren
(
element
);
var
children
=
getC
hildren
(
element
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
child
=
children
[
i
];
var
child
=
children
[
i
];
if
(
child
.
name
!==
undefined
)
{
if
(
child
.
name
!==
undefined
)
{
...
...
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