shikeying
2023-03-17 8c1a723d62a6aa5d6266ca613ae4eb77c789db06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'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);
  }
}