taron133
2020-10-26 aa8d874c8a3287d41d26566ae32b6ed8d4557ff9
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
 
function ModuleListContextPadProvider(contextPad, popupMenu, canvas, translate, eventBus) {
  this._contextPad = contextPad;
  this._popupMenu = popupMenu;
  this._canvas = canvas;
  this._translate = translate;
  this._eventBus = eventBus;
 
  contextPad.registerProvider(this);
}
 
 
ModuleListContextPadProvider.$inject = [
  'contextPad',
  'popupMenu',
  'canvas',
  'translate',
  'eventBus'
];
 
module.exports = ModuleListContextPadProvider;
 
 
ModuleListContextPadProvider.prototype.getContextPadEntries = function(element) {
  var self = this,
      translate = this._translate;
 
  var actions = {
    'set-modules': {
      group: 'edit',
      className: 'bpmn-icon-modules',
      title: translate('Set Modules'),
      action: {
        click: function(event, element) {
 
          var opts = getStartPosition(self._canvas, self._contextPad, element);
 
          // or fallback to current cursor position
          opts.cursor = {
            x: event.x,
            y: event.y
          };
 
          self._eventBus.fire('modulelist.element.click', { element, opts });
        }
      }
    }
  };
 
  return actions;
};
 
 
// helpers //////////////////////
 
function getStartPosition(canvas, contextPad, element) {
 
  var Y_OFFSET = 5;
 
  var diagramContainer = canvas.getContainer(),
      pad = contextPad.getPad(element).html;
 
  var diagramRect = diagramContainer.getBoundingClientRect(),
      padRect = pad.getBoundingClientRect();
 
  var top = padRect.top - diagramRect.top;
  var left = padRect.left - diagramRect.left;
 
  var pos = {
    x: left,
    y: top + padRect.height + Y_OFFSET
  };
 
  return pos;
}