CustomContextPad.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. export default class CustomContextPad {
  2. constructor(config, contextPad, create, elementFactory, injector, translate) {
  3. this.create = create;
  4. this.elementFactory = elementFactory;
  5. this.translate = translate;
  6. //自动摆放位置
  7. if (config.autoPlace !== false) {
  8. this.autoPlace = injector.get('autoPlace', false);
  9. }
  10. //注册工具
  11. contextPad.registerProvider(this);
  12. }
  13. getContextPadEntries(element) {
  14. const {
  15. autoPlace,
  16. create,
  17. elementFactory,
  18. translate
  19. } = this;
  20. function appendUserTask(event, element) {
  21. if (autoPlace) {
  22. const shape = elementFactory.createShape({ type: 'bpmn:UserTask' });
  23. autoPlace.append(element, shape);
  24. } else {
  25. appendUserTaskStart(event, element);
  26. }
  27. }
  28. function appendUserTaskStart(event) {
  29. const shape = elementFactory.createShape({ type: 'bpmn:UserTask' });
  30. create.start(event, shape, element);
  31. }
  32. function appendCallActivityStart(event) {
  33. const shape = elementFactory.createShape({ type: 'bpmn:CallActivity' });
  34. create.start(event, shape, element);
  35. }
  36. function appendCallActivity(event, element) {
  37. if (autoPlace) {
  38. const shape = elementFactory.createShape({ type: 'bpmn:CallActivity' });
  39. autoPlace.append(element, shape);
  40. } else {
  41. appendCallActivityStart(event, element);
  42. }
  43. }
  44. return {
  45. 'append.user-task': {
  46. group: 'model',
  47. className: 'bpmn-icon-user-task',
  48. title: translate('Append ServiceTask'),
  49. action: {
  50. click: appendUserTask,
  51. dragstart: appendUserTaskStart
  52. }
  53. },
  54. 'append.call-activity':{
  55. group: 'model',
  56. className: 'bpmn-icon-call-activity',
  57. title: translate('Append CallActivity'),
  58. action: {
  59. click: appendCallActivity,
  60. dragstart: appendCallActivityStart
  61. }
  62. }
  63. };
  64. }
  65. }
  66. CustomContextPad.$inject = [
  67. 'config',
  68. 'contextPad',
  69. 'create',
  70. 'elementFactory',
  71. 'injector',
  72. 'translate'
  73. ];