Hi,
short of “just reading the examples” - are there any resources for how to go about customising the modeler ?
I’m particular interested in added a “window” for some data entry for each node and to get that read/written into the generated XML.
(I’m wrapping the canvas used to display the modeler in some ExtJS panel stuff - compiled up the code and then just copied the generated index.js into my project - probably not a great way of doing it)
Its might be that the diagram events are enough.
But - for example - if I listen for a double click - open my window - it still shows the original “name” edit frame.
How do I prevent that ? (i tried e.preventDefault() and return false - but I think its opened when it calls my event handler)
Ok - mostly there now - I have a window with properties.
I can change the X,Y etc
But “name” is changing on the element (i can see it when I re-open my window) - but its not reflected on the diagram.
So - I tried that - but it still not updating.
Here - I’ve set newData to be an object containing the data I need to change - so something like
newData={name: ‘somename’};
[ no idea what this invoke is supposed to do - it was a c&p from google job! ]
The reason you need to generally dispatch updates via modeling is the fact that bpmn-js needs to be informed when elements have changed (read about it here).
Using modeling.updateProperties(...) changes attributes of the underlying BPMN element (exactly what you want to do). For details have a look at the UpdatePropertiesHandler that takes care of doing that.
For further assistance, please provide your example somewhere so we can look into it.
function showProperties (e) {
//newData is actually setup via a form..
var newData={ name:'blah'};
me.renderer.invoke(function (elementRegistry, modeling) {
modeling.updateProperties(e.element,
newData
);
});
}
…
var eventBus = me.renderer.get('eventBus');
eventBus.on('element.dblclick', 5000,function (e)
{
if (showProperties(e)) {
e.preventDefault();
return false;
}
});
Now - I can see that the “name” property changes to “blah” - and if i go back in - the form has this filled in - but the diagram still has the name being blank… (and so no label)…
I also tried without the event handler :
function setName() {
me.renderer.invoke(function (elementRegistry, modeling)
{
var newData = { name: 'blah' };
var e=elementRegistry.get('StartEvent_1');
modeling.updateProperties(e,
newData
);
});
}
var downloadLink = $('#js-download-diagram');
var downloadSvgLink = $('#js-download-svg');
$('#js-setName').click(function(e) {
e.stopPropagation();
e.preventDefault();
renderer.invoke(function (elementRegistry, modeling)
{
var newData = { name: 'blah' };
var e=elementRegistry.get('StartEvent_1');
modeling.updateProperties(e,
newData
);
});
window.alert("Set Name");
});
Compiled & loaded - it updated the “name” (you can see if you double click - its set to blah) - but the name is not displayed.
(I cant see an obvious way to attach the files - but I hope thats clear enough ? )
You can always for fork projects on GitHub, make the changes and commit these changes onto your own fork or branch. It is much easier for us to look into these branches than to rebuild examples from instructions.
A workaround is setting the element labels hidden attribute to false yourself:
var element = event.element;
var labelElement = element.label;
// we are changing text, force rendering it
if (labelElement) {
labelElement.hidden = false;
}
// modeling ....
Cheers.
As a matter of interest - should I be setting “name” or businessObject.name ?
Only - setting “name”, then saving and reloading is causing issues with the display labels - they are in the wrong place - and “name” is no longer set on the node itself (but is set in the businessObject.name)…