Class: Wraith.Controller
Defined in: | src/controller.coffee |
Inherits: | Wraith.BaseView |
Overview
The proverbial 'controller' in the MVC pattern. The Controller handles the logic your applications or components may have. This controller handles automatical registration and mapping of models to views.
Examples:
Example markup in HTML.
This will create a SelectList controller
and then create a view using the template with id "ListItem"
mapping to the model list.items (belonging to SelectList)
<ul data-view="SelectList">
<div data-template="ListItem" data-map="list.items"></div>
</ul>
Instance Method Summary
- - (void) constructor($el) Constructor Initializes a few private variables and sets the data-id attribute to a uniquely generated id.
- - (void) init() Initialize the controller by loading the views and elements with id tags.
- - (void) loadElements() Load our elements with id attributes into an object that is accesible at the controller level.
- - (void) loadViews() Find all the views embedded inside the controller and register them with the controller
- - (void) registerView($view, twoWay) Register the view to this controller
- - (Wraith.Model) registerModel(model, as) Register the model to this controller
- - (void) bindViews(name, model) Binds any view that is loaded into the controller to the given model.
- - (void) bindView(model, binding, view, twoWay) Binds a single instance of a view to a model.
- - (void) bindModelView(model, view) Bind a model to a view and bind the view to the model (used for two-way model-view binding)
- - (void) unbindModelView(model, view) Unbind a two-way model-view relationship.
- - (void) handleUIEvent(e, cb) Bound Handles the UI event which is mapped from the DOM to the controller.
- - (void) handleViewUIEvent(e, cb) Bound This is a wrapper for any UI event happening on views in this controller.
- - (Wraith.Model) getModelFromEl($el) Bound Traverses the dom upwards to find the first model it encounters If no model is found, it will return null
- - (void) getInputDataFromEl($el) Retrieve the input data from a given element
Inherited Method Summary
Methods inherited from Wraith.BaseView
#constructor, #bindUIEvents, #bindUIEvent, #wrapUIEvent, #handleUIEvent, #unbindUIEvents, #unbindUIEvent, #applyViewUpdate, #updateAttribute
Methods inherited from Wraith.Base
#constructor, #bind, #unbind, #emit, #proxy
Constructor Details
- (void) constructor($el)
Initializes a few private variables and sets the data-id attribute to a uniquely generated id.
Instance Method Details
- (void) init()
Initialize the controller by loading the views and elements with id tags. Also binds UI events to the controllers' respective callbacks
- (void) loadElements()
Load our elements with id attributes into an object that is accesible at the controller level. This makes it easier to access discrete DOM objects within the controller via @els['el-id']
- (void) loadViews()
Find all the views embedded inside the controller and register them with the controller
- (void) registerView($view, twoWay)
Register the view to this controller
- (Wraith.Model) registerModel(model, as)
Register the model to this controller
- (void) bindViews(name, model)
Binds any view that is loaded into the controller to the given model.
- (void) bindView(model, binding, view, twoWay)
Binds a single instance of a view to a model. Usings binding as the dot notation map.
- (void) bindModelView(model, view)
Bind a model to a view and bind the view to the model (used for two-way model-view binding)
- (void) unbindModelView(model, view)
Unbind a two-way model-view relationship.
- (void) handleUIEvent(e, cb) (bound)
Handles the UI event which is mapped from the DOM to the controller.
- (void) handleViewUIEvent(e, cb) (bound)
This is a wrapper for any UI event happening on views in this controller. We do this so we can do a lookup of the model and pass it through with the event
- (Wraith.Model) getModelFromEl($el) (bound)
Traverses the dom upwards to find the first model it encounters If no model is found, it will return null
- (void) getInputDataFromEl($el)
Retrieve the input data from a given element