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
|
|
|
/**
|
|
|
|
* A handler that updates the text a BPMN element.
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
|
|
|
*/
|
2014-07-16 14:15:23 +00:00
|
|
|
function UpdateTextHandler(eventBus) {
|
2014-06-11 13:08:45 +00:00
|
|
|
|
|
|
|
function setText(element, text) {
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
var semantic = element.businessObject;
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
LabelUtil.setLabel(semantic, text);
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
eventBus.fire('element.changed', { element: element.label || element });
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function execute(ctx) {
|
2014-08-04 07:32:36 +00:00
|
|
|
ctx.oldLabel = LabelUtil.getLabel(ctx.element.businessObject);
|
|
|
|
setText(ctx.element, ctx.newLabel);
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function revert(ctx) {
|
2014-08-04 07:32:36 +00:00
|
|
|
setText(ctx.element, ctx.oldLabel);
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function canExecute(ctx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// API
|
|
|
|
|
|
|
|
this.execute = execute;
|
|
|
|
this.revert = revert;
|
|
|
|
|
|
|
|
this.canExecute = canExecute;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
UpdateTextHandler.$inject = [ 'eventBus' ];
|
2014-06-11 13:08:45 +00:00
|
|
|
|
|
|
|
module.exports = UpdateTextHandler;
|