Commit 6d5fbc0b by Chris Dodge

work in progress

parent c52c61ff
......@@ -679,6 +679,9 @@ def clone_item(request):
parent_location = Location(request.POST['parent_location'])
template = Location(request.POST['template'])
data = request.POST.get('data')
metadata = None
if 'metadata' in request.POST and len(request.POST['metadata']) > 0:
metadata = json.loads(request.POST.get('metadata'))
display_name = request.POST.get('display_name')
......@@ -693,6 +696,9 @@ def clone_item(request):
# TODO: This needs to be deleted when we have proper storage for static content
new_item.metadata['data_dir'] = parent.metadata['data_dir']
if metadata is not None:
new_item.metadata.update(metadata)
# replace the display name with an optional parameter passed in from the caller
if display_name is not None:
new_item.metadata['display_name'] = display_name
......@@ -700,7 +706,6 @@ def clone_item(request):
_modulestore(template).update_metadata(new_item.location.url(), new_item.own_metadata)
# seed any initial content, if passed by caller
logging.debug('data = {0}'.format(data))
if data is not None:
_modulestore(template).update_item(new_item.location.url(), data)
......@@ -950,9 +955,7 @@ def assets(request, location):
display_info['thumb_url'] = StaticContent.get_url_path_from_location(thumbnail_location) if thumbnail_location is not None else None
display_info['markup'] = "<img src='{0}' />".format(display_info['url'])
asset_display.append(display_info)
logging.debug("assets = {0}".format(asset_display))
return HttpResponse(json.dumps(asset_display))
......
class LibraryEntry extends Backbone.Model
# declare the basic schema of this model
defaults:
id: null
thumb_url: null
......@@ -8,24 +9,31 @@ class LibraryEntry extends Backbone.Model
markup: null
mime_type: null
# this is the collection of assets
class LibraryCollection extends Backbone.Collection
url: '/assets/'
model: LibraryEntry
initialize: (course_location) ->
# the collection fetch url is /assets/<location
@url = @url + course_location
# this is the main Backbone View which encompasses the entire
# asset window
class CMS.Views.AssetWidget extends Backbone.View
initialize: ->
# the editor is passed in by the caller, we need this so we can inject content into it
# when we pick the asset to insert
@editor = @options.editor
# This subview covers the list of assets
@library = new CMS.Views.AssetWidget.Library(
el: @$('.library')
model: @model
assetWidget: @
)
# this subview covers the upload form
@uploadForm = new CMS.Views.AssetWidget.UploadForm(
el: @$('.upload-form')
model: @model
......
......@@ -35,11 +35,12 @@ class CMS.Views.ModuleEdit extends Backbone.View
return _metadata
cloneTemplate: (parent, template, content) ->
cloneTemplate: (parent, template, content, _metadata) ->
$.post("/clone_item", {
parent_location: parent
template: template
data: content
metadata: JSON.stringify(_metadata)
}, (data) =>
@model.set(id: data.id)
@$el.data('id', data.id)
......
class CMS.Views.ModuleSpeedEdit extends CMS.Views.ModuleEdit
events:
"click .component-actions .edit-button": 'clickEditButton'
"click .component-actions .delete-button": 'onDelete'
initialize: ->
@onDelete = @options.onDelete
@parent = @options.parent
super(@options)
clickEditButton: ->
@enterEditMode()
enterEditMode: ->
@$editorEl = $($('#problem-editor').html())
# Toggle our class
@$el.addClass('editing')
# We put the editor dialog in a separate Backbone view
@$editor = new CMS.Views.SpeedEditor(
el: @$editorEl
widget: @ # pass along a callback
parent: @parent
model: @model
)
$componentActions = $($('#component-actions').html())
@$el.append(@$editorEl)
@$el.append($componentActions)
@$el.show()
# $modalCover is defined in base.js
$modalCover.fadeIn(200)
onCloseEditor: ->
@exitEditMode()
@$el.remove()
onSaveEditor: ->
# note, we need to nest the whole XML inside a <problem></problem>
xml = '<problem>\n'+getXMLContent()+'</problem>'
metadata = {'markdown_source': getMarkdownContent()}
if not @model.id
@cloneTemplate(
@options.parent,
'i4x://edx/templates/problem/Empty',
xml,
metadata
)
@exitEditMode()
else
data =
data: xml
@model.save(data).done( ->
@exitEditMode()
).fail( =>
showToastMessage("There was an error saving your changes. Please try again.", null, 3)
)
exitEditMode: ->
$modalCover.fadeOut(150)
@$editorEl.remove()
@$el.removeClass('editing')
class CMS.Views.SpeedEditor extends Backbone.View
events:
"click .cancel-button": 'closeEditor'
"click .save-button": 'saveEditor'
initialize: ->
@$preview = $($('#problem-preview').html())
initProblemEditors(@$el, @$preview)
@$el.append(@$preview)
closeEditor: (event) ->
@$el.slideUp(150)
if @options.widget
@options.widget.onCloseEditor()
saveEditor: (event) ->
if @options.widget
@options.widget.onSaveEditor()
......@@ -92,9 +92,20 @@ class CMS.Views.UnitEdit extends Backbone.View
@$editor = $($('#video-editor').html())
$preview = $($('#video-preview').html())
when 'problem'
@$editor = $($('#problem-editor').html())
$preview = $($('#problem-preview').html())
initProblemEditors(@$editor, $preview)
parent = @$el.data('id')
$editView = $('<li>').addClass('component')
@$newComponentItem.before($editView)
@speedEditor = new CMS.Views.ModuleSpeedEdit(
el: $editView
onDelete: @deleteComponent
parent: parent
model: new CMS.Models.Module(
course_location: @model.get('course_location')
)
)
@speedEditor.enterEditMode()
return
when 'html'
$editView = $('<li>').addClass('component')
@$newComponentItem.before($editView)
......
......@@ -428,4 +428,12 @@ function onKeyboard(e) {
}
break;
}
}
\ No newline at end of file
}
function getXMLContent() {
return xmlEditor.getValue();
}
function getMarkdownContent() {
return simpleEditor.getValue();
}
---
metadata:
display_name: Empty
data: ""
children: []
---
metadata:
display_name: Empty
data: ""
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