Digital Office Automation System Backend
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

toolbar-controller.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Activiti Modeler component part of the Activiti project
  3. * Copyright 2005-2014 Alfresco Software, Ltd. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. 'use strict';
  19. angular.module('activitiModeler')
  20. .controller('ToolbarController', ['$scope', '$http', '$modal', '$q', '$rootScope', '$translate', '$location', function ($scope, $http, $modal, $q, $rootScope, $translate, $location) {
  21. $scope.editorFactory.promise.then(function () {
  22. $scope.items = KISBPM.TOOLBAR_CONFIG.items;
  23. });
  24. $scope.secondaryItems = KISBPM.TOOLBAR_CONFIG.secondaryItems;
  25. // Call configurable click handler (From http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string)
  26. var executeFunctionByName = function(functionName, context /*, args */) {
  27. var args = Array.prototype.slice.call(arguments).splice(2);
  28. var namespaces = functionName.split(".");
  29. var func = namespaces.pop();
  30. for(var i = 0; i < namespaces.length; i++) {
  31. context = context[namespaces[i]];
  32. }
  33. return context[func].apply(this, args);
  34. };
  35. // Click handler for toolbar buttons
  36. $scope.toolbarButtonClicked = function(buttonIndex) {
  37. // Default behaviour
  38. var buttonClicked = $scope.items[buttonIndex];
  39. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  40. executeFunctionByName(buttonClicked.action, window, services);
  41. // Other events
  42. var event = {
  43. type : KISBPM.eventBus.EVENT_TYPE_TOOLBAR_BUTTON_CLICKED,
  44. toolbarItem : buttonClicked
  45. };
  46. KISBPM.eventBus.dispatch(event.type, event);
  47. };
  48. // Click handler for secondary toolbar buttons
  49. $scope.toolbarSecondaryButtonClicked = function(buttonIndex) {
  50. var buttonClicked = $scope.secondaryItems[buttonIndex];
  51. var services = { '$scope' : $scope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate, '$location': $location};
  52. executeFunctionByName(buttonClicked.action, window, services);
  53. };
  54. /* Key bindings */
  55. Mousetrap.bind(['command+z', 'ctrl+z'], function(e) {
  56. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  57. KISBPM.TOOLBAR.ACTIONS.undo(services);
  58. return false;
  59. });
  60. Mousetrap.bind(['command+y', 'ctrl+y'], function(e) {
  61. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  62. KISBPM.TOOLBAR.ACTIONS.redo(services);
  63. return false;
  64. });
  65. Mousetrap.bind(['command+c', 'ctrl+c'], function(e) {
  66. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  67. KISBPM.TOOLBAR.ACTIONS.copy(services);
  68. return false;
  69. });
  70. Mousetrap.bind(['command+v', 'ctrl+v'], function(e) {
  71. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  72. KISBPM.TOOLBAR.ACTIONS.paste(services);
  73. return false;
  74. });
  75. Mousetrap.bind(['del'], function(e) {
  76. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  77. KISBPM.TOOLBAR.ACTIONS.deleteItem(services);
  78. return false;
  79. });
  80. /* Undo logic */
  81. $scope.undoStack = [];
  82. $scope.redoStack = [];
  83. $scope.editorFactory.promise.then(function() {
  84. // Catch all command that are executed and store them on the respective stacks
  85. $scope.editor.registerOnEvent(ORYX.CONFIG.EVENT_EXECUTE_COMMANDS, function( evt ){
  86. // If the event has commands
  87. if( !evt.commands ){ return; }
  88. $scope.undoStack.push( evt.commands );
  89. $scope.redoStack = [];
  90. for(var i = 0; i < $scope.items.length; i++)
  91. {
  92. var item = $scope.items[i];
  93. if (item.action === 'KISBPM.TOOLBAR.ACTIONS.undo')
  94. {
  95. item.enabled = true;
  96. }
  97. else if (item.action === 'KISBPM.TOOLBAR.ACTIONS.redo')
  98. {
  99. item.enabled = false;
  100. }
  101. }
  102. // Update
  103. $scope.editor.getCanvas().update();
  104. $scope.editor.updateSelection();
  105. });
  106. });
  107. // Handle enable/disable toolbar buttons
  108. $scope.editorFactory.promise.then(function() {
  109. $scope.editor.registerOnEvent(ORYX.CONFIG.EVENT_SELECTION_CHANGED, function( evt ){
  110. var elements = evt.elements;
  111. for(var i = 0; i < $scope.items.length; i++)
  112. {
  113. var item = $scope.items[i];
  114. if (item.enabledAction && item.enabledAction === 'element')
  115. {
  116. var minLength = 1;
  117. if(item.minSelectionCount) {
  118. minLength = item.minSelectionCount;
  119. }
  120. if (elements.length >= minLength && !item.enabled) {
  121. $scope.safeApply(function () {
  122. item.enabled = true;
  123. });
  124. }
  125. else if (elements.length == 0 && item.enabled) {
  126. $scope.safeApply(function () {
  127. item.enabled = false;
  128. });
  129. }
  130. }
  131. }
  132. });
  133. });
  134. }]);