work-in-progress: As a problem author, I would like to be able to edit module metadata
This commit is contained in:
@@ -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...)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<%include file="metadata-edit.html" />
|
||||
<section class="html-edit">
|
||||
<textarea name="" class="edit-box" rows="8" cols="40">${data}</textarea>
|
||||
</section>
|
||||
|
||||
8
cms/templates/widgets/metadata-edit.html
Normal file
8
cms/templates/widgets/metadata-edit.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<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>
|
||||
@@ -1,3 +1,4 @@
|
||||
<%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, ''),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user