From d51f127afa6db598b8065fde650322cbec4142e3 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 6f428ee3e8..14a11a2db1 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 }) @@ -284,6 +285,11 @@ def save_item(request): children = request.POST['children'] modulestore().update_children(item_location, children) + # 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 e2f911e9bd..4e1a926445 100644 --- a/cms/static/coffee/src/models/module.coffee +++ b/cms/static/coffee/src/models/module.coffee @@ -3,14 +3,26 @@ class CMS.Models.Module extends Backbone.Model defaults: data: '' children: '' + 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: @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, ''),