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