From 8df8e0fcc5945408fe1108715ca0263b812e3987 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Fri, 25 Oct 2019 13:26:01 +0200 Subject: [PATCH] feat: add multi-element delete action --- .../context-pad/ContextPadProvider.js | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/features/context-pad/ContextPadProvider.js b/lib/features/context-pad/ContextPadProvider.js index 80b04913..eeb97cb8 100644 --- a/lib/features/context-pad/ContextPadProvider.js +++ b/lib/features/context-pad/ContextPadProvider.js @@ -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; +} \ No newline at end of file