properties-sequenceflow-order-controller.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /*
  19. * Sequence flow order controller
  20. */
  21. var KisBpmSequenceFlowOrderCtrl = [ '$scope', '$modal', '$timeout', '$translate', function($scope, $modal, $timeout, $translate) {
  22. // Config for the modal window
  23. var opts = {
  24. template: 'editor-app/configuration/properties/sequenceflow-order-popup.html?version=' + Date.now(),
  25. scope: $scope
  26. };
  27. $modal(opts);
  28. }];
  29. var KisBpmSequenceFlowOrderPopupCtrl = ['$scope', '$translate', function($scope, $translate) {
  30. // Find the outgoing sequence flow of the current selected shape
  31. var outgoingSequenceFlow = [];
  32. var selectedShape = $scope.selectedShape;
  33. if (selectedShape) {
  34. var outgoingNodes = selectedShape.getOutgoingShapes();
  35. for (var i=0; i<outgoingNodes.length; i++) {
  36. if (outgoingNodes[i].getStencil().title() === 'Sequence flow') {
  37. var targetActivity = outgoingNodes[i].getTarget();
  38. // We need the resourceId of a sequence flow, not the id because that will change with every editor load
  39. outgoingSequenceFlow.push({
  40. id : outgoingNodes[i].resourceId,
  41. targetTitle : targetActivity.properties['oryx-name'],
  42. targetType : targetActivity.getStencil().title()
  43. });
  44. }
  45. }
  46. } else {
  47. console.log('Programmatic error: no selected shape found');
  48. }
  49. // Now we can apply the order which was (possibly) previously saved
  50. var orderedOutgoingSequenceFlow = [];
  51. if ($scope.property.value && $scope.property.value.sequenceFlowOrder) {
  52. var sequenceFlowOrderList = $scope.property.value.sequenceFlowOrder;
  53. // Loop the list of sequence flow that was saved in the json model and match them with the outgoing sequence flow found above
  54. for (var flowIndex=0; flowIndex < sequenceFlowOrderList.length; flowIndex++) {
  55. // find the sequence flow in the outgoing sequence flows.
  56. for (var outgoingFlowIndex=0; outgoingFlowIndex < outgoingSequenceFlow.length; outgoingFlowIndex++) {
  57. if (outgoingSequenceFlow[outgoingFlowIndex].id === sequenceFlowOrderList[flowIndex]) {
  58. orderedOutgoingSequenceFlow.push(outgoingSequenceFlow[outgoingFlowIndex]);
  59. outgoingSequenceFlow.splice(outgoingFlowIndex, 1);
  60. break;
  61. }
  62. }
  63. }
  64. // Now all the matching sequence flow we're removed from the outgoing sequence flow list
  65. // We can simply apply the remaining ones (these are new vs. the time when the values were saved to the model)
  66. orderedOutgoingSequenceFlow = orderedOutgoingSequenceFlow.concat(outgoingSequenceFlow);
  67. } else {
  68. orderedOutgoingSequenceFlow = outgoingSequenceFlow;
  69. }
  70. // Now we can put it on the scope
  71. $scope.outgoingSequenceFlow = orderedOutgoingSequenceFlow;
  72. // Move up click handler
  73. $scope.moveUp = function(index) {
  74. var temp = $scope.outgoingSequenceFlow[index];
  75. $scope.outgoingSequenceFlow[index] = $scope.outgoingSequenceFlow[index - 1];
  76. $scope.outgoingSequenceFlow[index - 1] = temp;
  77. };
  78. // Move down click handler
  79. $scope.moveDown = function(index) {
  80. var temp = $scope.outgoingSequenceFlow[index];
  81. $scope.outgoingSequenceFlow[index] = $scope.outgoingSequenceFlow[index + 1];
  82. $scope.outgoingSequenceFlow[index + 1] = temp;
  83. };
  84. // Save click handler
  85. $scope.save = function() {
  86. if ($scope.outgoingSequenceFlow.length > 0) {
  87. $scope.property.value = {};
  88. $scope.property.value.sequenceFlowOrder = [];
  89. for (var flowIndex=0; flowIndex < $scope.outgoingSequenceFlow.length; flowIndex++) {
  90. $scope.property.value.sequenceFlowOrder.push($scope.outgoingSequenceFlow[flowIndex].id);
  91. }
  92. } else {
  93. $scope.property.value = null;
  94. }
  95. $scope.updatePropertyInModel($scope.property);
  96. $scope.close();
  97. };
  98. // Cancel click handler
  99. $scope.cancel = function() {
  100. $scope.close();
  101. };
  102. // Close button handler
  103. $scope.close = function() {
  104. $scope.property.mode = 'read';
  105. $scope.$hide();
  106. };
  107. }];