图书馆智能管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
4.9 KiB

5 months ago
  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. var FLOWABLE = FLOWABLE || {};
  14. /** Inspired by https://github.com/krasimir/EventBus/blob/master/src/EventBus.js */
  15. FLOWABLE.eventBus = {
  16. /** Event fired when the editor is loaded and ready */
  17. EVENT_TYPE_EDITOR_READY: 'event-type-editor-ready',
  18. EVENT_TYPE_EDITOR_BOOTED: 'event-type-editor-booted',
  19. /** Event fired when a selection is made on the canvas. */
  20. EVENT_TYPE_SELECTION_CHANGE: 'event-type-selection-change',
  21. /** Event fired when a toolbar button has been clicked. */
  22. EVENT_TYPE_TOOLBAR_BUTTON_CLICKED: 'event-type-toolbar-button-clicked',
  23. /** Event fired when a stencil item is dropped on the canvas. */
  24. EVENT_TYPE_ITEM_DROPPED: 'event-type-item-dropped',
  25. /** Event fired when a property value is changed. */
  26. EVENT_TYPE_PROPERTY_VALUE_CHANGED: 'event-type-property-value-changed',
  27. /** Event fired on double click in canvas. */
  28. EVENT_TYPE_DOUBLE_CLICK: 'event-type-double-click',
  29. /** Event fired on a mouse out */
  30. EVENT_TYPE_MOUSE_OUT: 'event-type-mouse-out',
  31. /** Event fired on a mouse over */
  32. EVENT_TYPE_MOUSE_OVER: 'event-type-mouse-over',
  33. /** Event fired when a model is saved. */
  34. EVENT_TYPE_MODEL_SAVED: 'event-type-model-saved',
  35. /** Event fired when the quick menu buttons should be hidden. */
  36. EVENT_TYPE_HIDE_SHAPE_BUTTONS: 'event-type-hide-shape-buttons',
  37. /** Event fired when the validation popup should be shown. */
  38. EVENT_TYPE_SHOW_VALIDATION_POPUP: 'event-type-show-validation-popup',
  39. /** Event fired when a different process must be loaded. */
  40. EVENT_TYPE_NAVIGATE_TO_PROCESS: 'event-type-navigate-to-process',
  41. EVENT_TYPE_UNDO_REDO_RESET : 'event-type-undo-redo-reset',
  42. /** A mapping for storing the listeners*/
  43. listeners: {},
  44. /** The Oryx editor, which is stored locally to send events to */
  45. editor: null,
  46. /**
  47. * Add an event listener to the event bus, listening to the event with the provided type.
  48. * Type and callback are mandatory parameters.
  49. *
  50. * Provide scope parameter if it is important that the callback is executed
  51. * within a specific scope.
  52. */
  53. addListener: function (type, callback, scope) {
  54. // Add to the listeners map
  55. if (typeof this.listeners[type] !== "undefined") {
  56. this.listeners[type].push({scope: scope, callback: callback});
  57. } else {
  58. this.listeners[type] = [
  59. {scope: scope, callback: callback}
  60. ];
  61. }
  62. },
  63. /**
  64. * Removes the provided event listener.
  65. */
  66. removeListener: function (type, callback, scope) {
  67. if (typeof this.listeners[type] != "undefined") {
  68. var numOfCallbacks = this.listeners[type].length;
  69. var newArray = [];
  70. for (var i = 0; i < numOfCallbacks; i++) {
  71. var listener = this.listeners[type][i];
  72. if (listener.scope === scope && listener.callback === callback) {
  73. // Do nothing, this is the listener and doesn't need to survive
  74. } else {
  75. newArray.push(listener);
  76. }
  77. }
  78. this.listeners[type] = newArray;
  79. }
  80. },
  81. hasListener:function(type, callback, scope) {
  82. if(typeof this.listeners[type] != "undefined") {
  83. var numOfCallbacks = this.listeners[type].length;
  84. if(callback === undefined && scope === undefined){
  85. return numOfCallbacks > 0;
  86. }
  87. for(var i=0; i<numOfCallbacks; i++) {
  88. var listener = this.listeners[type][i];
  89. if(listener.scope == scope && listener.callback == callback) {
  90. return true;
  91. }
  92. }
  93. }
  94. return false;
  95. },
  96. /**
  97. * Dispatch an event to all event listeners registered to that specific type.
  98. */
  99. dispatch:function(type, event) {
  100. if(typeof this.listeners[type] != "undefined") {
  101. var numOfCallbacks = this.listeners[type].length;
  102. for(var i=0; i<numOfCallbacks; i++) {
  103. var listener = this.listeners[type][i];
  104. if(listener && listener.callback) {
  105. listener.callback.apply(listener.scope, [event]);
  106. }
  107. }
  108. }
  109. },
  110. dispatchOryxEvent: function(event, uiObject) {
  111. FLOWABLE.eventBus.editor.handleEvents(event, uiObject);
  112. }
  113. };