提交 | 用户 | 时间
|
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 |
* Form Properties |
|
22 |
*/ |
|
23 |
|
|
24 |
var KisBpmFormPropertiesCtrl = [ '$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/form-properties-popup.html?version=' + Date.now(), |
|
29 |
scope: $scope |
|
30 |
}; |
|
31 |
|
|
32 |
// Open the dialog |
|
33 |
$modal(opts); |
|
34 |
}]; |
|
35 |
|
|
36 |
var KisBpmFormPropertiesPopupCtrl = ['$scope', '$q', '$translate', '$timeout', function($scope, $q, $translate, $timeout) { |
|
37 |
|
|
38 |
// Put json representing form properties on scope |
|
39 |
if ($scope.property.value !== undefined && $scope.property.value !== null |
|
40 |
&& $scope.property.value.formProperties !== undefined |
|
41 |
&& $scope.property.value.formProperties !== null) { |
|
42 |
// Note that we clone the json object rather then setting it directly, |
|
43 |
// this to cope with the fact that the user can click the cancel button and no changes should have happended |
|
44 |
$scope.formProperties = angular.copy($scope.property.value.formProperties); |
|
45 |
|
|
46 |
for (var i = 0; i < $scope.formProperties.length; i++) { |
|
47 |
var formProperty = $scope.formProperties[i]; |
|
48 |
if (formProperty.enumValues && formProperty.enumValues.length > 0) { |
|
49 |
for (var j = 0; j < formProperty.enumValues.length; j++) { |
|
50 |
var enumValue = formProperty.enumValues[j]; |
|
51 |
if (!enumValue.id && !enumValue.name && enumValue.value) { |
|
52 |
enumValue.id = enumValue.value; |
|
53 |
enumValue.name = enumValue.value; |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
} else { |
|
60 |
$scope.formProperties = []; |
|
61 |
} |
|
62 |
|
|
63 |
// Array to contain selected properties (yes - we only can select one, but ng-grid isn't smart enough) |
|
64 |
$scope.selectedProperties = []; |
|
65 |
$scope.selectedEnumValues = []; |
|
66 |
|
|
67 |
$scope.translationsRetrieved = false; |
|
68 |
|
|
69 |
$scope.labels = {}; |
|
70 |
|
|
71 |
var idPromise = $translate('PROPERTY.FORMPROPERTIES.ID'); |
|
72 |
var namePromise = $translate('PROPERTY.FORMPROPERTIES.NAME'); |
|
73 |
var typePromise = $translate('PROPERTY.FORMPROPERTIES.TYPE'); |
|
74 |
|
|
75 |
$q.all([idPromise, namePromise, typePromise]).then(function(results) { |
|
76 |
$scope.labels.idLabel = results[0]; |
|
77 |
$scope.labels.nameLabel = results[1]; |
|
78 |
$scope.labels.typeLabel = results[2]; |
|
79 |
$scope.translationsRetrieved = true; |
|
80 |
|
|
81 |
// Config for grid |
|
82 |
$scope.gridOptions = { |
|
83 |
data: 'formProperties', |
|
84 |
enableRowReordering: true, |
|
85 |
headerRowHeight: 28, |
|
86 |
multiSelect: false, |
|
87 |
keepLastSelected : false, |
|
88 |
selectedItems: $scope.selectedProperties, |
|
89 |
columnDefs: [{ field: 'id', displayName: $scope.labels.idLabel }, |
|
90 |
{ field: 'name', displayName: $scope.labels.nameLabel}, |
|
91 |
{ field: 'type', displayName: $scope.labels.typeLabel}] |
|
92 |
}; |
|
93 |
|
|
94 |
$scope.enumGridOptions = { |
|
95 |
data: 'selectedProperties[0].enumValues', |
|
96 |
enableRowReordering: true, |
|
97 |
headerRowHeight: 28, |
|
98 |
multiSelect: false, |
|
99 |
keepLastSelected : false, |
|
100 |
selectedItems: $scope.selectedEnumValues, |
|
101 |
columnDefs: [{ field: 'id', displayName: $scope.labels.idLabel }, |
|
102 |
{ field: 'name', displayName: $scope.labels.nameLabel}] |
|
103 |
} |
|
104 |
}); |
|
105 |
|
|
106 |
// Handler for when the value of the type dropdown changes |
|
107 |
$scope.propertyTypeChanged = function() { |
|
108 |
|
|
109 |
// Check date. If date, show date pattern |
|
110 |
if ($scope.selectedProperties[0].type === 'date') { |
|
111 |
$scope.selectedProperties[0].datePattern = 'MM-dd-yyyy hh:mm'; |
|
112 |
|
|
113 |
} else { |
|
114 |
delete $scope.selectedProperties[0].datePattern; |
|
115 |
} |
|
116 |
|
|
117 |
// Check enum. If enum, show list of options |
|
118 |
if ($scope.selectedProperties[0].type === 'enum') { |
|
119 |
$scope.selectedProperties[0].enumValues = [ {id: 'value1', name: 'Value 1'}, {id: 'value2', name: 'Value 2'}]; |
|
120 |
|
|
121 |
} else { |
|
122 |
delete $scope.selectedProperties[0].enumValues; |
|
123 |
} |
|
124 |
}; |
|
125 |
|
|
126 |
// Click handler for add button |
|
127 |
var propertyIndex = 1; |
|
128 |
$scope.addNewProperty = function() { |
|
129 |
$scope.formProperties.push({ id : 'new_property_' + propertyIndex++, |
|
130 |
name : '', |
|
131 |
type : 'string', |
|
132 |
readable: true, |
|
133 |
writable: true}); |
|
134 |
|
|
135 |
$timeout(function(){ |
|
136 |
$scope.gridOptions.selectItem($scope.formProperties.length - 1, true); |
|
137 |
}); |
|
138 |
}; |
|
139 |
|
|
140 |
// Click handler for remove button |
|
141 |
$scope.removeProperty = function() { |
|
142 |
if ($scope.selectedProperties.length > 0) { |
|
143 |
var index = $scope.formProperties.indexOf($scope.selectedProperties[0]); |
|
144 |
$scope.gridOptions.selectItem(index, false); |
|
145 |
$scope.formProperties.splice(index, 1); |
|
146 |
|
|
147 |
$scope.selectedProperties.length = 0; |
|
148 |
if (index < $scope.formProperties.length) { |
|
149 |
$scope.gridOptions.selectItem(index + 1, true); |
|
150 |
} else if ($scope.formProperties.length > 0) { |
|
151 |
$scope.gridOptions.selectItem(index - 1, true); |
|
152 |
} |
|
153 |
} |
|
154 |
}; |
|
155 |
|
|
156 |
// Click handler for up button |
|
157 |
$scope.movePropertyUp = function() { |
|
158 |
if ($scope.selectedProperties.length > 0) { |
|
159 |
var index = $scope.formProperties.indexOf($scope.selectedProperties[0]); |
|
160 |
if (index != 0) { // If it's the first, no moving up of course |
|
161 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
162 |
var temp = $scope.formProperties[index]; |
|
163 |
$scope.formProperties.splice(index, 1); |
|
164 |
$timeout(function(){ |
|
165 |
$scope.formProperties.splice(index + -1, 0, temp); |
|
166 |
}, 100); |
|
167 |
|
|
168 |
} |
|
169 |
} |
|
170 |
}; |
|
171 |
|
|
172 |
// Click handler for down button |
|
173 |
$scope.movePropertyDown = function() { |
|
174 |
if ($scope.selectedProperties.length > 0) { |
|
175 |
var index = $scope.formProperties.indexOf($scope.selectedProperties[0]); |
|
176 |
if (index != $scope.formProperties.length - 1) { // If it's the last element, no moving down of course |
|
177 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
178 |
var temp = $scope.formProperties[index]; |
|
179 |
$scope.formProperties.splice(index, 1); |
|
180 |
$timeout(function(){ |
|
181 |
$scope.formProperties.splice(index + 1, 0, temp); |
|
182 |
}, 100); |
|
183 |
|
|
184 |
} |
|
185 |
} |
|
186 |
}; |
|
187 |
|
|
188 |
$scope.addNewEnumValue = function() { |
|
189 |
if ($scope.selectedProperties.length > 0) { |
|
190 |
$scope.selectedProperties[0].enumValues.push({ id : '', name : ''}); |
|
191 |
} |
|
192 |
|
|
193 |
$timeout(function(){ |
|
194 |
$scope.enumGridOptions.selectItem($scope.selectedProperties[0].enumValues.length - 1, true); |
|
195 |
}); |
|
196 |
}; |
|
197 |
|
|
198 |
// Click handler for remove button |
|
199 |
$scope.removeEnumValue = function() { |
|
200 |
if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) { |
|
201 |
var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]); |
|
202 |
$scope.enumGridOptions.selectItem(index, false); |
|
203 |
$scope.selectedProperties[0].enumValues.splice(index, 1); |
|
204 |
|
|
205 |
$scope.selectedEnumValues.length = 0; |
|
206 |
if (index < $scope.selectedProperties[0].enumValues.length) { |
|
207 |
$timeout(function(){ |
|
208 |
$scope.enumGridOptions.selectItem(index + 1, true); |
|
209 |
}); |
|
210 |
|
|
211 |
} else if ($scope.selectedProperties[0].enumValues.length > 0) { |
|
212 |
$timeout(function(){ |
|
213 |
$scope.enumGridOptions.selectItem(index - 1, true); |
|
214 |
}); |
|
215 |
} |
|
216 |
} |
|
217 |
}; |
|
218 |
|
|
219 |
// Click handler for up button |
|
220 |
$scope.moveEnumValueUp = function() { |
|
221 |
if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) { |
|
222 |
var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]); |
|
223 |
if (index != 0) { // If it's the first, no moving up of course |
|
224 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
225 |
var temp = $scope.selectedProperties[0].enumValues[index]; |
|
226 |
$scope.selectedProperties[0].enumValues.splice(index, 1); |
|
227 |
$timeout(function(){ |
|
228 |
$scope.selectedProperties[0].enumValues.splice(index + -1, 0, temp); |
|
229 |
}); |
|
230 |
|
|
231 |
} |
|
232 |
} |
|
233 |
}; |
|
234 |
|
|
235 |
// Click handler for down button |
|
236 |
$scope.moveEnumValueDown = function() { |
|
237 |
if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) { |
|
238 |
var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]); |
|
239 |
if (index != $scope.selectedProperties[0].enumValues.length - 1) { // If it's the last element, no moving down of course |
|
240 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
241 |
var temp = $scope.selectedProperties[0].enumValues[index]; |
|
242 |
$scope.selectedProperties[0].enumValues.splice(index, 1); |
|
243 |
$timeout(function(){ |
|
244 |
$scope.selectedProperties[0].enumValues.splice(index + 1, 0, temp); |
|
245 |
}); |
|
246 |
|
|
247 |
} |
|
248 |
} |
|
249 |
}; |
|
250 |
|
|
251 |
// Click handler for save button |
|
252 |
$scope.save = function() { |
|
253 |
|
|
254 |
if ($scope.formProperties.length > 0) { |
|
255 |
$scope.property.value = {}; |
|
256 |
$scope.property.value.formProperties = $scope.formProperties; |
|
257 |
} else { |
|
258 |
$scope.property.value = null; |
|
259 |
} |
|
260 |
|
|
261 |
$scope.updatePropertyInModel($scope.property); |
|
262 |
$scope.close(); |
|
263 |
}; |
|
264 |
|
|
265 |
$scope.cancel = function() { |
|
266 |
$scope.$hide(); |
|
267 |
$scope.property.mode = 'read'; |
|
268 |
}; |
|
269 |
|
|
270 |
// Close button handler |
|
271 |
$scope.close = function() { |
|
272 |
$scope.$hide(); |
|
273 |
$scope.property.mode = 'read'; |
|
274 |
}; |
|
275 |
|
|
276 |
}]; |