customPalette.js 2.93 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* eslint-disable no-unused-vars */
export default class CustomPalette {
  constructor(bpmnFactory, create, elementFactory, palette, translate) {
    this.bpmnFactory = bpmnFactory
    this.create = create
    this.elementFactory = elementFactory
    this.translate = translate

    palette.registerProvider(this)
  }

  getPaletteEntries(element) {
    const { bpmnFactory, create, elementFactory, translate } = this
    function createTask() {
      return function(event) {
        const extensionElements = bpmnFactory.create('bpmn:ExtensionElements')
        const Properties = bpmnFactory.create('camunda:Properties')
        const Property = bpmnFactory.create('camunda:Property')
        Property.name = 'custom'
        Property.value = 'msgTask'
        Properties.values = [Property]
        extensionElements.values = [Properties]
        const businessObject = bpmnFactory.create('bpmn:ServiceTask', {
wangdanlei's avatar
wangdanlei committed
24
          'camunda:class': 'com.yonde.dex.wfc.engine.camunda.delegate.CamundaServiceTaskDelegate',
wangdanlei's avatar
wangdanlei committed
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
          extensionElements: extensionElements
        })

        const shape = elementFactory.createShape({
          type: 'bpmn:ServiceTask',
          businessObject: businessObject
        })
        create.start(event, shape)
      }
    }
    function createUserTask() {
      return function(event) {
        const extensionElements = bpmnFactory.create('bpmn:ExtensionElements')
        const Properties = bpmnFactory.create('camunda:Properties')
        const Property = bpmnFactory.create('camunda:Property')
        Property.name = 'relationInfo'
        Property.value = JSON.stringify({
          taskExtInfo: {
            custom: 'userTask'
          }
        })
        Properties.values = [Property]
        extensionElements.values = [Properties]
        const businessObject = bpmnFactory.create('bpmn:UserTask', {
          extensionElements: extensionElements
        })

        const shape = elementFactory.createShape({
          type: 'bpmn:UserTask',
          businessObject: businessObject
        })
        create.start(event, shape)
      }
    }
    return {
      'create.notify-task': {
        title: '消息通知', // 鼠标悬浮到节点上显示的文字
        className: 'icon-custom bpmn-icon-notify', // 样式名
        action: { // 操作该节点时会触发的事件,此时只注册一个拖动事件即可,否则拖动时没有效果
          dragstart: createTask(),
          click: createTask()
        }
      },
      'create.user-task': {
        title: '插入', // 鼠标悬浮到节点上显示的文字
        className: 'icon-custom bpmn-icon-custom-user-task', // 样式名
        action: { // 操作该节点时会触发的事件,此时只注册一个拖动事件即可,否则拖动时没有效果
          dragstart: createUserTask(),
          click: createUserTask()
        }
      }
    }
  }
}

CustomPalette.$inject = [
  'bpmnFactory',
  'create',
  'elementFactory',
  'palette',
  'translate'
]