Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (28 sloc) 1.36 KB
template = require './templates/inspector'
error_reporter = { error: -> alert("Failed to load or save. Please make sure the Express server is running.\nResponse: #{JSON.stringify(arguments)}") }
class MyModel extends Backbone.Articulation.Model
@factory: (attributes={}) -> return new MyModel(_.defaults(attributes, {id: _.uniqueId('id'), name: _.uniqueId('name'), created_at: new Date()}))
class MyCollection extends Backbone.Articulation.Collection
model: MyModel
class InspectorViewModel
constructor: (collection) ->
@target = kb.collectionObservable(collection, {view_model: kb.ViewModel})
@is_open = ko.observable(false)
@save = (vm, event) => # make sure any input fields have been transferred to the models before save, error_reporter) for model in @target.collection().models
# expose the interface
@toggle = => @is_open(!@is_open())
@open = => @is_open(true)
@close = => @is_open(false)
module.exports = class InspectorDialog
render: ->
collection = new MyCollection()
collection.url = 'http://localhost:3000/models'
@view_model = new InspectorViewModel(collection)
@el = $(template())
ko.applyBindings(@view_model, @el[0])
# expose the view model interface
_.extend(@, _.pick(@view_model, 'toggle', 'open', 'close'))
Something went wrong with that request. Please try again.