Buttons¶
The primary purpose of this service is to provide buttons to display on the Portals main menu toolbar and the views.
To see the Buttons menu entry on the Portal, the buttons=view
permission is required.
For a summary of permission names and uses related to this service, please refer to this section.
Note
If you have the buttons=*
permission, you will have access to all the functions mentioned below.
List and view buttons¶
To list and display all buttons, the buttons=read
permission is required.
If your permission has values such as: buttons=read('Button 1', 'Button 2')
, you will only see the listed buttons.
You can view a button by clicking on the magnifier icon in the ‘Actions’ column.
Edit a button¶
To create, update, rename, duplicate, export or import buttons, the buttons=edit
permission is required.
To delete buttons, the buttons=delete
permission is required.
Double-click on a row of the table display or click on the pen icon to edit a button.
Type¶
A MENU
button will be added to the standard UI menu if the users buttons=display
permission checks succeed.
A VIEW
button when referenced as a defined
Handlers¶
The permission buttons=display
is required to access the following endpoints.
You can also restrict access to specific buttons (i.e. buttons=display("button1", "button2")
)
You can define other arguments in the uri to be passed to the script through the pipeline.
Notice
The URI must start with p6cmb://
.
The primary target for button calls is the script service but any p6 service can be called via this mechanism.
Variables will be provided to the script throw the pipeline:
- locale: the locale of the connected user
Button VIEW type only
- viewName: the name of the current view
- platform6.request.dataPartition: the dataPartition of the current view
- platform6.request.dataType: the dataType of the current view
- platform6.request.ids.X: the id of the selected item in the view (where X is 0 indexed number)
Before rendering¶
The button can be configured with a before render handler. It is the uri of the target destination of a message through the Common Message Bus.
For example, you can define a script as target:
p6cmb://scripts?platform6.request.action=execute&id=BeforeButtonRender
Specific variables will be provided to the script throw the pipeline:
- defaultLabel: the default localized label
- defaultTooltip: the default localized tooltip
- defaultStyle: the default style
- defaultIcon: the default icon
- defaultWeight: the default weight (for
MENU
only)
In response, the script can write into the pipeline the following entries prefixed by the transaction item ids:
- {key}.style: css classes to be applied to the button
- {key}.label: button label to be displayed (use the
p6.i18n
DSL to retrieve localized text) - {key}.icon: css classes to be applied to the icon. (If empty no icon will be displayed)
- {key}.display: should we display the button (true by default).
For MENU
only:
- {key}.weight: position of the button in the Platform6 main menu (should be an integer)
Notice
If the output pipeline entries are missing then the default configuration of the button will be used
Notice
For menu button type, {key} should be set to “menu”
Script example¶
Menu
p6.pipeline.put("menu.label", "Custom override")
p6.pipeline.put("menu.icon", "fa-fw fa fa-bolt")
p6.pipeline.put("menu.weight", "100")
p6.pipeline.put("menu.display", "true")
Transaction
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;
def label = [
EN: "items to pay",
FR: "articles à payer"
]
def xmlSlurper = new XmlSlurper()
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
println " > Processing: " + pk
def key = pk.getItemIds().join(",")
def item = p6.transaction.get(pk)
def transactionInfo = xmlSlurper.parseText(item)
def count = transactionInfo.KeyValue.find{it.Key == 'Line items'}.Value.text()
p6.pipeline.put("${key}.label", "${count} " + p6.i18n.getText(label))
p6.pipeline.put("${key}.style", "btn-trans btn-success")
if(count.toInteger() > 10) {
p6.pipeline.put("${key}.style", "btn-trans btn-danger")
}
if(count.toInteger() == 0) {
p6.pipeline.put("${key}.display", "false")
}
}
On click¶
The button can be configured with an on click render handler. It is the uri of the target destination of a message through the Common Message Bus.
For example, you can define a script as target:
p6cmb://scripts?platform6.request.action=execute&id=OnButtonClick
In response, the service can write into the pipeline the following entries:
-
ui.action: the action to be returned to the UI:
-
POPUP_MESSAGE: Simple message popups containing locale specific text
-
OPEN_JOBS: Open the jobs panel so the user can see job progress and download generated payloads
-
OPEN_VIEW: This will open a transactions list panel with the given view id
-
OPEN_DASHBOARD: This will open a specific dashboard
-
REFRESH_CURRENT_VIEW: Force the refresh of the current page view of transactions or workflow tasks
-
NEW_FORM: This causes the UI to call the new
Forms Service
to retrieve the definition and render the named form -
WEB_LINK: Open the given url in a new tab
-
INDICATOR: Return an execution indicator
-
Notice
Only the script service is capable of reading and writing to/from the pipeline. Other services must read/write the Platform 6 Common Message directly to adhere to this implied Request/Response contract. If the call succeeds a success action will be returned. Otherwise, a failure will be returned, and a warning is displayed in the log of Platform 6.
The following action requires additional parameters:
POPUP_MESSAGE
- popup.type: the type of the popup (allowed values are: ERROR, INFO, WARNING, SUCCESS)
- popup.title: the title of the popup
- popup.message: the message of the popup
OPEN_VIEW
- view.name: the name of the view to be displayed
NEW_FORM
- form.id: the id of the form to be displayed
WEB_LINK
- link.url: the url to be opened in a new tab
OPEN_DASHBOARD
- dashboard.name: the name of the dashboard to be displayed
The following action accepts optional parameters:
INDICATOR
- indicator.success: is the indicator on success (true by default)
- indicator.message: the indicator message
Script example¶
Menu
p6.pipeline.put("ui.action", "POPUP_MESSAGE")
p6.pipeline.put("popup.type", "INFO")
p6.pipeline.put("popup.title", p6.i18n.getText([EN: "Payment", FR: "Paiement"]))
p6.pipeline.put("popup.message", "Message to be displayed")
Transaction
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;
def xmlSlurper = new XmlSlurper()
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
println " > Processing: " + pk
/*
def item = p6.transaction.get(pk)
def transactionInfo = xmlSlurper.parseText(item)
... some logic
*/
}
p6.pipeline.put("ui.action", "REFRESH_CURRENT_VIEW");
Workflow
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
println " > Processing: " + pk
p6.transaction.getItemLinks(pk, p6.pipeline.get('viewName')).each { itemLink ->
println " > ItemLink: " + itemLink
}
}
p6.pipeline.put("ui.action", "REFRESH_CURRENT_VIEW");