2014-10-06 10:23:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash'),
|
|
|
|
$ = require('jquery');
|
|
|
|
|
|
|
|
/**
|
2014-11-17 10:01:07 +00:00
|
|
|
* A palette provider for BPMN 2.0 elements.
|
2014-10-06 10:23:22 +00:00
|
|
|
*/
|
2014-11-17 10:01:07 +00:00
|
|
|
function PaletteProvider(palette, modeling, elementRegistry, canvas) {
|
2014-10-06 10:23:22 +00:00
|
|
|
|
2014-10-06 13:46:26 +00:00
|
|
|
this._modeling = modeling;
|
|
|
|
this._elementRegistry = elementRegistry;
|
2014-10-06 10:23:22 +00:00
|
|
|
this._canvas = canvas;
|
|
|
|
|
|
|
|
palette.registerProvider(this);
|
|
|
|
}
|
|
|
|
|
2014-11-17 10:01:07 +00:00
|
|
|
module.exports = PaletteProvider;
|
2014-10-06 10:23:22 +00:00
|
|
|
|
2014-11-17 10:01:07 +00:00
|
|
|
PaletteProvider.$inject = [ 'palette', 'modeling', 'elementRegistry', 'canvas' ];
|
2014-10-06 10:23:22 +00:00
|
|
|
|
|
|
|
|
2014-11-17 10:01:07 +00:00
|
|
|
PaletteProvider.prototype.getPaletteEntries = function(element) {
|
2014-10-06 10:23:22 +00:00
|
|
|
|
|
|
|
var actions = {},
|
|
|
|
modeling = this._modeling,
|
|
|
|
elementRegistry = this._elementRegistry,
|
|
|
|
canvas = this._canvas;
|
|
|
|
|
|
|
|
var root = elementRegistry.getRoot();
|
|
|
|
var vbox = canvas.viewbox();
|
|
|
|
|
|
|
|
var center = {
|
2014-10-08 09:38:01 +00:00
|
|
|
x: Math.round(vbox.outer.width * 1 / vbox.scale / 2),
|
|
|
|
y: Math.round(vbox.outer.height * 1 / vbox.scale / 2)
|
2014-10-06 10:23:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_.extend(actions, {
|
|
|
|
'add.start-event': {
|
|
|
|
group: 'model-event',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-start-event',
|
2014-10-06 10:23:22 +00:00
|
|
|
alt: 'Start Event',
|
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:StartEvent'
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
},
|
2014-11-17 10:01:07 +00:00
|
|
|
'add.intermediate-throw-event': {
|
2014-10-06 10:23:22 +00:00
|
|
|
group: 'model-event',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-intermediate-event',
|
2014-10-06 10:23:22 +00:00
|
|
|
alt: 'Intermediate Throw Event',
|
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:IntermediateThrowEvent'
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'add.end-event': {
|
|
|
|
group: 'model-event',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-end-event',
|
2014-10-06 10:23:22 +00:00
|
|
|
alt: 'End Event',
|
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:EndEvent'
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'add.exclusive-gateway': {
|
|
|
|
group: 'model-gateway',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-gateway',
|
2014-10-06 10:23:22 +00:00
|
|
|
alt: 'Exclusive Gateway',
|
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:ExclusiveGateway'
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'add.task': {
|
|
|
|
group: 'model-activity',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-task',
|
2014-10-06 10:23:22 +00:00
|
|
|
alt: 'Task',
|
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:Task'
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'add.subProcess-collapsed': {
|
|
|
|
group: 'model-activity',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-subprocess-collapsed',
|
|
|
|
alt: 'Sub-Process (collapsed)',
|
2014-10-06 10:23:22 +00:00
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:SubProcess',
|
|
|
|
isExpanded: false
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'add.subProcess-expanded': {
|
|
|
|
group: 'model-activity',
|
2014-11-17 10:01:07 +00:00
|
|
|
className: 'icon-subprocess-expanded',
|
|
|
|
alt: 'Sub-Process (expanded)',
|
2014-10-06 10:23:22 +00:00
|
|
|
action: function(event, element) {
|
|
|
|
modeling.createShape({
|
|
|
|
type: 'bpmn:SubProcess',
|
|
|
|
isExpanded: true
|
|
|
|
}, center, root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return actions;
|
2014-11-17 10:01:07 +00:00
|
|
|
};
|