SUI.ActionList

SUI.ActionList is a component that helps you manage the different actions that can be performed in an user interface. It gives you a centralized repository to store your actions and different interface elements can register to and trigger those actions.

For example: in your interface the save action is triggered by a toolbar button, a context menu item and a key combination. Instead of calling your save action directly by the element handlers of these controls, you can call this action through the action list. The benefits of the action list is that the toolbar and context menu can use common data as the action's descriptive text and icon, but it also provides a centralized way to enable/disable the action and show the enabled state in the user interface.

The following code exerpt shows an action list together with a toolbar and context menu component that use the actions of the list. Both the toolbar and context menu will also use the action list for the text and icon of their items. Changes to the enabled state of the action list's items will be reflected by the toolbar and context menu.

// Create an actionlist: add descriptive information (icon, title)
// to the action and store these in the list.
var actionList = new SUI.ActionList([{
    actionId: "error",
    title: "Show an error message",
    icon: "delete.png",
    handler: function(){alert("Error");}
},{
    actionId: "ok",
    title: "Show an ok message",
    icon: "tick.png",
    handler: function(){alert("Ok");}
},{
    actionId: "alert",
    title: "Show an alert message",
    icon: "info.png",
    handler: function(){alert("Alert");}
}]);

// Create a toolbar that uses actions from the action list
var toolbar = new SUI.Toolbar({
    top: 20, left: 20, width: 120,
    actionlist: actionList,
    tools: [
        new SUI.ToolbarButton({actionId: "error"}),
        new SUI.ToolbarButton({actionId: "ok"}),
        new SUI.ToolbarButton({actionId: "alert"})
    ]
});

// Create a menu that uses actions from the action list
var menu = new SUI.PopupMenu({
    actionlist: actionList,
    items: [
        { actionId: "error" },
        { actionId: "ok" },
        { actionId: "alert" }
    ]
});

Defined in: ActionList.js


Constructor summary

Attr. Name / Description
public

SUI.ActionList(arg, arg[], [arg[])

Construct an action list component. You can add your actions directly by passing them to the constructor as an array.

Member summary

Attr. Type Name Description
private Object[]

_list

Array to store the actions.

Method summary

Attr. Type Name / Description
public

add(a)

Add an action to the action list.

public

doAction(aId)

Execute one of the list's actions.

public

enable(actObj)

Enable/disable a number of actions in the list.

public Object

get(aId)

Retrieve an action from the list.

public

select(actObj)

Select/deselect a number of actions in the list.

 


Constructor

public SUI.ActionList( Object[] arg, object arg[], object [arg[])

Construct an action list component. You can add your actions directly by passing them to the constructor as an array.

Parameters:

Name Type Argument Default Description
Object[] arg An object array that describes a set of actions that will added to the action list.
String arg[].actionId The action's name/id.
Function arg[].handler The action handler.
boolean arg[].enabled <optional>
true The enabled state of the action.
boolean arg[].selected <optional>
false The selected state of the action.
String [arg[].title="Action 'actionId'"] A descriptive title for the action.
String arg[].icon <optional>
An icon for the action.

Members

private Object[] _list

Array to store the actions.


Methods

public add( Object a)

Add an action to the action list.

Parameters:

Name Type Argument Default Description
Object a An argument object that describes the action to add.
String a.actionId The action's name/id.
Function a.handler The action handler.
boolean a.enabled <optional>
true The enabled state of the action.
boolean a.selected <optional>
false The selected state of the action.
String a.title <optional>
"Action 'actionId'" A descriptive title for the action.
String a.icon <optional>
An icon for the action.
public doAction( String aId)

Execute one of the list's actions.

Parameters:

Name Type Description
String aId The action id of the action to execute.
public enable( Object actObj)

Enable/disable a number of actions in the list.

Parameters:

Name Type Description
Object actObj A list of action id's with the preferred enabled state in object notation: the field names are the names of the action id's, the value of each field is the action's enabled state.
public Object get( String aId)

Retrieve an action from the list.

Parameters:

Name Type Description
String aId The action id of the action to retrieve.

Returns:

Object An action object.

public select( Object actObj)

Select/deselect a number of actions in the list.

Parameters:

Name Type Description
Object actObj A list of action id's with the preferred selected state in object notation: the field names are the names of the action id's, the value of each field is the action's selected state.