Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
UpdateCanvasRootHandler.prototype.execute = function(context) {
var canvas = this._canvas;
var newRoot = context.newRoot,
newRootBusinessObject = newRoot.businessObject,
oldRoot = canvas.getRootElement(),
oldRootBusinessObject = oldRoot.businessObject,
bpmnDefinitions = oldRootBusinessObject.$parent,
diPlane = oldRootBusinessObject.di;
// (1) replace process old <> new root
canvas.setRootElement(newRoot, true);
// (2) update root elements
collectionAdd(bpmnDefinitions.rootElements, newRootBusinessObject);
newRootBusinessObject.$parent = bpmnDefinitions;
collectionRemove(bpmnDefinitions.rootElements, oldRootBusinessObject);
oldRootBusinessObject.$parent = null;
// (3) wire di
oldRootBusinessObject.di = null;
diPlane.bpmnElement = newRootBusinessObject;
newRootBusinessObject.di = diPlane;
context.oldRoot = oldRoot;
// TODO(nikku): return changed elements?
// return [ newRoot, oldRoot ];
};
let context = e.context,
shape = context.shape,
businessObject = shape.businessObject;
if (!isDomainStory(shape)) {
return;
}
let parent = shape.parent;
let customElements = bpmnjs._customElements;
// make sure element is added / removed from bpmnjs.customElements
if (!parent) {
collectionRemove(customElements, businessObject);
} else {
collectionAdd(customElements, businessObject);
}
// save custom element position
assign(businessObject, pick(shape, ['x', 'y']));
// save custom element size if resizable
if (isDomainStoryGroup(shape)) {
assign(businessObject, pick(shape, ['height', 'width']));
// rework the child-parent relations if a group was moved, such that all Objects that are visually in the group are also associated with it
// since we do not have access to the standard-canvas object here, we cannot use the function correctGroupChildren() from DSLabelUtil
if (parent != null) {
reworkGroupElements(parent, shape);
}
}
// make sure the participants process is properly attached / detached
// from the XML document
var process = businessObject.processRef,
definitions;
if (process) {
definitions = getDefinitions(businessObject.$parent || newParent);
if (businessObject.$parent) {
collectionRemove(definitions.get('rootElements'), process);
process.$parent = null;
}
if (newParent) {
collectionAdd(definitions.get('rootElements'), process);
process.$parent = definitions;
}
}
} else
if (is(businessObject, 'bpmn:DataOutputAssociation')) {
containment = 'dataOutputAssociations';
} else
if (is(businessObject, 'bpmn:DataInputAssociation')) {
containment = 'dataInputAssociations';
}
if (!containment) {
throw new Error(translate(
'no parent for {element} in {parent}',
update.add.forEach(function(newLane) {
collectionAdd(lanes, newLane);
collectionAdd(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
});
});
update.remove.forEach(function(oldLane) {
collectionAdd(lanes, oldLane);
collectionAdd(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
});
});
function getTargetRef(element, create) {
var properties = element.get('properties');
var targetRefProp = find(properties, function(p) {
return p.name === TARGET_REF_PLACEHOLDER_NAME;
});
if (!targetRefProp && create) {
targetRefProp = bpmnFactory.create('bpmn:Property', {
name: TARGET_REF_PLACEHOLDER_NAME
});
collectionAdd(properties, targetRefProp);
}
return targetRefProp;
}
this.reverted('shape.delete', function(event) {
var context = event.context,
shape = context.shape;
if (is(shape, 'bpmn:Group')) {
var businessObject = getBusinessObject(shape),
categoryValueRef = businessObject.categoryValueRef,
definitions = getDefinitions(),
category = categoryValueRef ? categoryValueRef.$parent : null;
collectionAdd(category.get('categoryValue'), categoryValueRef);
collectionAdd(definitions.get('rootElements'), category);
}
});
update.add.forEach(function(newLane) {
collectionAdd(lanes, newLane);
collectionAdd(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
});
});
this.reverted('shape.delete', function(event) {
var context = event.context,
shape = context.shape;
if (is(shape, 'bpmn:Group')) {
var businessObject = getBusinessObject(shape),
categoryValueRef = businessObject.categoryValueRef,
definitions = getDefinitions(),
category = categoryValueRef ? categoryValueRef.$parent : null;
collectionAdd(category.get('categoryValue'), categoryValueRef);
collectionAdd(definitions.get('rootElements'), category);
}
});