feat: add multi-element delete action

This commit is contained in:
Philipp Fromme 2019-10-25 13:26:01 +02:00 committed by Beatriz Mendes
parent 9b1096abbc
commit 8df8e0fcc5
1 changed files with 47 additions and 2 deletions

View File

@ -1,7 +1,8 @@
import {
assign,
forEach,
isArray
isArray,
every
} from 'min-dash';
import {
@ -86,9 +87,49 @@ ContextPadProvider.$inject = [
'translate'
];
ContextPadProvider.prototype.getMultiElementContextPadEntries = function(elements) {
var modeling = this._modeling;
var actions = {};
if (this._isDeleteAllowed(elements)) {
assign(actions, {
'delete': {
group: 'edit',
className: 'bpmn-icon-trash',
title: this._translate('Remove'),
action: {
click: function(event, elements) {
modeling.removeElements(elements.slice());
}
}
}
});
}
return actions;
};
/**
* @param {djs.model.Base[]} elements
* @return {boolean}
*/
ContextPadProvider.prototype._isDeleteAllowed = function(elements) {
var baseAllowed = this._rules.allowed('elements.delete', {
elements: elements
});
if (isArray(baseAllowed)) {
return every(baseAllowed, function(element) {
return includes(baseAllowed, element);
});
}
return baseAllowed;
};
ContextPadProvider.prototype.getContextPadEntries = function(element) {
var contextPad = this._contextPad,
modeling = this._modeling,
@ -470,3 +511,7 @@ function isEventType(eventBo, type, definition) {
return isType && isDefinition;
}
function includes(array, item) {
return array.indexOf(item) !== -1;
}