Commit d51f127a by Chris Dodge

work-in-progress: As a problem author, I would like to be able to edit module metadata

parent 0a7dfca0
......@@ -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
......
......@@ -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...)
<%include file="metadata-edit.html" />
<section class="html-edit">
<textarea name="" class="edit-box" rows="8" cols="40">${data}</textarea>
</section>
<section class="metadata_edit">
<h3>Metadata</h3>
<ul>
% for keyname in metadata.keys():
<li>${keyname}: <input type='text' xmetadata_name='${keyname}' value='${metadata[keyname]}' size='60' /></li>
% endfor
</ul>
</section>
<%include file="metadata-edit.html" />
<section class="raw-edit">
<textarea name="" class="edit-box" rows="8" cols="40">${data | h}</textarea>
</section>
......@@ -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, ''),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment