new (require("bajaux/commands/ToggleCommand"))(paramsopt)
- Description:
A ToggleCommand adds an additional state variable allowing it to be
turned on or off. If no function is specified in the Constructor, the default
behavior is to simply call 'toggle'.
- Source:
Extends:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
<optional> |
all parameters compatible with module:bajaux/commands/Command Properties
|
Extends
Methods
defaultNotifyUser(err, paramsopt) → {Promise}
- Description:
Provides a default way of notifying the user about a Command invocation
failure. Shows a dialog with details about the error.You might override this at runtime with your own error dialog handler.
- Source:
- Since:
- Niagara 4.12
- Inherited From:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
err |
Error | * | ||||||||||
params |
object |
<optional> |
Properties
|
Returns:
- Type
- Promise
getAccelerator() → {Object}
- Description:
Return the accelerator for the Command or null if
nothing is defined.
- Source:
- Inherited From:
- See:
Returns:
The accelerator or null if nothing is defined.
- Type
- Object
getDescriptionFormat() → {String}
- Description:
Get the unformatted description of the command.
- Source:
- Inherited From:
Returns:
- Type
- String
getDisplayNameFormat() → {String}
- Description:
Return the format display name of the command.
- Source:
- Inherited From:
Returns:
- Type
- String
getFlags() → {Number}
- Description:
Get this command's flags.
- Source:
- Inherited From:
Returns:
- Type
- Number
getFunction() → {function}
- Description:
Return the raw function associated with this command.
- Source:
- Inherited From:
Returns:
- Type
- function
getIcon() → {String}
- Description:
Return the Command's icon URI
- Source:
- Inherited From:
Returns:
- Type
- String
getId()
- Description:
Return a unique numerical id for the Command.
This is id unique to every Command object created.
- Source:
- Inherited From:
hasFlags(flags) → {Boolean}
- Description:
Check to see if this command's flags match any of the bits of the
input flags.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
flags |
Number | The flags to check against |
Returns:
- Type
- Boolean
invoke() → {Promise}
- Description:
Invoke the Command. Triggers a
bajaux:invokecommandor
bajaux:failcommandevent, as appropriate.Arguments can be passed into
invoke()that will be passed into the
function's Command Handler.
- Source:
- Inherited From:
Returns:
A promise object that will be resolved (or rejected)
once the Command's function handler has finished invoking.
- Type
- Promise
invokeFromEvent(e) → {Promise|*}
- Description:
If your Command optionally implements this function, then CommandButton
will call it on click instead of simply callinginvoke. Use this in case
your Command needs to respond differently based on where on the screen the
user is pointing.
- Source:
- Since:
- Niagara 4.11
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
e |
JQuery.Event | the DOM event triggered by the user's request to |
Returns:
- Type
- Promise | *
isAcceleratorMatch(event) → {boolean}
- Description:
Check to see if a keyboard event matches the accelerator.
The keycode and the modifiers must match for this to return true.
The command must also be enabled for this accelerator to match.
- Source:
- Since:
- Niagara 4.15
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
event |
Event |
Returns:
- Type
- boolean
isCommand()
- Description:
Always returns true.
- Source:
- Inherited From:
isEnabled() → {Boolean}
- Description:
Gets this command's enabled status.
- Source:
- Inherited From:
Returns:
- Type
- Boolean
isLoading() → {Boolean}
- Description:
Return true if the Command is still loading.
- Source:
- Inherited From:
Returns:
true if still loading.
- Type
- Boolean
isSelected() → {Boolean}
- Description:
Gets this command's selected status.
- Source:
Returns:
- Type
- Boolean
isToggleCommand()
- Description:
Always returns true.
- Source:
- Overrides:
isUndoable() → {boolean}
- Source:
- Since:
- Niagara 4.11
- Inherited From:
Returns:
true if this command is undoable
- Type
- boolean
jq(jqDomopt) → {JQuery}
- Description:
If a jQuery DOM argument is specified, this will set the DOM.
If not specified then no DOM will be set.
This method will always return the jQuery DOM associated with this Command.
- Source:
- Inherited From:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
jqDom |
JQuery |
<optional> |
If specified, this will set the jQuery DOM. |
Returns:
A jQuery DOM object for firing events on.
- Type
- JQuery
loading() → {Promise}
- Description:
Return the loading promise for the Command.
The returned promise will be resolved once the Command
has finished loading.
- Source:
- Inherited From:
Returns:
The promise used for loading a Command.
- Type
- Promise
merge(cmd) → {module:bajaux/commands/Command}
- Description:
Attempt to merge this command with another command, and return a new
Command that does both tasks. If the two commands are mutually
incompatible, return a falsy value.
- Source:
- Inherited From:
Example
Here is an example to show the basic concept. Commands that simply add two numbers together can easily be merged together thanks to the associative property.
var AddCommand = function AddCommand(inc) {
this.$inc = inc;
Command.call(this, {
displayName: 'Add ' + inc + ' to the given number',
func: function (num) { return num + inc; }
});
};
AddCommand.prototype = Object.create(Command.prototype);
AddCommand.prototype.merge = function (cmd) {
if (cmd instanceof AddCommand) {
return new AddCommand(this.$inc + cmd.$inc);
}
};
var addOneCommand = new AddCommand(1),
addFiveCommand = new AddCommand(5),
addSixCommand = addOneCommand.merge(addFiveCommand);
addSixCommand.invoke(10)
.then(function (result) {
console.log('is 16? ', result === 16);
});
Parameters:
| Name | Type | Description |
|---|---|---|
cmd |
module:bajaux/commands/Command |
Returns:
off(eventopt, handleropt)
- Description:
Unregister a function callback handler for the specified event.
- Source:
- Inherited From:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
event |
String |
<optional> |
The name of the event to unregister. |
handler |
function |
<optional> |
The function to unregister. If |
on(event, handler)
- Description:
Register a function callback handler for the specified event.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
event |
String | The event id to register the function for. |
handler |
function | The event handler to be called when the event is fired. |
setAccelerator(acc)
- Description:
Set the accelerator information for the Command.
- Source:
- Inherited From:
- See:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
acc |
Object | String | Number | null | undefined | The accelerator keyboard information. This can Properties
|
setDescriptionFormat(description)
- Description:
Set the description format of the command. Triggers a
bajaux:changecommandevent.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
description |
String | the command description - supports baja Format |
setDisplayNameFormat(displayName)
- Description:
Set the display name format of the command. Triggers a
bajaux:changecommandevent.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
displayName |
String | display name - supports baja Format syntax |
setEnabled(enabled)
- Description:
Sets this command's enabled status. Triggers a
bajaux:changecommandevent.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
enabled |
Boolean |
setFlags(flags)
- Description:
Set this command's flags.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
flags |
Number |
setFunction(func)
- Description:
Set the Command's function handler.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function | The new function handler for the command. |
setIcon(icon)
- Description:
Sets the icon for this Command. Triggers a
bajaux:changecommandevent.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
icon |
String | The Command's icon (either a URI or a module:// ORD string) |
setSelected(selected, paramsopt)
- Description:
Sets this command's selected status. Triggers a
bajaux:changecommand.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
selected |
Boolean | ||
params |
Object |
<optional> |
Some optional parameters to pass through |
toDescription() → {Promise}
- Description:
Access the Command's description.
In order to access the description, a promise will be returned
that will be resolved once the command has been loaded and
the description has been found.
- Source:
- Inherited From:
Returns:
Promise to be resolved with the description
- Type
- Promise
toDisplayName() → {Promise}
- Description:
Access the Command's display name.
In order to access the display name, a promise will be returned
that will be resolved once the command has been loaded and
the display name has been found.
- Source:
- Inherited From:
Returns:
Promise to be resolved with the display name
- Type
- Promise
toString() → {string}
- Source:
- Since:
- Niagara 4.15
- Inherited From:
Returns:
- Type
- string
toggle(paramsopt)
- Description:
Selects if deselected, or deselects if selected. Triggers a
bajaux:changecommand.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
params |
Object |
<optional> |
Some optional parameters to pass through to |
trigger(name)
- Description:
Triggers an event from this Command.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
String |
visit(func)
- Description:
Visit this Command with the specified function.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function | Will be invoked with this |