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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
 
var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;
 
 
function PopupMenuProvider(popupMenu, modeling, translate) {
  this._popupMenu = popupMenu;
  this._modeling = modeling;
  this._translate = translate;
  this._popupMenu.registerProvider('colorpicker', this);
}
 
 
PopupMenuProvider.$inject = [
  'popupMenu',
  'modeling',
  'translate'
];
module.exports = PopupMenuProvider;
 
 
PopupMenuProvider.prototype.getEntries = function(element) {
  var self = this,
      translate = this._translate;
 
  var colors = [
    {
      label: translate('Red'),
      hex: 'ff0000'
    }, {
      label: translate('Orange'),
      hex: 'ff7f00'
    }, {
      label: translate('Yellow'),
      hex: 'ffff00'
    }, {
      label: translate('Green'),
      hex: '00ff00'
    }, {
      label: translate('Blue'),
      hex: '0000ff'
    }, {
      label: translate('Indigo'),
      hex: '4b0082'
    }, {
      label: translate('Violet'),
      hex: '9400d3'
    }, {
      label: translate('Black'),
      hex: '000000'
    }
  ];
 
  var entries = colors.map(function(color) {
    return {
      label: color.label,
      id: color.label.toLowerCase() + '-color',
      className: 'color-icon-' + color.hex,
      action: createAction(self._modeling, element, '#' + color.hex)
    };
  });
 
  return entries;
};
 
 
PopupMenuProvider.prototype.getHeaderEntries = function(element) {
  var translate = this._translate;
  return [
    {
      label: translate('Clear'),
      id: 'clear-color',
      className: 'color-icon-clear',
      action: createAction(this._modeling, element)
    }
  ];
};
 
 
function createAction(modeling, element, newColor) {
  // set hex value to an element
  return function() {
    var bo = getBusinessObject(element);
    var di = bo.di;
 
    var currentColor = di.get('color:background-color');
 
    console.log('Replacing colors from/to: ', currentColor, newColor);
 
    var ns = (
      newColor ?
        'http://www.omg.org/spec/BPMN/non-normative/color/1.0' :
        undefined
    );
 
    modeling.updateProperties(element, {
      di: {
        'xmlns:color': ns,
        'color:background-color': newColor
      }
    });
 
  };
}