From 17a4d7fd093aa09b7c43b390b6adbd1f76b673d8 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 22 Jun 2012 08:59:53 -0400 Subject: [PATCH] Call js module name dynamically, rather than statically calling the HTML module --- cms/djangoapps/contentstore/views.py | 5 ++++- cms/static/coffee/main.coffee | 2 +- cms/templates/unit.html | 3 +++ common/lib/xmodule/html_module.py | 8 ++------ common/lib/xmodule/js/module/html.coffee | 5 +++++ common/lib/xmodule/setup.py | 3 +++ 6 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 cms/templates/unit.html create mode 100644 common/lib/xmodule/js/module/html.coffee diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index b8667da156..138b7434a8 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -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, + }) diff --git a/cms/static/coffee/main.coffee b/cms/static/coffee/main.coffee index 142e8c7089..b74cd3c7d3 100644 --- a/cms/static/coffee/main.coffee +++ b/cms/static/coffee/main.coffee @@ -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' ) $ -> diff --git a/cms/templates/unit.html b/cms/templates/unit.html new file mode 100644 index 0000000000..0ce973bb9e --- /dev/null +++ b/cms/templates/unit.html @@ -0,0 +1,3 @@ +
+ ${contents} +
diff --git a/common/lib/xmodule/html_module.py b/common/lib/xmodule/html_module.py index 17d60c731c..977b5ef606 100644 --- a/common/lib/xmodule/html_module.py +++ b/common/lib/xmodule/html_module.py @@ -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): diff --git a/common/lib/xmodule/js/module/html.coffee b/common/lib/xmodule/js/module/html.coffee new file mode 100644 index 0000000000..47c6084837 --- /dev/null +++ b/common/lib/xmodule/js/module/html.coffee @@ -0,0 +1,5 @@ +class @HTML + constructor: (id) -> + $('#' + id + " #edit-box").on('input', -> + $('#' + id + ' #edit-preview').empty().append($(this).val()) + ) diff --git a/common/lib/xmodule/setup.py b/common/lib/xmodule/setup.py index 48af72479c..7b67029f34 100644 --- a/common/lib/xmodule/setup.py +++ b/common/lib/xmodule/setup.py @@ -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