Controller

An abstract class used in implementing Mojo Controllers.  A Controller is an object that encapsulates all event handling, Command managing and dispatching and intercepting in a Mojo application.

Example

dojo.provide("sample.controller.ProfileController");
dojo.require("mojo.controller.Controller");

dojo.declare("sample.controller.ProfileController", mojo.controller.Controller,
{
addObservers: function() {
this.addObserver(this, "onInit", "GetProfile");
// add more observers ...
},
addCommands: function() {
this.addCommand("GetProfile", "sampleApplication.command.profile.GetProfileCommand");
// add more commands ...
},
addIntercepts: function() {
// add more intercepts ...
}
});
Summary
An abstract class used in implementing Mojo Controllers.
Returns the specified configuration object.
Returns the value of the specified parameter.
Sets the value of the specified parameter.
Returns a Controller instance that is in the same context as the current Controller.
Returns the DOM context of the Controller.
This event fires when the Controller is first initialized.
Abstract function fired on instantiation of concrete implementation of Controller class.
Removes all observers associated with the Controller.
Defines and adds an observer to the Controller.
Abstract function fired on instantiation of concrete implementation of Controller class.
Adds a command object to a Controller’s command registry.
Retrieves the first command associated with the reference name.
Retrieves a set of Mojo Command Objects based on a specified command name.
Executes all Command instances associated with the command name.
Abstract function fired on instantiation of concrete implementation of Controller class.
Adds an intercept to inject a Command before, after or around another Command when it has been triggered.
Static function.

Functions

getConfig

getConfig: function(configName)

Returns the specified configuration object.

Parameters

configName{string}

Returns

{object} configObj

getValue

getValue: function(paramName)

Returns the value of the specified parameter.

Parameters

paramName{string}

Returns

{object} value

setValue

setValue: function(paramName,
value)

Sets the value of the specified parameter.

Parameters

paramName{string}
value{object}

getContextController

getContextController: function(controllerName)

Returns a Controller instance that is in the same context as the current Controller.

Parameters

controllerName{string}

Returns

{mojo.controller.Controller} contextControllerObj

getContextElement

getContextElement: function()

Returns the DOM context of the Controller.

Returns

{DOMElement} contextElementObj

Events

onInit

This event fires when the Controller is first initialized.

Functions

addObservers

addObservers: function()

Abstract function fired on instantiation of concrete implementation of Controller class.  Used as container function for adding observers.

Example

// see above for sample implementation usage

removeObserver

removeObservers: function()

Removes all observers associated with the Controller.

addObserver

addObserver: function(srcObj,
srcFunc,
cmdName,
paramsObj)

Defines and adds an observer to the Controller.

Parameters

srcObj{object}
srcFunc{string}
cmdName{string}
paramsObj{object|function}

Example

// observing an button, and firing a message onclick
this.addObserver("#button", "onclick", "Messaging", function(context, caller) { return {
topic: "hello", message: {from: caller}
}});

addCommands

addCommands: function()

Abstract function fired on instantiation of concrete implementation of Controller class.  Used as container function for adding commands.

Parameters

cmdName{string}
cmdObjPath{string}

Example

//See above for sample implementation usage.

addCommand

addCommand: function(cmdName,
cmdObjPath)

Adds a command object to a Controller’s command registry.  Commands are referenced via a reference name.  A single name can be associated with multiple Commands.

Parameters

cmdName{string}
cmdObjPath{string}

getCommand

getCommand: function(cmdName)

Retrieves the first command associated with the reference name.

Parameters

cmdName{string}

Returns

{string} Command Name

Example

// observing a function in a Command
this.addObserver(this.getCommand("GetProfile"), "onResponse", "ProfileCompleted");

getCommandChain

getCommandChain: function(cmdName)

Retrieves a set of Mojo Command Objects based on a specified command name.

Parameters

cmdName{string}

Returns

{object array} Array of Mojo Command Objects

fireCommandChain

fireCommandChain: function(cmdName,
requestObj)

Executes all Command instances associated with the command name.

Parameters

cmdName{string}
requestObj{mojo.controller.Request}

addIntercepts

addIntercepts: function()

Abstract function fired on instantiation of concrete implementation of Controller class.  Used as a container for adding intercepts.

Parameters

interceptType{string} Supports Intercepting “before|after|around”.
interceptCmdName{string} The reference name of the Command to intercept.
cmdName{string} The reference name of the Command to inject when intercepting.
paramsObj{object|function} Optional parameters to send via the Command request.

Example

// inside a controller implementation
//...
addIntercepts: function() {
// intercept the UpdateProfile Command, and Validate it before it fires
this.addIntercept("around", "UpdateProfile", "ValidateProfile", function() { return {
formSet: mojo.queryFirst("#profile-form")
}});
//...

addIntercept

addIntercept: function(interceptType,
interceptCmdName,
cmdName,
paramsObj)

Adds an intercept to inject a Command before, after or around another Command when it has been triggered.

Parameters

interceptType{string} Supports Intercepting “before|after|around”.
interceptCmdName{string} The reference name of the Command to intercept.
cmdName{string} The reference name of the Command to inject when intercepting.
paramsObj{object|function} Optional parameters to send via the Command request.

Example

// inside a controller implementation
//...
addIntercepts: function() {
// intercept the UpdateProfile Command, and Validate it before it fires
this.addIntercept("around", "UpdateProfile", "ValidateProfile", function() { return {
formSet: mojo.queryFirst("#profile-form")
}});
//..

updateObservers

mojo.controller.Controller.updateObservers = function(controllerName)

Static function.  Re-adds all observers for a particular Controller.  If no Controller is specified, all Controllers in application are updated.

Parameters

controllerName{string} (optional)

Example

// update all observers for all controllers
mojo.controller.Controller.updateObservers();
getConfig: function(configName)
Returns the specified configuration object.
getValue: function(paramName)
Returns the value of the specified parameter.
setValue: function(paramName,
value)
Sets the value of the specified parameter.
getContextController: function(controllerName)
Returns a Controller instance that is in the same context as the current Controller.
getContextElement: function()
Returns the DOM context of the Controller.
addObservers: function()
Abstract function fired on instantiation of concrete implementation of Controller class.
removeObservers: function()
Removes all observers associated with the Controller.
addObserver: function(srcObj,
srcFunc,
cmdName,
paramsObj)
Defines and adds an observer to the Controller.
addCommands: function()
Abstract function fired on instantiation of concrete implementation of Controller class.
addCommand: function(cmdName,
cmdObjPath)
Adds a command object to a Controller’s command registry.
getCommand: function(cmdName)
Retrieves the first command associated with the reference name.
getCommandChain: function(cmdName)
Retrieves a set of Mojo Command Objects based on a specified command name.
fireCommandChain: function(cmdName,
requestObj)
Executes all Command instances associated with the command name.
addIntercepts: function()
Abstract function fired on instantiation of concrete implementation of Controller class.
addIntercept: function(interceptType,
interceptCmdName,
cmdName,
paramsObj)
Adds an intercept to inject a Command before, after or around another Command when it has been triggered.
mojo.controller.Controller.updateObservers = function(controllerName)
Static function.