new (require("bajaux/commands/ToggleCommandGroup"))(params)
ToggleCommandGroup is a special CommandGroup that behaves like a radio button group.
Extends:
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
Properties
|
Examples
new ToggleCommandGroup({
commands: [
{
module: "mymodule",
lex: "mycommand1",
value: 0
},
{
module: "mymodule",
lex: "mycommand2",
value: 1
},
{
module: "mymodule",
lex: "mycommand3",
value: 2
}
],
onChange: function (value) {
// receives the values specified above.
switch (value) {
case 0:
case 1:
case 2:
}
}
});
Use a flat style for your toggle button group.
var buttonGroup = new CommandButtonGroup();
return buttonGroup.initialize(dom, { toggleGroup: true })
.then(function () {
return buttonGroup.load(toggleCommandGroup);
});
Methods
-
add(command)
-
Add a command to this group. Triggers a
bajaux:changecommandgroupevent. Multiple arguments can be specified to
add many commands at once.Parameters:
Name Type Description commandmodule:bajaux/commands/Command The command to add.
- Inherited From:
Returns:
Return the CommandGroup instance.
-
doSort(kids)
-
Does the work of sorting this command group. By default, does nothing.
When overriding this method, be sure to return the sorted array as a
parameter todeferred.resolve.Parameters:
Name Type Description kidsArray An array of the command group's children - this may
include commands or sub-CommandGroups.- Inherited From:
Returns:
an array containing the sorted children, or
a promise to be resolved with same- Type
- Array | Promise
-
filter(options)
-
Filters the commands in this command group based on the results of
a test function, and returns a new, filtered CommandGroup instance.Parameters:
Name Type Description optionsObject An options object literal
Properties
Name Type Argument Description includefunction <optional>
A function that will receive a
command object and return true or false depending on whether to include
that command in the filtered results. If omitted, defaults to always
return true.flagsNumber <optional>
A number containing flag bits to test on
each command. If omitted, defaults to Command.flags.ALL.- Inherited From:
Returns:
A filtered command group.
-
findCommand()
-
Find a Command in this CommandGroup (or sub CommandGroup) via its id and return it.
- Inherited From:
Returns:
return the found Command (or null if nothing found).
-
flatten(options)
-
Return a listing of the commands (not command groups) contained within
this group. Can optionally recursively visit down through any
sub-CommandGroups contained in this group (depth first) to return all
commands. Can optionally filter commands by flags as well.Parameters:
Name Type Description optionsObject An options object.
Properties
Name Type Argument Description flagsNumber <optional>
flags Used to filter commands. If omitted,
includes all commands regardless of flags.recurseBoolean <optional>
trueif should recurse down through any
sub-groups.- Inherited From:
Returns:
An array of Commands.
- Type
- Array
Example
cmdGroup.flatten(); // all child commands cmdGroup.flatten(Command.flags.MENU); // only children with MENU flag cmdGroup.flatten({ flags: Command.flags.MENU, recurse: true }); -
get(index)
-
Return a Command/CommandGroup based upon the index or
null if nothing can be found.Parameters:
Name Type Description indexNumber - Inherited From:
Returns:
-
getChildren()
-
Returns a defensive copy of this group's array of children.
- Inherited From:
Returns:
- Type
- Array
-
getDisplayNameFormat()
-
Return the format display name of this command group.
- Inherited From:
Returns:
- Type
- String
-
getFlags()
-
Returns this group's flags.
- Inherited From:
Returns:
- Type
- Number
-
getSelected()
-
Get the selected command
Returns:
The selected ToggleCommand
-
getSelectedValue()
-
Get the selected value if available
Returns:
If a 'value' parameter is set it will be returned
- Type
- any
-
hasFlags(flags)
-
Check to see if this group's flags match any of the bits of the
input flags.Parameters:
Name Type Description flagsNumber The flags to check against
- Inherited From:
-
isCommand()
-
Always returns false.
- Inherited From:
-
isEmpty()
-
Return true if this CommandGroup doesn't contain any children.
- Inherited From:
Returns:
true if empty.
-
isLoading()
-
- Inherited From:
Returns:
true if any of the Commands are still loading.
- Type
- boolean
-
isToggleCommand()
-
Always returns false.
- Inherited From:
-
jq( [jqDom])
-
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 CommandGroup.Parameters:
Name Type Argument Description jqDomJQuery <optional>
If specified, this will set the jQuery DOM.
- Inherited From:
Returns:
A jQuery DOM object for firing events on.
- Type
- JQuery
-
loading()
-
Return promise that will be resolved once all the Commands in this
group have been loaded.- Inherited From:
Returns:
A promise that will be resolved once all of the
child Commands have loaded.- Type
- Promise
-
merge(group [, params])
-
Merges an input command group with this one, and returns a new
command group with the merged results.Parameters:
Name Type Argument Description groupmodule:bajaux/commands/CommandGroup The group to merge with
this oneparamsobject <optional>
Properties
Name Type Argument Default Description mergeCommandsboolean <optional>
true set to false to cause commands
to be merged by a simple instanceof check, and all child commands of this
group will be included; otherwise, only commands whosemerge()function
returns a new Command will be included- Inherited From:
Returns:
the merged group, or
null if the merge could not be completed- Type
- module:bajaux/commands/CommandGroup | null
-
remove(command)
-
Remove a command from this group. Triggers a
bajaux:changecommandgroupevent. Multiple arguments
can be specified so multiple commands can be removed at once.Parameters:
Name Type Description commandmodule:bajaux/commands/Command | Number The command or index
of the Command to remove.- Inherited From:
Returns:
Return the CommandGroup instance.
-
removeAll(options)
-
Remove all children of this command group that match the input flag,
optionally emptying out child groups as well. Triggers a
bajaux:changecommandgroupevent.Parameters:
Name Type Description optionsObject An options object
Properties
Name Type Argument Description flagsNumber <optional>
Flags to use to filter commands. Only
children that match one of these flags will be removed.
If omitted, defaults toCommand.flags.ALLmeaning all
children will be removed.recurseBoolean <optional>
trueif should also empty out any
sub-groups.- Inherited From:
Example
cmdGroup.removeAll(); cmdGroup.removeAll(Command.flags.MENU_BAR); cmdGroup.removeAll({ flags: Command.flags.MENU_BAR, recurse: true }); -
setChildren(children)
-
Sets this group's array of commands/groups wholesale. Triggers a
bajaux:changecommandgroupevent.Parameters:
Name Type Description childrenArray - Inherited From:
-
setDisplayNameFormat(displayName)
-
Set the display name format of the command group. Triggers a
bajaux:changecommandgroupevent.Parameters:
Name Type Description displayNameString display name - supports baja Format syntax
- Inherited From:
-
setFlags(flags)
-
Sets this group's flags. Triggers a
bajaux:changecommandgroupevent.Parameters:
Name Type Description flagsNumber - Inherited From:
-
size()
-
Return the number of children the CommandGroup has
(this covers both Commands and CommandGroups).- Inherited From:
Returns:
- Type
- Number
-
sort()
-
Sorts this command group. Typically will not be overridden; override
doSortinstead. Triggers abajaux:changecommandgroupevent.- Inherited From:
Returns:
A promise that will be invoked once the CommandGroup
has been sorted.- Type
- Promise
-
toDisplayName()
-
Formats the command's display name.
- Inherited From:
Returns:
Promise to be resolved with the display name
- Type
- Promise.<String>
-
trigger(name)
-
Triggers an event from this CommandGroup.
Parameters:
Name Type Description nameString - Inherited From:
-
visit(func)
-
Visit through all of the Commands and CommandGroups.
The function passed it will be called for every Command and CommandGroup
found (including this CommandGroup).Parameters:
Name Type Description funcCalled for every CommandGroup and Command found. Each
Command/CommandGroup is passed in as the first argument to the function.
If the function returns a false value then iteration stops.- Inherited From: