提交 | 用户 | 时间
|
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 |
* Task listeners |
|
22 |
*/ |
|
23 |
|
|
24 |
var KisBpmTaskListenersCtrl = [ '$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/task-listeners-popup.html?version=' + Date.now(), |
|
29 |
scope: $scope |
|
30 |
}; |
|
31 |
|
|
32 |
// Open the dialog |
|
33 |
$modal(opts); |
|
34 |
}]; |
|
35 |
|
|
36 |
var KisBpmTaskListenersPopupCtrl = [ '$scope', '$q', '$translate', function($scope, $q, $translate) { |
|
37 |
|
|
38 |
// Put json representing form properties on scope |
|
39 |
if ($scope.property.value !== undefined && $scope.property.value !== null |
|
40 |
&& $scope.property.value.taskListeners !== undefined |
|
41 |
&& $scope.property.value.taskListeners !== null) { |
|
42 |
|
|
43 |
if ($scope.property.value.taskListeners.constructor == String) |
|
44 |
{ |
|
45 |
$scope.taskListeners = JSON.parse($scope.property.value.taskListeners); |
|
46 |
} |
|
47 |
else |
|
48 |
{ |
|
49 |
// Note that we clone the json object rather then setting it directly, |
|
50 |
// this to cope with the fact that the user can click the cancel button and no changes should have happened |
|
51 |
$scope.taskListeners = angular.copy($scope.property.value.taskListeners); |
|
52 |
} |
|
53 |
|
|
54 |
for (var i = 0; i < $scope.taskListeners.length; i++) |
|
55 |
{ |
|
56 |
var taskListener = $scope.taskListeners[i]; |
|
57 |
if (taskListener.className !== undefined && taskListener.className !== '') |
|
58 |
{ |
|
59 |
taskListener.implementation = taskListener.className; |
|
60 |
} |
|
61 |
else if (taskListener.expression !== undefined && taskListener.expression !== '') |
|
62 |
{ |
|
63 |
taskListener.implementation = taskListener.expression; |
|
64 |
} |
|
65 |
else if (taskListener.delegateExpression !== undefined && taskListener.delegateExpression !== '') |
|
66 |
{ |
|
67 |
taskListener.implementation = taskListener.delegateExpression; |
|
68 |
} |
|
69 |
} |
|
70 |
} else { |
|
71 |
$scope.taskListeners = []; |
|
72 |
} |
|
73 |
|
|
74 |
// Array to contain selected properties (yes - we only can select one, but ng-grid isn't smart enough) |
|
75 |
$scope.selectedListeners = []; |
|
76 |
$scope.selectedFields = []; |
|
77 |
$scope.translationsRetrieved = false; |
|
78 |
|
|
79 |
$scope.labels = {}; |
|
80 |
|
|
81 |
var eventPromise = $translate('PROPERTY.TASKLISTENERS.EVENT'); |
|
82 |
var implementationPromise = $translate('PROPERTY.TASKLISTENERS.FIELDS.IMPLEMENTATION'); |
|
83 |
var namePromise = $translate('PROPERTY.TASKLISTENERS.FIELDS.NAME'); |
|
84 |
|
|
85 |
$q.all([eventPromise, implementationPromise, namePromise]).then(function(results) { |
|
86 |
$scope.labels.eventLabel = results[0]; |
|
87 |
$scope.labels.implementationLabel = results[1]; |
|
88 |
$scope.labels.nameLabel = results[2]; |
|
89 |
$scope.translationsRetrieved = true; |
|
90 |
|
|
91 |
// Config for grid |
|
92 |
$scope.gridOptions = { |
|
93 |
data: 'taskListeners', |
|
94 |
enableRowReordering: true, |
|
95 |
headerRowHeight: 28, |
|
96 |
multiSelect: false, |
|
97 |
keepLastSelected : false, |
|
98 |
selectedItems: $scope.selectedListeners, |
|
99 |
afterSelectionChange: function (rowItem, event) { |
|
100 |
$scope.selectedFields.length = 0; |
|
101 |
if ($scope.selectedListeners.length > 0) |
|
102 |
{ |
|
103 |
var fields = $scope.selectedListeners[0].fields; |
|
104 |
if (fields !== undefined && fields !== null) |
|
105 |
{ |
|
106 |
for (var i = 0; i < fields.length; i++) |
|
107 |
{ |
|
108 |
var field = fields[i]; |
|
109 |
if (field.stringValue !== undefined && field.stringValue !== '') |
|
110 |
{ |
|
111 |
field.implementation = field.stringValue; |
|
112 |
} |
|
113 |
else if (field.expression !== undefined && field.expression !== '') |
|
114 |
{ |
|
115 |
field.implementation = field.expression; |
|
116 |
} |
|
117 |
else if (field.string !== undefined && field.string !== '') |
|
118 |
{ |
|
119 |
field.implementation = field.string; |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
}, |
|
125 |
columnDefs: [{ field: 'event', displayName: $scope.labels.eventLabel }, |
|
126 |
{ field: 'implementation', displayName: $scope.labels.implementationLabel}] |
|
127 |
}; |
|
128 |
|
|
129 |
// Config for field grid |
|
130 |
$scope.gridFieldOptions = { |
|
131 |
data: 'selectedListeners[0].fields', |
|
132 |
enableRowReordering: true, |
|
133 |
headerRowHeight: 28, |
|
134 |
multiSelect: false, |
|
135 |
keepLastSelected : false, |
|
136 |
selectedItems: $scope.selectedFields, |
|
137 |
columnDefs: [{ field: 'name', displayName: $scope.labels.name }, |
|
138 |
{ field: 'implementation', displayName: $scope.labels.implementationLabel}] |
|
139 |
}; |
|
140 |
}); |
|
141 |
|
|
142 |
$scope.listenerDetailsChanged = function() { |
|
143 |
if ($scope.selectedListeners[0].className !== '') |
|
144 |
{ |
|
145 |
$scope.selectedListeners[0].implementation = $scope.selectedListeners[0].className; |
|
146 |
} |
|
147 |
else if ($scope.selectedListeners[0].expression !== '') |
|
148 |
{ |
|
149 |
$scope.selectedListeners[0].implementation = $scope.selectedListeners[0].expression; |
|
150 |
} |
|
151 |
else if ($scope.selectedListeners[0].delegateExpression !== '') |
|
152 |
{ |
|
153 |
$scope.selectedListeners[0].implementation = $scope.selectedListeners[0].delegateExpression; |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
$scope.selectedListeners[0].implementation = ''; |
|
158 |
} |
|
159 |
}; |
|
160 |
|
|
161 |
// Click handler for add button |
|
162 |
$scope.addNewListener = function() { |
|
163 |
$scope.taskListeners.push({ event : 'create', |
|
164 |
implementation : '', |
|
165 |
className : '', |
|
166 |
expression: '', |
|
167 |
delegateExpression: ''}); |
|
168 |
}; |
|
169 |
|
|
170 |
// Click handler for remove button |
|
171 |
$scope.removeListener = function() { |
|
172 |
if ($scope.selectedListeners.length > 0) { |
|
173 |
var index = $scope.taskListeners.indexOf($scope.selectedListeners[0]); |
|
174 |
$scope.gridOptions.selectItem(index, false); |
|
175 |
$scope.taskListeners.splice(index, 1); |
|
176 |
|
|
177 |
$scope.selectedListeners.length = 0; |
|
178 |
if (index < $scope.taskListeners.length) { |
|
179 |
$scope.gridOptions.selectItem(index + 1, true); |
|
180 |
} else if ($scope.taskListeners.length > 0) { |
|
181 |
$scope.gridOptions.selectItem(index - 1, true); |
|
182 |
} |
|
183 |
} |
|
184 |
}; |
|
185 |
|
|
186 |
// Click handler for up button |
|
187 |
$scope.moveListenerUp = function() { |
|
188 |
if ($scope.selectedListeners.length > 0) { |
|
189 |
var index = $scope.taskListeners.indexOf($scope.selectedListeners[0]); |
|
190 |
if (index != 0) { // If it's the first, no moving up of course |
|
191 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
192 |
var temp = $scope.taskListeners[index]; |
|
193 |
$scope.taskListeners.splice(index, 1); |
|
194 |
$timeout(function(){ |
|
195 |
$scope.taskListeners.splice(index + -1, 0, temp); |
|
196 |
}, 100); |
|
197 |
|
|
198 |
} |
|
199 |
} |
|
200 |
}; |
|
201 |
|
|
202 |
// Click handler for down button |
|
203 |
$scope.moveListenerDown = function() { |
|
204 |
if ($scope.selectedListeners.length > 0) { |
|
205 |
var index = $scope.taskListeners.indexOf($scope.selectedListeners[0]); |
|
206 |
if (index != $scope.taskListeners.length - 1) { // If it's the last element, no moving down of course |
|
207 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
208 |
var temp = $scope.taskListeners[index]; |
|
209 |
$scope.taskListeners.splice(index, 1); |
|
210 |
$timeout(function(){ |
|
211 |
$scope.taskListeners.splice(index + 1, 0, temp); |
|
212 |
}, 100); |
|
213 |
|
|
214 |
} |
|
215 |
} |
|
216 |
}; |
|
217 |
|
|
218 |
$scope.fieldDetailsChanged = function() { |
|
219 |
if ($scope.selectedFields[0].stringValue != '') |
|
220 |
{ |
|
221 |
$scope.selectedFields[0].implementation = $scope.selectedFields[0].stringValue; |
|
222 |
} |
|
223 |
else if ($scope.selectedFields[0].expression != '') |
|
224 |
{ |
|
225 |
$scope.selectedFields[0].implementation = $scope.selectedFields[0].expression; |
|
226 |
} |
|
227 |
else if ($scope.selectedFields[0].string != '') |
|
228 |
{ |
|
229 |
$scope.selectedFields[0].implementation = $scope.selectedFields[0].string; |
|
230 |
} |
|
231 |
else |
|
232 |
{ |
|
233 |
$scope.selectedFields[0].implementation = ''; |
|
234 |
} |
|
235 |
}; |
|
236 |
|
|
237 |
// Click handler for add button |
|
238 |
$scope.addNewField = function() { |
|
239 |
if ($scope.selectedListeners.length > 0) |
|
240 |
{ |
|
241 |
if ($scope.selectedListeners[0].fields == undefined) |
|
242 |
{ |
|
243 |
$scope.selectedListeners[0].fields = []; |
|
244 |
} |
|
245 |
$scope.selectedListeners[0].fields.push({ name : 'fieldName', |
|
246 |
implementation : '', |
|
247 |
stringValue : '', |
|
248 |
expression: '', |
|
249 |
string: ''}); |
|
250 |
} |
|
251 |
}; |
|
252 |
|
|
253 |
// Click handler for remove button |
|
254 |
$scope.removeField = function() { |
|
255 |
if ($scope.selectedFields.length > 0) { |
|
256 |
var index = $scope.selectedListeners[0].fields.indexOf($scope.selectedFields[0]); |
|
257 |
$scope.gridFieldOptions.selectItem(index, false); |
|
258 |
$scope.selectedListeners[0].fields.splice(index, 1); |
|
259 |
|
|
260 |
$scope.selectedFields.length = 0; |
|
261 |
if (index < $scope.selectedListeners[0].fields.length) { |
|
262 |
$scope.gridFieldOptions.selectItem(index + 1, true); |
|
263 |
} else if ($scope.selectedListeners[0].fields.length > 0) { |
|
264 |
$scope.gridFieldOptions.selectItem(index - 1, true); |
|
265 |
} |
|
266 |
} |
|
267 |
}; |
|
268 |
|
|
269 |
// Click handler for up button |
|
270 |
$scope.moveFieldUp = function() { |
|
271 |
if ($scope.selectedFields.length > 0) { |
|
272 |
var index = $scope.selectedListeners[0].fields.indexOf($scope.selectedFields[0]); |
|
273 |
if (index != 0) { // If it's the first, no moving up of course |
|
274 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
275 |
var temp = $scope.selectedListeners[0].fields[index]; |
|
276 |
$scope.selectedListeners[0].fields.splice(index, 1); |
|
277 |
$timeout(function(){ |
|
278 |
$scope.selectedListeners[0].fields.splice(index + -1, 0, temp); |
|
279 |
}, 100); |
|
280 |
|
|
281 |
} |
|
282 |
} |
|
283 |
}; |
|
284 |
|
|
285 |
// Click handler for down button |
|
286 |
$scope.moveFieldDown = function() { |
|
287 |
if ($scope.selectedFields.length > 0) { |
|
288 |
var index = $scope.selectedListeners[0].fields.indexOf($scope.selectedFields[0]); |
|
289 |
if (index != $scope.selectedListeners[0].fields.length - 1) { // If it's the last element, no moving down of course |
|
290 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
291 |
var temp = $scope.selectedListeners[0].fields[index]; |
|
292 |
$scope.selectedListeners[0].fields.splice(index, 1); |
|
293 |
$timeout(function(){ |
|
294 |
$scope.selectedListeners[0].fields.splice(index + 1, 0, temp); |
|
295 |
}, 100); |
|
296 |
|
|
297 |
} |
|
298 |
} |
|
299 |
}; |
|
300 |
|
|
301 |
// Click handler for save button |
|
302 |
$scope.save = function() { |
|
303 |
|
|
304 |
if ($scope.taskListeners.length > 0) { |
|
305 |
$scope.property.value = {}; |
|
306 |
$scope.property.value.taskListeners = $scope.taskListeners; |
|
307 |
} else { |
|
308 |
$scope.property.value = null; |
|
309 |
} |
|
310 |
|
|
311 |
$scope.updatePropertyInModel($scope.property); |
|
312 |
$scope.close(); |
|
313 |
}; |
|
314 |
|
|
315 |
$scope.cancel = function() { |
|
316 |
$scope.close(); |
|
317 |
}; |
|
318 |
|
|
319 |
// Close button handler |
|
320 |
$scope.close = function() { |
|
321 |
$scope.property.mode = 'read'; |
|
322 |
$scope.$hide(); |
|
323 |
}; |
|
324 |
|
|
325 |
}]; |