提交 | 用户 | 时间
|
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 KisBpmFieldsCtrl = [ '$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/fields-popup.html', |
|
29 |
scope: $scope |
|
30 |
}; |
|
31 |
|
|
32 |
// Open the dialog |
|
33 |
$modal(opts); |
|
34 |
}]; |
|
35 |
|
|
36 |
var KisBpmFieldsPopupCtrl = [ '$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.fields !== undefined |
|
41 |
&& $scope.property.value.fields !== 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 happened |
|
44 |
$scope.fields = angular.copy($scope.property.value.fields); |
|
45 |
|
|
46 |
for (var i = 0; i < $scope.fields.length; i++) |
|
47 |
{ |
|
48 |
var field = $scope.fields[i]; |
|
49 |
if (field.stringValue !== undefined && field.stringValue !== '') |
|
50 |
{ |
|
51 |
field.implementation = field.stringValue; |
|
52 |
} |
|
53 |
else if (field.expression !== undefined && field.expression !== '') |
|
54 |
{ |
|
55 |
field.implementation = field.expression; |
|
56 |
} |
|
57 |
else if (field.string !== undefined && field.string !== '') |
|
58 |
{ |
|
59 |
field.implementation = field.string; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
} else { |
|
64 |
$scope.fields = []; |
|
65 |
} |
|
66 |
|
|
67 |
// Array to contain selected properties (yes - we only can select one, but ng-grid isn't smart enough) |
|
68 |
$scope.selectedFields = []; |
|
69 |
$scope.translationsRetrieved = false; |
|
70 |
$scope.labels = {}; |
|
71 |
|
|
72 |
var namePromise = $translate('PROPERTY.FIELDS.NAME'); |
|
73 |
var implementationPromise = $translate('PROPERTY.FIELDS.IMPLEMENTATION'); |
|
74 |
|
|
75 |
$q.all([namePromise, implementationPromise]).then(function(results) { |
|
76 |
$scope.labels.nameLabel = results[0]; |
|
77 |
$scope.labels.implementationLabel = results[1]; |
|
78 |
$scope.translationsRetrieved = true; |
|
79 |
|
|
80 |
// Config for grid |
|
81 |
$scope.gridOptions = { |
|
82 |
data: 'fields', |
|
83 |
enableRowReordering: true, |
|
84 |
headerRowHeight: 28, |
|
85 |
multiSelect: false, |
|
86 |
keepLastSelected: false, |
|
87 |
selectedItems: $scope.selectedFields, |
|
88 |
columnDefs: [{field: 'name', displayName: $scope.labels.nameLabel}, |
|
89 |
{field: 'implementation', displayName: $scope.labels.implementationLabel}] |
|
90 |
}; |
|
91 |
}); |
|
92 |
|
|
93 |
$scope.fieldDetailsChanged = function() { |
|
94 |
if ($scope.selectedFields[0].stringValue != '') |
|
95 |
{ |
|
96 |
$scope.selectedFields[0].implementation = $scope.selectedFields[0].stringValue; |
|
97 |
} |
|
98 |
else if ($scope.selectedFields[0].expression != '') |
|
99 |
{ |
|
100 |
$scope.selectedFields[0].implementation = $scope.selectedFields[0].expression; |
|
101 |
} |
|
102 |
else if ($scope.selectedFields[0].string != '') |
|
103 |
{ |
|
104 |
$scope.selectedFields[0].implementation = $scope.selectedFields[0].string; |
|
105 |
} |
|
106 |
else |
|
107 |
{ |
|
108 |
$scope.selectedFields[0].implementation = ''; |
|
109 |
} |
|
110 |
}; |
|
111 |
|
|
112 |
// Click handler for add button |
|
113 |
$scope.addNewField = function() { |
|
114 |
$scope.fields.push({ name : 'fieldName', |
|
115 |
implementation : '', |
|
116 |
stringValue : '', |
|
117 |
expression: '', |
|
118 |
string: ''}); |
|
119 |
}; |
|
120 |
|
|
121 |
// Click handler for remove button |
|
122 |
$scope.removeField = function() { |
|
123 |
if ($scope.selectedFields.length > 0) { |
|
124 |
var index = $scope.fields.indexOf($scope.selectedFields[0]); |
|
125 |
$scope.gridOptions.selectItem(index, false); |
|
126 |
$scope.fields.splice(index, 1); |
|
127 |
|
|
128 |
$scope.selectedFields.length = 0; |
|
129 |
if (index < $scope.fields.length) { |
|
130 |
$scope.gridOptions.selectItem(index + 1, true); |
|
131 |
} else if ($scope.fields.length > 0) { |
|
132 |
$scope.gridOptions.selectItem(index - 1, true); |
|
133 |
} |
|
134 |
} |
|
135 |
}; |
|
136 |
|
|
137 |
// Click handler for up button |
|
138 |
$scope.moveFieldUp = function() { |
|
139 |
if ($scope.selectedFields.length > 0) { |
|
140 |
var index = $scope.fields.indexOf($scope.selectedFields[0]); |
|
141 |
if (index != 0) { // If it's the first, no moving up of course |
|
142 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
143 |
var temp = $scope.fields[index]; |
|
144 |
$scope.fields.splice(index, 1); |
|
145 |
$timeout(function(){ |
|
146 |
$scope.fields.splice(index + -1, 0, temp); |
|
147 |
}, 100); |
|
148 |
|
|
149 |
} |
|
150 |
} |
|
151 |
}; |
|
152 |
|
|
153 |
// Click handler for down button |
|
154 |
$scope.moveFieldDown = function() { |
|
155 |
if ($scope.selectedFields.length > 0) { |
|
156 |
var index = $scope.fields.indexOf($scope.selectedFields[0]); |
|
157 |
if (index != $scope.fields.length - 1) { // If it's the last element, no moving down of course |
|
158 |
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272 |
|
159 |
var temp = $scope.fields[index]; |
|
160 |
$scope.fields.splice(index, 1); |
|
161 |
$timeout(function(){ |
|
162 |
$scope.fields.splice(index + 1, 0, temp); |
|
163 |
}, 100); |
|
164 |
|
|
165 |
} |
|
166 |
} |
|
167 |
}; |
|
168 |
|
|
169 |
// Click handler for save button |
|
170 |
$scope.save = function() { |
|
171 |
|
|
172 |
if ($scope.fields.length > 0) { |
|
173 |
$scope.property.value = {}; |
|
174 |
$scope.property.value.fields = $scope.fields; |
|
175 |
} else { |
|
176 |
$scope.property.value = null; |
|
177 |
} |
|
178 |
|
|
179 |
$scope.updatePropertyInModel($scope.property); |
|
180 |
$scope.close(); |
|
181 |
}; |
|
182 |
|
|
183 |
$scope.cancel = function() { |
|
184 |
$scope.close(); |
|
185 |
}; |
|
186 |
|
|
187 |
// Close button handler |
|
188 |
$scope.close = function() { |
|
189 |
$scope.property.mode = 'read'; |
|
190 |
$scope.$hide(); |
|
191 |
}; |
|
192 |
}]; |