'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 } }); }; }