Call js module name dynamically, rather than statically calling the HTML module
This commit is contained in:
@@ -17,4 +17,7 @@ def index(request):
|
||||
def edit_item(request):
|
||||
item_id = request.GET['id']
|
||||
item = keystore().get_item(item_id)
|
||||
return HttpResponse(item.get_html())
|
||||
return render_to_response('unit.html', {
|
||||
'contents': item.get_html(),
|
||||
'type': item.type,
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ edit_item = (id) ->
|
||||
bind_edit_links()
|
||||
$('section.edit-pane').show()
|
||||
$('body').addClass('content')
|
||||
window['construct_html']('module-html')
|
||||
new window[$('#unit-wrapper').attr('class')] 'module-html'
|
||||
)
|
||||
|
||||
$ ->
|
||||
|
||||
3
cms/templates/unit.html
Normal file
3
cms/templates/unit.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<div id="unit-wrapper" class="${type}">
|
||||
${contents}
|
||||
</div>
|
||||
@@ -4,6 +4,7 @@ import logging
|
||||
from x_module import XModule
|
||||
from mako_module import MakoModuleDescriptor
|
||||
from lxml import etree
|
||||
from pkg_resources import resource_string
|
||||
|
||||
log = logging.getLogger("mitx.courseware")
|
||||
|
||||
@@ -16,12 +17,7 @@ class HtmlModuleDescriptor(MakoModuleDescriptor):
|
||||
mako_template = "widgets/html-edit.html"
|
||||
|
||||
# TODO (cpennington): Make this into a proper module
|
||||
js = {'coffee': ["""
|
||||
window.construct_html = (id) ->
|
||||
$('#' + id + " #edit-box").on('input', ->
|
||||
$('#' + id + ' #edit-preview').empty().append($(this).val())
|
||||
)
|
||||
"""]}
|
||||
js = {'coffee': [resource_string(__name__, 'js/module/html.coffee')]}
|
||||
|
||||
|
||||
class Module(XModule):
|
||||
|
||||
5
common/lib/xmodule/js/module/html.coffee
Normal file
5
common/lib/xmodule/js/module/html.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
class @HTML
|
||||
constructor: (id) ->
|
||||
$('#' + id + " #edit-box").on('input', ->
|
||||
$('#' + id + ' #edit-preview').empty().append($(this).val())
|
||||
)
|
||||
@@ -5,6 +5,9 @@ setup(
|
||||
version="0.1",
|
||||
packages=find_packages(),
|
||||
install_requires=['distribute'],
|
||||
package_data={
|
||||
'': ['js/*']
|
||||
},
|
||||
|
||||
# See http://guide.python-distribute.org/creation.html#entry-points
|
||||
# for a description of entry_points
|
||||
|
||||
Reference in New Issue
Block a user