Skip to content

Instantly share code, notes, and snippets.

@prantlf
Created January 27, 2021 21:09
Show Gist options
  • Save prantlf/3ba53e6bd0277348d80f15a1e832638d to your computer and use it in GitHub Desktop.
Save prantlf/3ba53e6bd0277348d80f15a1e832638d to your computer and use it in GitHub Desktop.
How to add a menu item opening Personal Workspace to the user profile menu.
src/commands/profile.menuitems.js (add menu items):
define(function () {
return {
profileMenu: [
{
signature: 'myext-open-pws',
name: 'Go to Personal Workspace',
group: 'others'
}
]
};
});
src/commands/open.pws/open.pws.command.js (add a command):
define([
'csui/lib/jquery', 'csui/models/command'
], function ($, CommandModel) {
var OpenPWSCommand = CommandModel.extend({
defaults: { signature: 'myext-open-pws' },
execute: function (status, options) {
var deferred = $.Deferred();
require([
'csui/models/node/node.model'
], function (NodeModel) {
var context = status.context ||
options && options.context;
var connector = context.getObject('connector');
var pws = new NodeModel(
{ id: 'volume', type: 142 },
{ connector: connector }
);
pws.fetch()
.then(function () {
var nextNode = context.getModel('nextNode');
nextNode.set('id', pws.get('id'));
deferred.resolve();
}, deferred.reject);
}, deferred.reject);
return deferred.promise();
}
});
return OpenPWSCommand;
});
src/myext-extensions.json (register both extensions):
{
"csui/widgets/navigation.header/profile.menuitems": {
"extensions": {
"myext": [
"myext/commands/profile.menuitems"
]
}
},
"csui/utils/commands": {
"extensions": {
"myext": [
"myext/commands/open.pws/open.pws.command"
]
}
},
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment