Make editing work, building towards drag/drop saving

This commit is contained in:
Calen Pennington
2012-09-27 15:01:48 -04:00
parent b91c2b6680
commit fd7223bd87
11 changed files with 93 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
class @InlineDiscussion
class @InlineDiscussion extends XModule.Descriptor
constructor: (element) ->
@el = $(element).find('.discussion-module')
@view = new DiscussionModuleView(el: @el)

View File

@@ -1,7 +1,8 @@
class @JSONEditingDescriptor
class @JSONEditingDescriptor extends XModule.Descriptor
constructor: (@element) ->
@edit_box = CodeMirror.fromTextArea($(".edit-box", @element)[0], {
mode: { name: "javascript", json: true }
})
save: -> JSON.parse @edit_box.getValue()
save: ->
data: JSON.parse @edit_box.getValue()

View File

@@ -1,7 +1,8 @@
class @XMLEditingDescriptor
class @XMLEditingDescriptor extends XModule.Descriptor
constructor: (@element) ->
@edit_box = CodeMirror.fromTextArea($(".edit-box", @element)[0], {
mode: "xml"
})
save: -> @edit_box.getValue()
save: ->
data: @edit_box.getValue()

View File

@@ -1,4 +1,4 @@
class @SequenceDescriptor
class @SequenceDescriptor extends XModule.Descriptor
constructor: (@element) ->
@$tabs = $(@element).find("#sequence-list")
@$tabs.sortable()

View File

@@ -1,4 +1,4 @@
class @VerticalDescriptor
class @VerticalDescriptor extends XModule.Descriptor
constructor: (@element) ->
@$items = $(@element).find(".vert-mod")
@$items.sortable()

View File

@@ -86,6 +86,7 @@ class SequenceModule(XModule):
'progress_status': Progress.to_js_status_str(progress),
'progress_detail': Progress.to_js_detail_str(progress),
'type': child.get_icon_class(),
'id': child.id,
}
if childinfo['title']=='':
childinfo['title'] = child.metadata.get('display_name','')

View File

@@ -10,8 +10,13 @@
return
try
$(element).data('module', new window[moduleType](element))
$(document).trigger('XModule.loaded', [element])
module = new window[moduleType](element)
if $(element).hasClass('xmodule_edit')
$(document).trigger('XModule.loaded.edit', [element, module])
if $(element).hasClass('xmodule_display')
$(document).trigger('XModule.loaded.display', [element, module])
catch error
console.error "Unable to load #{moduleType}: #{error.message}" if console
@@ -29,3 +34,40 @@
modules = $(selector)
modules.each (idx, element) -> XModule.loadModule element
class @XModule.Descriptor
callbacks: []
###
Register a callback method to be called when the state of this
descriptor is updated. The callback will be passed the results
of calling the save method on this descriptor.
###
onUpdate: (callback) ->
@callbacks.push(callback)
###
Notify registered callbacks that the state of this descriptor has changed
###
update: =>
data = @save()
callback(data) for callback in @callbacks
###
Bind the module to an element. This may be called multiple times,
if the element content has changed and so the module needs to be rebound
@method: constructor
@param {html element} the .xmodule_edit section containing all of the descriptor content
###
constructor: (@element) -> return
###
Return the current state of the descriptor (to be written to the module store)
@method: save
@returns {object} An object containing children and data attributes (both optional).
The contents of the attributes will be saved to the server
###
save: -> return {}