Commit 509e5315 by Xavier Antoviaque

light-children: Re-rendering of units upon display

parent bb863a3e
...@@ -151,6 +151,16 @@ class XBlockWithLightChildren(LightChildrenMixin, XBlock): ...@@ -151,6 +151,16 @@ class XBlockWithLightChildren(LightChildrenMixin, XBlock):
super(XBlockWithLightChildren, self).__init__(*args, **kwargs) super(XBlockWithLightChildren, self).__init__(*args, **kwargs)
self.load_children_from_xml_content() self.load_children_from_xml_content()
@XBlock.json_handler
def view(self, data, suffix=''):
"""
Current HTML view of the XBlock, for refresh by client
"""
frag = self.student_view({})
return {
'html': frag.content,
}
class LightChild(Plugin, LightChildrenMixin): class LightChild(Plugin, LightChildrenMixin):
""" """
......
...@@ -58,18 +58,33 @@ function MentoringBlock(runtime, element) { ...@@ -58,18 +58,33 @@ function MentoringBlock(runtime, element) {
} }
} }
$(element).find('.submit').bind('click', function() { function initXBlock() {
var data = {}; $(element).find('.submit').bind('click', function() {
var children = getChildren(element); var data = {};
for (var i = 0; i < children.length; i++) { var children = getChildren(element);
var child = children[i]; for (var i = 0; i < children.length; i++) {
if (child.name !== undefined) { var child = children[i];
data[child.name] = callIfExists(child, 'submit'); if (child.name !== undefined) {
data[child.name] = callIfExists(child, 'submit');
}
} }
} var handlerUrl = runtime.handlerUrl(element, 'submit');
var handlerUrl = runtime.handlerUrl(element, 'submit'); $.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults);
$.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults); });
});
renderProgress();
}
function handleRefreshResults(results) {
$(element).html(results.html);
initXBlock();
}
function refreshXBlock() {
var handlerUrl = runtime.handlerUrl(element, 'view');
$.post(handlerUrl, '{}').success(handleRefreshResults);
}
renderProgress(); // We need to manually refresh, XBlocks are currently loaded together with the section
refreshXBlock(element);
} }
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