2014-06-11 13:08:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
var LabelUtil = require('../LabelUtil');
|
|
|
|
|
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
/**
|
2014-09-11 14:44:56 +00:00
|
|
|
* A handler that updates the text of a BPMN element.
|
2014-06-11 13:08:45 +00:00
|
|
|
*/
|
2016-05-18 05:54:58 +00:00
|
|
|
function UpdateLabelHandler() {
|
2016-03-03 16:09:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the label and return the changed elements.
|
|
|
|
*
|
|
|
|
* Element parameter can be label itself or connection (i.e. sequence flow).
|
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
* @param {String} text
|
|
|
|
*/
|
2014-06-11 13:08:45 +00:00
|
|
|
function setText(element, text) {
|
|
|
|
|
2016-03-03 16:09:43 +00:00
|
|
|
// external label if present
|
|
|
|
var label = element.label || element;
|
|
|
|
|
|
|
|
var labelTarget = element.labelTarget || element;
|
|
|
|
|
|
|
|
LabelUtil.setLabel(label, text, labelTarget !== label);
|
|
|
|
|
|
|
|
return [ label, labelTarget ];
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function execute(ctx) {
|
2014-09-08 17:03:39 +00:00
|
|
|
ctx.oldLabel = LabelUtil.getLabel(ctx.element);
|
2014-09-11 14:44:56 +00:00
|
|
|
return setText(ctx.element, ctx.newLabel);
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function revert(ctx) {
|
2014-09-11 14:44:56 +00:00
|
|
|
return setText(ctx.element, ctx.oldLabel);
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 14:03:11 +00:00
|
|
|
// API
|
2016-05-18 05:54:58 +00:00
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
this.execute = execute;
|
|
|
|
this.revert = revert;
|
|
|
|
}
|
|
|
|
|
2016-05-18 05:54:58 +00:00
|
|
|
module.exports = UpdateLabelHandler;
|