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

@@ -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 {}