From 1cd81a2a4fd6db9c46c0cc697e14470c5bd6b998 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 21 Sep 2012 09:14:28 -0400 Subject: [PATCH] work-in-progress: As a problem author, I would like to be able to edit module metadata --- cms/djangoapps/contentstore/views.py | 6 ++++++ cms/static/coffee/src/models/module.coffee | 12 ++++++++++++ cms/templates/widgets/html-edit.html | 1 + cms/templates/widgets/metadata-edit.html | 8 ++++++++ cms/templates/widgets/raw-edit.html | 1 + common/lib/xmodule/xmodule/editing_module.py | 1 + 6 files changed, 29 insertions(+) create mode 100644 cms/templates/widgets/metadata-edit.html diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 505b897497..bffadcf666 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -110,6 +110,7 @@ def edit_item(request): 'category': item.category, 'url_name': item.url_name, 'previews': get_module_previews(request, item), + 'metadata': item.metadata }) @@ -279,6 +280,11 @@ def save_item(request): data = json.loads(request.POST['data']) modulestore().update_item(item_location, data) + # cdodge: also commit any metadata which might have been passed along in the + # POST from the client + if request.POST['metadata']: + modulestore().update_metadata(item_location, request.POST['metadata']) + # Export the course back to github # This uses wildcarding to find the course, which requires handling # multiple courses returned, but there should only ever be one diff --git a/cms/static/coffee/src/models/module.coffee b/cms/static/coffee/src/models/module.coffee index 159172e852..b1bbb3bb72 100644 --- a/cms/static/coffee/src/models/module.coffee +++ b/cms/static/coffee/src/models/module.coffee @@ -2,14 +2,26 @@ class CMS.Models.Module extends Backbone.Model url: '/save_item' defaults: data: '' + metadata: {} loadModule: (element) -> elt = $(element).find('.xmodule_edit').first() @module = XModule.loadModule(elt) + # find the metadata edit region which should be setup server side, + # so that we can wire up posting back those changes + @metadata_elt = $(element).find('.metadata_edit') editUrl: -> "/edit_item?#{$.param(id: @get('id'))}" save: (args...) -> @set(data: JSON.stringify(@module.save())) if @module + # cdodge: package up metadata which is separated into a number of input fields + # there's probably a better way to do this, but at least this lets me continue to move onwards + if @metadata_elt + _metadata = {} + # walk through the set of elments which have the 'xmetadata_name' attribute and + # build up a object to pass back to the server on the subsequent POST + _metadata[el.getAttribute("xmetadata_name")]=el.value for el in $('[xmetadata_name]') + @set(metadata: _metadata) super(args...) diff --git a/cms/templates/widgets/html-edit.html b/cms/templates/widgets/html-edit.html index 1e86c6c734..9f7196b6e4 100644 --- a/cms/templates/widgets/html-edit.html +++ b/cms/templates/widgets/html-edit.html @@ -1,3 +1,4 @@ +<%include file="metadata-edit.html" />
diff --git a/cms/templates/widgets/metadata-edit.html b/cms/templates/widgets/metadata-edit.html new file mode 100644 index 0000000000..a130436e37 --- /dev/null +++ b/cms/templates/widgets/metadata-edit.html @@ -0,0 +1,8 @@ +
+

Metadata

+ +
diff --git a/cms/templates/widgets/raw-edit.html b/cms/templates/widgets/raw-edit.html index fbd1757be5..9488552be5 100644 --- a/cms/templates/widgets/raw-edit.html +++ b/cms/templates/widgets/raw-edit.html @@ -1,3 +1,4 @@ +<%include file="metadata-edit.html" />
diff --git a/common/lib/xmodule/xmodule/editing_module.py b/common/lib/xmodule/xmodule/editing_module.py index 67a4d66dad..c562617c98 100644 --- a/common/lib/xmodule/xmodule/editing_module.py +++ b/common/lib/xmodule/xmodule/editing_module.py @@ -21,6 +21,7 @@ class EditingDescriptor(MakoModuleDescriptor): return { 'module': self, 'data': self.definition.get('data', ''), + 'metadata': self.metadata # TODO (vshnayder): allow children and metadata to be edited. #'children' : self.definition.get('children, ''),