提交 | 用户 | 时间
|
1ac2bc
|
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 |
* Execution listeners |
|
22 |
*/ |
|
23 |
|
|
24 |
var KisBpmEventListenersCtrl = [ '$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/event-listeners-popup.html?version=' + Date.now(), |
|
29 |
scope: $scope |
|
30 |
}; |
|
31 |
|
|
32 |
// Open the dialog |
|
33 |
$modal(opts); |
|
34 |
}]; |
|
35 |
|
|
36 |
//Need a separate controller for the modal window due to https://github.com/angular-ui/bootstrap/issues/259 |
|
37 |
// Will be fixed in a newer version of Angular UI |
|
38 |
var KisBpmEventListenersPopupCtrl = [ '$scope', '$q', '$translate', function($scope, $q, $translate) { |
|
39 |
|
|
40 |
// Put json representing form properties on scope |
|
41 |
if ($scope.property.value !== undefined && $scope.property.value !== null |
|
42 |
&& $scope.property.value.eventListeners !== undefined |
|
43 |
&& $scope.property.value.eventListeners !== null) { |
|
44 |
|
|
45 |
if ($scope.property.value.eventListeners.constructor == String) |
|
46 |
{ |
|
47 |
$scope.eventListeners = JSON.parse($scope.property.value.eventListeners); |
|
48 |
} |
|
49 |
else |
|
50 |
{ |
|
51 |
// Note that we clone the json object rather then setting it directly, |
|
52 |
// this to cope with the fact that the user can click the cancel button and no changes should have happened |
|
53 |
$scope.eventListeners = angular.copy($scope.property.value.eventListeners); |
|
54 |
} |
|
55 |
|
|
56 |
} else { |
|
57 |
$scope.eventListeners = []; |
|
58 |
} |
|
59 |
|
|
60 |
// Array to contain selected properties (yes - we only can select one, but ng-grid isn't smart enough) |
|
61 |
$scope.selectedListeners = []; |
|
62 |
$scope.translationsRetrieved = false; |
|
63 |
|
|
64 |
$scope.labels = {}; |
|
65 |
|
|
66 |
var eventPromise = $translate('PROPERTY.EXECUTIONLISTENERS.EVENT'); |
|
67 |
var implementationPromise = $translate('PROPERTY.EXECUTIONLISTENERS.FIELDS.IMPLEMENTATION'); |
|
68 |
var namePromise = $translate('PROPERTY.EXECUTIONLISTENERS.FIELDS.NAME'); |
|
69 |
|
|
70 |
$q.all([eventPromise, implementationPromise, namePromise]).then(function(results) { |
|
71 |
$scope.labels.eventLabel = results[0]; |
|
72 |
$scope.labels.implementationLabel = results[1]; |
|
73 |
$scope.labels.nameLabel = results[2]; |
|
74 |
$scope.translationsRetrieved = true; |
|
75 |
|
|
76 |
// Config for grid |
|
77 |
$scope.gridOptions = { |
|
78 |
data: 'eventListeners', |
|
79 |
enableRowReordering: true, |
|
80 |
headerRowHeight: 28, |
|
81 |
multiSelect: false, |
|
82 |
keepLastSelected : false, |
|
83 |
selectedItems: $scope.selectedListeners, |
|
84 |
afterSelectionChange: function (rowItem, event) { |
|
85 |
|
|
86 |
if ($scope.selectedListeners.length > 0) |
|
87 |
{ |
|
88 |
var fields = $scope.selectedListeners[0].fields; |
|
89 |
if (fields !== undefined && fields !== null) |
|
90 |
{ |
|
91 |
for (var i = 0; i < fields.length; i++) |
|
92 |
{ |
|
93 |
var field = fields[i]; |
|
94 |
if (field.stringValue !== undefined && field.stringValue !== '') |
|
95 |
{ |
|
96 |
field.implementation = field.stringValue; |
|
97 |
} |
|
98 |
else if (field.expression !== undefined && field.expression !== '') |
|
99 |
{ |
|
100 |
field.implementation = field.expression; |
|
101 |
} |
|
102 |
else if (field.string !== undefined && field.string !== '') |
|
103 |
{ |
|
104 |
field.implementation = field.string; |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
if (!$scope.selectedListeners[0].events || $scope.selectedListeners[0].events.length == 0) |
|
110 |
{ |
|
111 |
$scope.selectedListeners[0].events = [{event: ''}]; |
|
112 |
} |
|
113 |
} |
|
114 |
}, |
|
115 |
columnDefs: [{ field: 'event', displayName: $scope.labels.eventLabel }, |
|
116 |
{ field: 'implementation', displayName: $scope.labels.implementationLabel }] |
|
117 |
}; |
|
118 |
}); |
|
119 |
|
|
120 |
// Click handler for + button after enum value |
|
121 |
$scope.addEventValue = function(index) { |
|
122 |
$scope.selectedListeners[0].events.splice(index + 1, 0, {event: ''}); |
|
123 |
}; |
|
124 |
|
|
125 |
// Click handler for - button after enum value |
|
126 |
$scope.removeEventValue = function(index) { |
|
127 |
$scope.selectedListeners[0].events.splice(index, 1); |
|
128 |
$scope.listenerDetailsChanged(); |
|
129 |
}; |
|
130 |
|
|
131 |
$scope.listenerDetailsChanged = function() { |
|
132 |
var listener = $scope.selectedListeners[0]; |
|
133 |
if (listener.events) |
|
134 |
{ |
|
135 |
var eventText = ''; |
|
136 |
for (var i = 0; i < listener.events.length; i++) |
|
137 |
{ |
|
138 |
if (i > 0) |
|
139 |
{ |
|
140 |
eventText += ", "; |
|
141 |
} |
|
142 |
eventText += listener.events[i].event; |
|
143 |
} |
|
144 |
$scope.selectedListeners[0].event = eventText; |
|
145 |
} |
|
146 |
|
|
147 |
if (listener.rethrowEvent) |
|
148 |
{ |
|
149 |
var implementationText = ''; |
|
150 |
if (listener.rethrowType && listener.rethrowType.length > 0) |
|
151 |
{ |
|
152 |
if (listener.rethrowType === 'error' && listener.errorcode !== '') |
|
153 |
{ |
|
154 |
implementationText = "Rethrow as error " + listener.errorcode; |
|
155 |
} |
|
156 |
else if (listener.rethrowType === 'message' && listener.messagename !== '') |
|
157 |
{ |
|
158 |
implementationText = "Rethrow as message " + listener.messagename; |
|
159 |
} |
|
160 |
else if ((listener.rethrowType === 'signal' || listener.rethrowType === 'globalSignal') && listener.signalname !== '') |
|
161 |
{ |
|
162 |
implementationText = "Rethrow as signal " + listener.signalname; |
|
163 |
} |
|
164 |
} |
|
165 |
$scope.selectedListeners[0].implementation = implementationText; |
|
166 |
} |
|
167 |
else |
|
168 |
{ |
|
169 |
if ($scope.selectedListeners[0].className !== '') |
|
170 |
{ |
|
171 |
$scope.selectedListeners[0].implementation = $scope.selectedListeners[0].className; |
|
172 |
} |
|
173 |
else if ($scope.selectedListeners[0].delegateExpression !== '') |
|
174 |
{ |
|
175 |
$scope.selectedListeners[0].implementation = $scope.selectedListeners[0].delegateExpression; |
|
176 |
} |
|
177 |
else |
|
178 |
{ |
|
179 |
$scope.selectedListeners[0].implementation = ''; |
|
180 |
} |
|
181 |
} |
|
182 |
}; |
|
183 |
|
|
184 |
// Click handler for add button |
|
185 |
$scope.addNewListener = function() { |
|
186 |
$scope.eventListeners.push({ event : '', |
|
187 |
implementation : '', |
|
188 |
className : '', |
|
189 |
delegateExpression: '', |
|
190 |
retrowEvent: false}); |
|
191 |
}; |
|
192 |
|
|
193 |
// Click handler for remove button |
|
194 |
$scope.removeListener = function() { |
|
195 |
if ($scope.selectedListeners.length > 0) { |
|
196 |
var index = $scope.eventListeners.indexOf($scope.selectedListeners[0]); |
|
197 |
$scope.gridOptions.selectItem(index, false); |
|
198 |
$scope.eventListeners.splice(index, 1); |
|
199 |
|
|
200 |
$scope.selectedListeners.length = 0; |
|
201 |
if (index < $scope.eventListeners.length) { |
|
202 |
$scope.gridOptions.selectItem(index + 1, true); |
|
203 |
} else if ($scope.eventListeners.length > 0) { |
|
204 |
$scope.gridOptions.selectItem(index - 1, true); |
|
205 |
} |
|
206 |
} |
|
207 |
}; |
|
208 |
|
|
209 |
// Click handler for up button |
|
210 |
$scope.moveListenerUp = function() { |
|
211 |
if ($scope.selectedListeners.length > 0) { |
|
212 |
var index = $scope.eventListeners.indexOf($scope.selectedListeners[0]); |
|
213 |
if (index != 0) { // If it's the first, no moving up of course |
|
214 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
215 |
var temp = $scope.eventListeners[index]; |
|
216 |
$scope.eventListeners.splice(index, 1); |
|
217 |
$timeout(function(){ |
|
218 |
$scope.eventListeners.splice(index + -1, 0, temp); |
|
219 |
}, 100); |
|
220 |
|
|
221 |
} |
|
222 |
} |
|
223 |
}; |
|
224 |
|
|
225 |
// Click handler for down button |
|
226 |
$scope.moveListenerDown = function() { |
|
227 |
if ($scope.selectedListeners.length > 0) { |
|
228 |
var index = $scope.eventListeners.indexOf($scope.selectedListeners[0]); |
|
229 |
if (index != $scope.eventListeners.length - 1) { // If it's the last element, no moving down of course |
|
230 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
231 |
var temp = $scope.eventListeners[index]; |
|
232 |
$scope.eventListeners.splice(index, 1); |
|
233 |
$timeout(function(){ |
|
234 |
$scope.eventListeners.splice(index + 1, 0, temp); |
|
235 |
}, 100); |
|
236 |
|
|
237 |
} |
|
238 |
} |
|
239 |
}; |
|
240 |
|
|
241 |
// Click handler for save button |
|
242 |
$scope.save = function() { |
|
243 |
|
|
244 |
if ($scope.eventListeners.length > 0) { |
|
245 |
$scope.property.value = {}; |
|
246 |
$scope.property.value.eventListeners = $scope.eventListeners; |
|
247 |
} else { |
|
248 |
$scope.property.value = null; |
|
249 |
} |
|
250 |
|
|
251 |
$scope.updatePropertyInModel($scope.property); |
|
252 |
$scope.close(); |
|
253 |
}; |
|
254 |
|
|
255 |
$scope.cancel = function() { |
|
256 |
$scope.property.mode = 'read'; |
|
257 |
$scope.$hide(); |
|
258 |
}; |
|
259 |
|
|
260 |
// Close button handler |
|
261 |
$scope.close = function() { |
|
262 |
$scope.property.mode = 'read'; |
|
263 |
$scope.$hide(); |
|
264 |
}; |
|
265 |
|
|
266 |
}]; |