1
|
var wfFormFields = angular.module("wfFormFields", []);
|
2
|
|
3
|
wfFormFields.value('availableUis', {
|
4
|
LOCAL_DATABASE : [
|
5
|
{ label : 'show database', url : 'dbManager.do#/db/%s', paramRequired : true }
|
6
|
],
|
7
|
MDSTORE_ID : [
|
8
|
{ label : 'show records', url : '../inspector/mdstore.do?id=%s', paramRequired : true },
|
9
|
{ label : 'show profile', url : 'is#/profile/%s', paramRequired : true }
|
10
|
],
|
11
|
OBJECTSTORE_ID : [
|
12
|
{ label : 'show objects', url : '../inspector/objectstore.do?id=%s', paramRequired : true },
|
13
|
{ label : 'show profile', url : 'is#/profile/%s', paramRequired : true }
|
14
|
],
|
15
|
TRANSFORMATION_RULE_ID : [
|
16
|
{ label : 'register profile', url : 'is#/register', paramRequired : false },
|
17
|
{ label : 'show profile', url : 'is#/profile/%s', paramRequired : true }
|
18
|
],
|
19
|
CLEANER_RULE_ID : [
|
20
|
{ label : 'register profile', url : 'is#/register', paramRequired : false },
|
21
|
{ label : 'show profile', url : 'is#/profile/%s', paramRequired : true }
|
22
|
]
|
23
|
});
|
24
|
|
25
|
wfFormFields.service('cacheParameters', function () {
|
26
|
var validParamValuesCache = {};
|
27
|
|
28
|
return {
|
29
|
listValidValuesForUserParam: function (func, refresh) {
|
30
|
|
31
|
if (refresh || !validParamValuesCache[func]) {
|
32
|
try {
|
33
|
validParamValuesCache[func] = eval(func);
|
34
|
} catch (e) {
|
35
|
alert('Error evaluating function: ' + func);
|
36
|
validParamValuesCache[func] = [];
|
37
|
}
|
38
|
}
|
39
|
return validParamValuesCache[func];
|
40
|
}
|
41
|
};
|
42
|
});
|
43
|
|
44
|
wfFormFields.filter('sprintf', function () {
|
45
|
function parse(str) {
|
46
|
var args = [].slice.call(arguments, 1), i = 0;
|
47
|
return str.replace(/%s/g, function () {
|
48
|
return args[i++];
|
49
|
});
|
50
|
}
|
51
|
|
52
|
return function (str) {
|
53
|
return parse(str, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
|
54
|
};
|
55
|
});
|
56
|
|
57
|
|
58
|
wfFormFields.directive('bsHasError', function () {
|
59
|
return {
|
60
|
restrict: "A",
|
61
|
link: function (scope, element, attrs, ctrl) {
|
62
|
element.toggleClass('has-feedback', true);
|
63
|
var input = element.find('input[ng-model], select[ng-model]');
|
64
|
if (input) {
|
65
|
scope.$watch(function () {
|
66
|
if (input.controller('ngModel').$invalid) {
|
67
|
return 0;
|
68
|
} else if (!input.controller('ngModel').$viewValue) {
|
69
|
return 1;
|
70
|
} else {
|
71
|
return 2;
|
72
|
}
|
73
|
}, function (code) {
|
74
|
if (code < 0) return;
|
75
|
|
76
|
element.toggleClass('has-error', (code == 0));
|
77
|
element.toggleClass('has-warning', (code == 1));
|
78
|
element.toggleClass('has-success', (code == 2));
|
79
|
|
80
|
var feedback = element.find('.form-control-feedback');
|
81
|
if (feedback) {
|
82
|
feedback.toggleClass('glyphicon-remove', (code == 0));
|
83
|
feedback.toggleClass('glyphicon-warning-sign', (code == 1));
|
84
|
feedback.toggleClass('glyphicon-ok', (code == 2));
|
85
|
}
|
86
|
});
|
87
|
}
|
88
|
}
|
89
|
};
|
90
|
});
|
91
|
|
92
|
wfFormFields.directive('wfFormRowStatic', function (availableUis) {
|
93
|
return {
|
94
|
restrict: 'E',
|
95
|
scope: {
|
96
|
name : '@',
|
97
|
value : '@',
|
98
|
description : '@',
|
99
|
valueDescription : '@',
|
100
|
valueStyle : '@',
|
101
|
img : '@',
|
102
|
url : '@',
|
103
|
category : '@'
|
104
|
},
|
105
|
templateUrl: '/html/wf/wf-form-row-static.html',
|
106
|
link: function (scope) {
|
107
|
if (scope.category && availableUis[scope.category]) {
|
108
|
scope.links = availableUis[scope.category];
|
109
|
} else {
|
110
|
scope.links = [];
|
111
|
}
|
112
|
}
|
113
|
}
|
114
|
});
|
115
|
|
116
|
wfFormFields.directive('wfFormRowLabel', function () {
|
117
|
return {
|
118
|
restrict: 'E',
|
119
|
scope: {
|
120
|
name : '@',
|
121
|
value : '@',
|
122
|
description : '@',
|
123
|
date : '@',
|
124
|
labelClass : '@'
|
125
|
},
|
126
|
templateUrl: '/html/wf/wf-form-row-label.html'
|
127
|
}
|
128
|
});
|
129
|
|
130
|
wfFormFields.directive('wfFormRowStoreLink', function () {
|
131
|
return {
|
132
|
restrict: 'E',
|
133
|
scope: {
|
134
|
name : '@',
|
135
|
date : '@',
|
136
|
total : '@',
|
137
|
url : '@'
|
138
|
},
|
139
|
templateUrl: '/html/wf/wf-form-row-store-link.html'
|
140
|
}
|
141
|
});
|
142
|
|
143
|
|
144
|
wfFormFields.directive('wfFormRowSelect', function (cacheParameters, availableUis) {
|
145
|
return {
|
146
|
restrict: 'E',
|
147
|
templateUrl: '/html/wf/wf-form-row-select.html',
|
148
|
scope: {
|
149
|
name : '@',
|
150
|
value : '@',
|
151
|
mandatory : '@',
|
152
|
description : '@',
|
153
|
initValue : '@',
|
154
|
ngModel : '=',
|
155
|
ngOriginalModel : '=',
|
156
|
values : '=',
|
157
|
valuesFunction : '@',
|
158
|
category : '@'
|
159
|
},
|
160
|
link: function (scope) {
|
161
|
|
162
|
if (scope.category && availableUis[scope.category]) {
|
163
|
scope.links = availableUis[scope.category];
|
164
|
} else {
|
165
|
scope.links = [];
|
166
|
}
|
167
|
|
168
|
scope.finalValues = [];
|
169
|
|
170
|
scope.ngModel = scope.initValue;
|
171
|
scope.ngOriginalModel = scope.initValue;
|
172
|
|
173
|
scope.isRequired = (scope.mandatory == "true");
|
174
|
|
175
|
if (scope.values) {
|
176
|
scope.finalValues = scope.values;
|
177
|
} else if (scope.valuesFunction) {
|
178
|
scope.finalValues = cacheParameters.listValidValuesForUserParam(scope.valuesFunction);
|
179
|
}
|
180
|
}
|
181
|
}
|
182
|
});
|
183
|
|
184
|
wfFormFields.directive('wfFormRowMultiSelect', function (cacheParameters, availableUis) {
|
185
|
return {
|
186
|
restrict: 'E',
|
187
|
templateUrl: '/html/wf/wf-form-row-multi-select.html',
|
188
|
scope: {
|
189
|
name : '@',
|
190
|
value : '@',
|
191
|
mandatory : '@',
|
192
|
description : '@',
|
193
|
initValue : '@',
|
194
|
ngModel : '=',
|
195
|
ngOriginalModel : '=',
|
196
|
values : '=',
|
197
|
valuesFunction : '@',
|
198
|
category : '@'
|
199
|
},
|
200
|
link: function (scope) {
|
201
|
|
202
|
if (scope.category && availableUis[scope.category]) {
|
203
|
scope.links = availableUis[scope.category];
|
204
|
} else {
|
205
|
scope.links = [];
|
206
|
}
|
207
|
|
208
|
scope.finalValues = [];
|
209
|
|
210
|
scope.ngModel = scope.initValue.split(',');
|
211
|
scope.ngOriginalModel = scope.initValue.split(',');
|
212
|
|
213
|
scope.isRequired = (scope.mandatory == "true");
|
214
|
|
215
|
if (scope.values) {
|
216
|
scope.finalValues = scope.values;
|
217
|
} else if (scope.valuesFunction) {
|
218
|
scope.finalValues = cacheParameters.listValidValuesForUserParam(scope.valuesFunction);
|
219
|
}
|
220
|
|
221
|
scope.refreshValues = function() {
|
222
|
scope.finalValues = cacheParameters.listValidValuesForUserParam(scope.valuesFunction, true);
|
223
|
}
|
224
|
}
|
225
|
}
|
226
|
});
|
227
|
|
228
|
|
229
|
wfFormFields.directive('wfFormRowText', function (availableUis) {
|
230
|
return {
|
231
|
restrict: 'E',
|
232
|
templateUrl: '/html/wf/wf-form-row-text.html',
|
233
|
//require: '^ngModel',
|
234
|
scope: {
|
235
|
name : '@',
|
236
|
mandatory : '@',
|
237
|
description : '@',
|
238
|
initValue : '@',
|
239
|
type : '@',
|
240
|
regex : '@',
|
241
|
ngModel : '=',
|
242
|
ngOriginalModel : '=',
|
243
|
category : '@'
|
244
|
},
|
245
|
link: function (scope) {
|
246
|
|
247
|
if (scope.category && availableUis[scope.category]) {
|
248
|
scope.links = availableUis[scope.category];
|
249
|
} else {
|
250
|
scope.links = [];
|
251
|
}
|
252
|
|
253
|
scope.ngModel = "";
|
254
|
scope.ngOriginalModel = "";
|
255
|
|
256
|
if (scope.initValue) {
|
257
|
scope.ngModel = scope.initValue;
|
258
|
scope.ngOriginalModel = scope.initValue;
|
259
|
}
|
260
|
|
261
|
scope.isRequired = (scope.mandatory == "true");
|
262
|
|
263
|
if (scope.regex) {
|
264
|
scope.mypattern = new RegExp(scope.regex);
|
265
|
} else if (scope.type == 'boolean') {
|
266
|
scope.mypattern = new RegExp("^(true|false)$");
|
267
|
} else if (scope.type == 'int') {
|
268
|
scope.mypattern = new RegExp("^[-+]?[0-9]+$");
|
269
|
} else if (scope.type == 'float') {
|
270
|
scope.mypattern = new RegExp("^[-+]?[0-9]+(\.[0-9]+)?$");
|
271
|
} else if (scope.type == 'date') {
|
272
|
scope.mypattern = new RegExp("^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$");
|
273
|
} else {
|
274
|
scope.mypattern = new RegExp("^.+$");
|
275
|
}
|
276
|
}
|
277
|
}
|
278
|
});
|