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
|
|
|
*
|
|
|
|
* @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-09-08 17:03:39 +00:00
|
|
|
var label = LabelUtil.setLabel(element, text);
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-09-08 17:03:39 +00:00
|
|
|
eventBus.fire('element.changed', { element: label });
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|