diff --git a/cms/envs/common.py b/cms/envs/common.py index b2e15a9eba..250a053da5 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -685,6 +685,7 @@ ADVANCED_COMPONENT_TYPES = [ 'done', # Lets students mark things as done. See https://github.com/pmitros/DoneXBlock 'audio', # Embed an audio file. See https://github.com/pmitros/AudioXBlock 'recommender', # Crowdsourced recommender. Prototype by dli&pmitros. Intended for roll-out in one place in one course. + 'profile', # Prototype user profile XBlock. Used to test XBlock parameter passing. See https://github.com/pmitros/ProfileXBlock 'split_test', 'combinedopenended', 'peergrading', diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py index 5f79014847..6edb621317 100644 --- a/common/djangoapps/xmodule_modifiers.py +++ b/common/djangoapps/xmodule_modifiers.py @@ -101,6 +101,13 @@ def wrap_xblock(runtime_class, block, view, frag, context, usage_id_serializer, for key, value in data.iteritems()), } + if hasattr(frag, 'json_init_args') and frag.json_init_args is not None: + template_context['js_init_parameters'] = json.dumps(frag.json_init_args) + template_context['js_pass_parameters'] = True + else: + template_context['js_init_parameters'] = "" + template_context['js_pass_parameters'] = False + return wrap_fragment(frag, render_to_string('xblock_wrapper.html', template_context)) diff --git a/common/static/coffee/src/xblock/core.coffee b/common/static/coffee/src/xblock/core.coffee index 41f99f31b4..885d9af599 100644 --- a/common/static/coffee/src/xblock/core.coffee +++ b/common/static/coffee/src/xblock/core.coffee @@ -18,7 +18,14 @@ if runtime? and version? and initFnName? runtime = new window[runtime]["v#{version}"] initFn = window[initFnName] - block = initFn(runtime, element) ? {} + if initFn.length > 2 + initargs = $(".xblock_json_init_args", element) + if initargs.length == 0 + console.log("Warning: XBlock expects data parameters") + data = JSON.parse(initargs.text()) + block = initFn(runtime, element, data) ? {} + else + block = initFn(runtime, element) ? {} block.runtime = runtime else elementTag = $('