mirror of
https://github.com/sartography/bpmn-js-spiffworkflow.git
synced 2025-02-24 05:28:20 +00:00
Adding new data object rules that will prevent you from moving a DataObject from one process to a sub-process. Fixing the Selection of Data Objects to properly use the command stack.
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
/**
|
|
* Custom Rules for the DataObject - Rules allow you to prevent an
|
|
* action from happening in the diagram, such as dropping an element
|
|
* where it doesn't belong.
|
|
*
|
|
* Here we don't allow people to move a data object Reference
|
|
* from one parent to another, as we can't move the data objects
|
|
* from one parent to another.
|
|
*
|
|
*/
|
|
import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider';
|
|
import inherits from 'inherits-browser';
|
|
import { is } from 'bpmn-js/lib/util/ModelUtil';
|
|
import IoRules from '../InputOutput/IoRules';
|
|
|
|
export default function DataObjectRules(eventBus) {
|
|
RuleProvider.call(this, eventBus);
|
|
}
|
|
inherits(DataObjectRules, RuleProvider);
|
|
const HIGH_PRIORITY = 1500;
|
|
|
|
DataObjectRules.prototype.init = function() {
|
|
this.addRule('elements.move', HIGH_PRIORITY,function(context) {
|
|
let elements = context.shapes;
|
|
let target = context.target;
|
|
return canDrop(elements, target);
|
|
});
|
|
};
|
|
|
|
function canDrop(elements, target) {
|
|
for (let element of elements) {
|
|
if (is(element, 'bpmn:DataObjectReference') && element.parent && target) {
|
|
return target === element.parent;
|
|
}
|
|
}
|
|
}
|
|
|
|
IoRules.prototype.canDrop = canDrop;
|