ruoyi-vue-nocode/ruoyi-ui/ruoyi-bpmnjs/resources/properties-panel/provider/activiti/element-templates/cmd/index.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-08-11 16:10:41 +08:00
'use strict';
var ChangeElementTemplateHandler = require('./ChangeElementTemplateHandler');
var getTemplate = require('../Helper').getTemplate,
getDefaultTemplate = require('../Helper').getDefaultTemplate;
function registerHandlers(commandStack, elementTemplates, eventBus, elementRegistry) {
commandStack.registerHandler(
'propertiesPanel.activiti.changeTemplate',
ChangeElementTemplateHandler
);
// apply default element templates on shape creation
eventBus.on([ 'commandStack.shape.create.postExecuted' ], function(context) {
applyDefaultTemplate(context.context.shape, elementTemplates, commandStack);
});
// apply default element templates on connection creation
eventBus.on([ 'commandStack.connection.create.postExecuted' ], function(context) {
applyDefaultTemplate(context.context.connection, elementTemplates, commandStack);
});
}
registerHandlers.$inject = [ 'commandStack', 'elementTemplates', 'eventBus', 'elementRegistry' ];
module.exports = {
__init__: [ registerHandlers ]
};
function applyDefaultTemplate(element, elementTemplates, commandStack) {
if (!getTemplate(element, elementTemplates)
&& getDefaultTemplate(element, elementTemplates)) {
var command = 'propertiesPanel.activiti.changeTemplate';
var commandContext = {
element: element,
newTemplate: getDefaultTemplate(element, elementTemplates)
};
commandStack.execute(command, commandContext);
}
}