Module: alfresco/renderers/ToggleStateActions

alfresco/renderers/ToggleStateActions

This is an extension to the 'alfresco/renderers/Actions' widget that adds a secondary "off" state where no actions are available. Clicking the button toggles the widget into the "on" state and allows the actions menu to be displayed. The original use case for this widget was in sharing documents - the "off" state was the document not being shared, clicking the button would share the document (and move it into the "on" state) and provide additional actions in the drop-down menu.

Since:
  • 1.0.64
Author:
  • Dave Draper
License:
Source:

Example

Basic Example

{
  name: "alfresco/renderers/ToggleStateActions",
  config: {
    itemKeyProperty: "nodeRef",
    toggleOnWhenPropertySet: true,
    toggleStateProperty: "node.properties.qshare:sharedId",
    toggleOnStateLabel: "Shared",
    toggleOffStateLabel: "Share",
    toggleOnRequestTopic: "SHARE",
    toggleOnSuccessTopic: "SHARE",
    toggleOffSuccessTopic: "UNSHARED",
    customActions: [
       {
          label: "Copy Link",
          publishTopic: "COPY"
       },
       {
          label: "E-Mail Link",
          publishTopic: "EMAIL"
       },
       {
          label: "Stop sharing",
          publishTopic: "UNSHARED"
       }
    ]
  }
}

Members

_actionsEnabled :string

Private attribute used to determine whether or not the actions are enabled (actions are enabled when the button is toggled to the "on" state).
Type:
  • string
Default Value:
  • true
Source:

_itemKey :object

The unique value that uniquely identifies the item. This is set once in postCreate using the value of itemKeyProperty from the currentItem.
Type:
  • object
Default Value:
  • null
Source:

i18nRequirements :object[]

An array of the i18n files to use with this widget.
Type:
  • object[]
Default Value:
  • [{i18nFile: "./i18n/ToggleStateActions.properties"}]
Source:

itemKeyProperty :string

The property of the current item that uniquely identifies it. This attribute is used to check that any published toggleOnSuccessTopic relates to the [currentItem]module:alfresco/core/CoreWidgetProcessing#currentItem. This allows the state to be toggled by an external widget.
Type:
  • string
Default Value:
  • "node.nodeRef"
Source:

toggleOffStateLabel :string

This is the label to display on the button when toggled to the "off" state.
Type:
  • string
Default Value:
  • "toggle.state.off.label"
Source:

toggleOnStateLabel :string

This is the label to display on the button when toggled to the "on" state.
Type:
  • string
Default Value:
  • "toggle.state.on.label"
Source:

toggleOnWhenPropertySet :string

If this is configured to be true then the toggleStateProperty only needs to exist in order for the button to be toggled to the "on" state.
Type:
  • string
Default Value:
  • false
Source:

toggleStateOnValue :string

This is the value that the toggleStateProperty must be in order for the button to be in toggled "on" state when first loaded.
Type:
  • string
Default Value:
  • "node.properties.qshare:sharedId"
Source:

toggleStateProperty :string

This is the property to compare against the toggleStateOnValue to determine whether or not the button is in the toggled "on" state. If toggleOnWhenPropertySet is configured to be true then the button will be toggled to the "on" state if the property exists.
Type:
  • string
Default Value:
  • null
Source:

Methods

postCreate()

Extends the inherited function to retrieve the itemKeyProperty from the [currentItem]module:alfresco/core/CoreWidgetProcessing#currentItem, set the initial toggle state and to update the label, topic and payload of the associated button.
Source:
Listens to Events:

toggleDropDown()

Extends the function inherited from dijit/_HasDropDown to only allow the drop-down actions menu to be displayed when _actionsEnabled is set to true.
Source:

toggleOff(payload)

Handles requests to toggle the state of the button to off. The payload is checked that the _itemKey matches either the itemKeyProperty or the itemKeyProperty prefixed by "document.". This latter condition exists to satisfy the case where there is not intermediate service between toggle request and response where the action menu item includes the [currentItem]{@link module:alfresco/core/CoreWidgetProcessing#currentItem} assigned to the "document" attribute in the published payload.
Parameters:
Name Type Description
payload object The payload published requesting to toggle to the off state
Source:

toggleOn(payload)

Handles requests to toggle the state of the button to off. The payload is checked that the _itemKey matches the itemKeyProperty.
Parameters:
Name Type Description
payload object The payload published requesting to toggle to the off state
Source:

updateButtonLabel(payload)

Sets the label of the button with either the toggleOnStateLabel or the toggleOffStateLabel depending upon the value of _actionsEnabled.
Parameters:
Name Type Description
payload object The payload published requesting to toggle to the off state
Source:

Events

toggleOffSuccessTopic

This is the topic that should be published to toggle from the "on" state to the "off" state. It should be published either by one of the actions displayed in the drop-down menu when the button is "on" state or from a service that handles requests to change the toggle state of an item. It could also be published by an entirely unrelated widget or service if necessary. The only requirement is that the itemKeyProperty exists in the published payload to match requests against the appropriate instance of the widget.
Type:
  • string
Default Value:
  • TOGGLE_OFF
Source:
Listeners of This Event:

toggleOnRequestTopic

This is the topic that is published when the button is clicked when in the "off" state. It makes a request to update the toggle state. Typically this topic would be subscribed to by a service that would indicate a successful change in state by publishing on the toggleOnSuccessTopic. However, it is possible to skip this intermediate step and configure the toggleOnSuccessTopic to have an idential value.
Type:
  • string
Default Value:
  • TOGGLE_ON
Source:

toggleOnSuccessTopic

This is the topic that should be published to toggle from the "off" state to the "on" state. Typically it would be published by a service that handles requests to change the toggle state of an item. However, it is possible to skip this intermediate step and configure the toggleOnRequestTopic to have an idential value. The only requirement is that the itemKeyProperty exists in the published payload to match requests against the appropriate instance of the widget.
Type:
  • string
Default Value:
  • TOGGLE_ON
Source:
Listeners of This Event: