Module: alfresco/menus/AlfMenuBarToggle

alfresco/menus/AlfMenuBarToggle

This provides a basic on/off state toggle button that can be placed on a menu bar. By default it simply renders a switch with localized "On" and "Off" labels and doesn't actually perform any action beyond rendering it's current state.

It can be configured with custom labels and/or icons to represent state. Ideally each state should be given a publish topic and payload so that it can interact with other widgets and perform a useful action. This is done by configuing the "onConfig" and "offConfig" attributes.

Example configuration:

{
   name: "alfresco/menus/AlfMenuBarToggle",
   config: {
      id: "MyToggle",
      checked: true,
      onConfig: {
         label: "Turned On",
         title: "Click to turn off",
         iconClass: "on-icon",
         iconAltText: "Toggle is on",
         publishTopic: "toggle_changed",
         publishPayload: {
            value: "ON"
         }
      },
      offConfig: {
         label: "Turned Off",
         title: "Click to turn on",
         iconClass: "off-icon",
         iconAltText: "Toggle is off",
         publishTopic: "toggle_changed",
         publishPayload: {
            value: "OFF"
         }
      }
   }
}

Author:
  • Dave Draper
License:
Source:

Members

checked :boolean

Indicates the on/off state. True is on, false is off.
Type:
  • boolean
Default Value:
  • false
Source:

checkedValue :string

This is the value that indicates the toggle should be checked. It defaults to "true" and should be overridden as necessary.
Type:
  • string
Default Value:
  • "true"
Source:

cssRequirements :object[]

An array of the CSS files to use with this widget.
Type:
  • object[]
Default Value:
  • [{cssFile:"./css/AlfMenuBarToggle.css"}]
Source:

hashName :string

If this instance should be set according to a hash fragment value then this attribute should be set to the name of the fragment parameter to use. If the hash fragment parameter exists and the value is "true" then the toggle will be automatically checked.
Type:
  • string
Default Value:
  • null
Source:

i18nRequirements :object[]

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

offConfig :object

The configuration representing the toggle in it's 'off' state
Type:
  • object
Default Value:
  • null
Source:

onConfig :object

The configuration representing the toggle in it's 'on' state
Type:
  • object
Default Value:
  • null
Source:

subscriptionAttribute :string

This is the attribute to look for in the payload when handling external requests to control the toggle.
Type:
  • string
Default Value:
  • "value"
Source:

subscriptionTopic :string

This is a topic that can be subscribed to that when published on will set the state of the toggle
Type:
  • string
Default Value:
  • null
Source:

Methods

constructor()

This sets default values for the onConfig and offConfig attributes if they have not been configured. The defaults are localised "On" and "Off" labels with no publication data for either state.
Source:

onClick()

This handles the user clicking on the toggle. The state is changed (e.g. from OFF on ON) and any data associated with the new state is published on the configured topic.
Source:

postCreate()

Sets up the initial state of the widget based on the onConfig and offConfig attributes. The renderToggle function is called to render the starting state.
Source:

postMixInProperties()

Subscribe the document list topics.
Source:

renderToggle(newConfig, oldConfig)

This performs the rendering of the toggle when the widget is instantiated and when the state is changed. The labels and icons are updated to reflect the new state.
Parameters:
Name Type Description
newConfig object The new configuration to apply to the toggle button
oldConfig object The old configuration being removed from the toggle button.
Source:

setState()

This handles the toggle being set by a 3rd party widget. It does not publish but just changes the display.
Source: