Introduction
This document describes how to create a command plugin for the
global toolbar in
the EPiServer user interface.
Creating a command provider for the global toolbar
To be able to add commands to the global toolbar, a Command Provider for the toolbar has to be created and added to the
global command registry. The global command registry is used to map command providers
against given keys.
The following example shows how to create provider that adds three commands to the different areas inside the global toolbar.
JavaScript
define([
"dojo/_base/declare",
"dijit/form/Button",
"dijit/form/ToggleButton",
"epi-cms/component/command/_GlobalToolbarCommandProvider",
"samples/TestCommand",
"samples/MyToggleCommand"
], function (declare, Button, ToggleButton, _GlobalToolbarCommandProvider, TestCommand, MyToggleCommand) {
return declare([_GlobalToolbarCommandProvider], {
constructor: function () {
this.inherited(arguments);
this.addToLeading(new TestCommand({
label:"First command"
}), {showLabel:true, widget:Button});
this.addToCenter(new MyToggleCommand({
label:"Second command"
}), {showLabel:true, widget:ToggleButton});
this.addToTrailing(new TestCommand({
label:"Third command"
}), {showLabel:true, widget:Button});
}
});
});
And here are the test commands
JavaScript
define([
"dojo/_base/declare",
"epi/shell/command/_Command"
],
function (declare, _Command) {
return declare([_Command], {
name: "Test",
label: "Test command",
tooltip: "Click to execute me",
iconClass: "dijitIconNewPage",
canExecute: true,
_execute: function () {
alert("label:", this.label);
}
});
});
define([
"dojo/_base/declare",
"epi/shell/command/ToggleCommand"
],
function (declare, _Command) {
return declare([ToggleCommand], {
name: "Test",
label: "Click here to toggle",
tooltip: "Click to toggle me",
iconClass: "dijitIconNewPage",
canExecute: true,
_execute: function () {
alert("Label: " + this.label);
}
});
});
For the system to find your command provider, you must register it in the global command registry.
JavaScript
var commandregistry = dependency.resolve("epi.globalcommandregistry");
commandregistry.registerProvider("epi.cms.globalToolbar", new MyCommandProvider());