//Instead of:
$('.tasks').click(function(e){ ... })
//do this
TasksController = MVC.Controller.extend('tasks',{
click: function(params){...}
}) TasksController = MVC.Controller.extend('tasks',{
".delete mouseover": function(params){ ... }
}) | Action | Format | Description |
|---|---|---|
| Event | [CSS] [change|click|...] | Matches standard DOM events |
| Subscribe | [OpenAjax.hub event] subscribe | Subscribes this action to OpenAjax hub. |
| Drag | [CSS] [dragstart|dragging|...] | Matches events on a dragged object |
| Drop | [CSS] [dropadd|dropover|...] | Matches events on a droppable object |
| EnterLeave | [CSS] [mouseenter|mouseleave.] | Similar to mouseover, mouseout, but handles nested elements. |
| Hover | [CSS] [hoverenter|hoverleave.] | Similar to mouseenter, but only gets called if the user stops on an element. |
| Lasso | [CSS] [lassostart|...] | Allows you to lasso elements. |
| Selectable | [CSS] [selectadd|...] | Matches events on elements that can be selected by the lasso. |
//matches <div id="file_manager"></div>
FileManagerController = MVC.Controller.extend('file_manager') //matches <div class="task"></div>
TasksController = MVC.Controller.extend('tasks') If you want to match events on an element with the id, add '#' to the start of your action. For example:
TasksController = MVC.Controller.extend('tasks',{
click : function(){ .. } //matches <div class="task"></div>
"# click" : function(){ .. } //matches <div id="tasks"></div>
}) A flag if controllers can respond to events.
dispatch(action_name, params) -> undefined
{String} - The name of the action to be called.
{Controller.Params} - The params the action will be called with.
init() -> undefined
The name of the model this controller can uses for param functions like element_instance
_get_history_point(options) -> undefined
{Object} - an object that will turned into history point
continue_to(action) -> Function
Controller('todos',{
"a click" : function(params){
this.element = params.element;
this.element.innerHTML = 'deleting ...';
new Ajax('delete', {onComplete: this.continue_to('deleted')}
},
deleted : function(response){
this.element.parentNode.removeChild(this.element);
}
});{String} - Name of prototype function you want called
{Function} - function that when called, directs to another controller function
delay(delay, action_name, params) -> undefined
{Object} -
{Object} -
{Object} -
history_add(options, data) -> undefined
{Object} - an object that will turned into a url like #controller/action¶m1=value1
{Object} - extra data saved in history
path() -> undefined
path_data() -> undefined
publish(message, data) -> undefined
{String} -
{Object} -
redirect_to(options) -> undefined
{Object} - an object that will turned into a url like #controller/action¶m1=value1
render(options) -> String
TasksController = MVC.Controller.extend('tasks',{
click : function(params){
this.data = "Hello_world" // can display with <%= data %>
this.render({after: params.element, action: "under"}) // renders with views/tasks/under.ejs
this.render({to: "element_id"}) // renders with views/tasks/click.ejs
this.render({top: "another_e", partial: "bee/sugar")) // renders with views/bee/_sugar.ejs
}
}){Object} - A hash with the following properties
| Option | Default | Description |
|---|---|---|
| action | null | If present, looks for a template in app/views/controller_name/action.ejs |
| partial | null | A string value that looks like: 'folder/template' or 'template'. If a folder is present, it looks for a template in app/views/folder/_template.ejs; otherwise, it looks for a template in app/views/controller_name/template.ejs. |
| to | null | If present, a HTMLElement or element ID whose text will be replaced by the render. |
| before, after, top, bottom | null | If present, the content will be placed relative to the HTMLElement or element ID. The dom/element plugin is required for this functionality. |
| text | null | Instead of using a view to generate text, it uses the text as the rendered text. |
| using | null | If present, renders with the data in using instead of the controller instance. This is important for stateful controllers. |
{String} - the result of the render.