Commit f8cda89b by Xavier Antoviaque

Allow editing of mentoring XML content from Studio

parent 5a5f3632
......@@ -27,6 +27,7 @@ import logging
from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String
from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren
from .message import MentoringMessageBlock
......@@ -63,7 +64,6 @@ class MentoringBlock(XBlockWithLightChildren):
default=True, scope=Scope.content)
display_submit = Boolean(help="Allow to submit current block?", default=True, scope=Scope.content)
xml_content = String(help="XML content", default='', scope=Scope.content)
has_children = True
icon_class = 'problem'
def student_view(self, context):
......@@ -156,6 +156,30 @@ class MentoringBlock(XBlockWithLightChildren):
else:
return ''
def studio_view(self, context):
"""
Editing view in Studio
"""
fragment = Fragment()
fragment.add_content(render_template('templates/html/mentoring_edit.html', {
'self': self,
}))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring_edit.js'))
fragment.initialize_js('MentoringEditBlock')
return fragment
@XBlock.json_handler
def studio_submit(self, submissions, suffix=''):
log.info(u'Received submissions: {}'.format(submissions))
# TODO-MRQ: Add XML validation
self.xml_content = submissions['xml_content']
return {
'result': 'success',
}
@staticmethod
def workbench_scenarios():
"""
......
function MentoringEditBlock(runtime, element) {
$('.save-button').bind('click', function() {
var data = {
'xml_content': $('#mentoring-xml-content').val(),
};
var handlerUrl = runtime.handlerUrl(element, 'studio_submit');
$.post(handlerUrl, JSON.stringify(data)).complete(function() {
// TODO-MRQ: Error handling
window.location.reload(false);
});
});
}
<!-- TODO: Replace by default edit view once available in Studio -->
<div class="wrapper-comp-settings is-active" id="settings-tab">
<script id="metadata-editor-tpl" type="text/template">// JS crashes when empty //</script>
<ul class="list-input settings-list">
<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="mentoring-xml-content">XML content</label>
<input class="input setting-input" id="mentoring-xml-content" value="{{ self.xml_content }}" type="text">
</div>
<span class="tip setting-help">XML source of the mentoring block</span>
</li>
</ul>
</div>
<div class="row module-actions">
<a href="#" class="save-button action-primary action">Save</a>
<a href="#" class="cancel-button action-secondary action">Cancel</a>
</div>
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