Project

General

Profile

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 : 'isManager.do#/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 : 'isManager.do#/profile/%s',      paramRequired : true }
14
	  ],
15
	TRANSFORMATION_RULE_ID : [
16
		{ label : 'register profile', url : 'isManager.do#/register',   paramRequired : false },
17
		{ label : 'show profile',     url : 'isManager.do#/profile/%s', paramRequired : true }
18
	],
19
	CLEANER_RULE_ID : [
20
		{ label : 'register profile', url : 'isManager.do#/register',   paramRequired : false },
21
		{ label : 'show profile',     url : 'isManager.do#/profile/%s', paramRequired : true }
22
	]
23
});
24

    
25
wfFormFields.service('cacheParameters', function () {
26
	var validParamValuesCache = {};
27
	
28
	return {
29
		listValidValuesForUserParam: function (func, refresh) {
30
			if (refresh || !validParamValuesCache[func]) {
31
				try {
32
					validParamValuesCache[func] = eval(func);
33
				} catch (e) {
34
					alert('Error evaluating function: ' + func);
35
					validParamValuesCache[func] = [];
36
				}
37
			}
38
			return validParamValuesCache[func];
39
		}
40
	};
41
});
42

    
43
wfFormFields.filter('sprintf', function () {
44
	function parse(str) {
45
		var args = [].slice.call(arguments, 1), i = 0;
46
		return str.replace(/%s/g, function () {
47
			return args[i++];
48
		});
49
	}
50

    
51
	return function (str) {
52
		return parse(str, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
53
	};
54
});
55

    
56

    
57
wfFormFields.directive('bsHasError', function () {
58
	return {
59
		restrict: "A",
60
		link: function (scope, element, attrs, ctrl) {
61
			element.toggleClass('has-feedback', true);
62
			var input = element.find('input[ng-model], select[ng-model]');
63
			if (input) {
64
				scope.$watch(function () {
65
					if (input.controller('ngModel').$invalid) {
66
						return 0;
67
					} else if (!input.controller('ngModel').$viewValue) {
68
						return 1;
69
					} else {
70
						return 2;
71
					}
72
				}, function (code) {
73
					if (code < 0) return;
74

    
75
					element.toggleClass('has-error', (code == 0));
76
					element.toggleClass('has-warning', (code == 1));
77
					element.toggleClass('has-success', (code == 2));
78

    
79
					var feedback = element.find('.form-control-feedback');
80
					if (feedback) {
81
						feedback.toggleClass('glyphicon-remove', (code == 0));
82
						feedback.toggleClass('glyphicon-warning-sign', (code == 1));
83
						feedback.toggleClass('glyphicon-ok', (code == 2));
84
					}
85
				});
86
			}
87
		}
88
	};
89
});
90

    
91
wfFormFields.directive('wfFormRowStatic', function (availableUis) {
92
	return {
93
		restrict: 'E',
94
		scope: {
95
			name             : '@',
96
			value            : '@',
97
			description      : '@',
98
			valueDescription : '@',
99
			valueStyle       : '@',
100
			img              : '@',
101
			url              : '@',
102
			category         : '@'
103
		},
104
		templateUrl: '../resources/html/wf/wf-form-row-static.html',
105
		link: function (scope) {
106
			if (scope.category && availableUis[scope.category]) {
107
				scope.links = availableUis[scope.category];
108
			} else {
109
				scope.links = [];
110
			}
111
		}
112
	}
113
});
114

    
115
wfFormFields.directive('wfFormRowLabel', function () {
116
	return {
117
		restrict: 'E',
118
		scope: {
119
			name        : '@',
120
			value       : '@',
121
			description : '@',
122
			date        : '@',
123
			labelClass  : '@'
124
		},
125
		templateUrl: '../resources/html/wf/wf-form-row-label.html'
126
	}
127
});
128

    
129
wfFormFields.directive('wfFormRowStoreLink', function () {
130
	return {
131
		restrict: 'E',
132
		scope: {
133
			name  : '@',
134
			date  : '@',
135
			total : '@',
136
			url   : '@'
137
		},
138
		templateUrl: '../resources/html/wf/wf-form-row-store-link.html'
139
	}
140
});
141

    
142

    
143
wfFormFields.directive('wfFormRowSelect', function (cacheParameters, availableUis) {
144
	return {
145
		restrict: 'E',
146
		templateUrl: '../resources/html/wf/wf-form-row-select.html',
147
		scope: {
148
			name            : '@',
149
			value           : '@',
150
			mandatory       : '@',
151
			description     : '@',
152
			initValue       : '@',
153
			ngModel         : '=',
154
			ngOriginalModel : '=',
155
			values          : '=',
156
			valuesFunction  : '@',
157
			category        : '@'
158
		},
159
		link: function (scope) {
160

    
161
			if (scope.category && availableUis[scope.category]) {
162
				scope.links = availableUis[scope.category];
163
			} else {
164
				scope.links = [];
165
			}
166
						
167
			scope.finalValues = [];
168

    
169
			scope.ngModel = scope.initValue;
170
			scope.ngOriginalModel = scope.initValue;
171

    
172
			scope.isRequired = (scope.mandatory == "true");
173

    
174
			if (scope.values) {
175
				scope.finalValues = scope.values;
176
			} else if (scope.valuesFunction) {
177
				scope.finalValues = cacheParameters.listValidValuesForUserParam(scope.valuesFunction);
178
			}
179
		}
180
	}
181
});
182

    
183
wfFormFields.directive('wfFormRowMultiSelect', function (cacheParameters, availableUis) {
184
	return {
185
		restrict: 'E',
186
		templateUrl: '../resources/html/wf/wf-form-row-multi-select.html',
187
		scope: {
188
			name            : '@',
189
			value           : '@',
190
			mandatory       : '@',
191
			description     : '@',
192
			initValue       : '@',
193
			ngModel         : '=',
194
			ngOriginalModel : '=',
195
			values          : '=',
196
			valuesFunction  : '@',
197
			category        : '@'
198
		},
199
		link: function (scope) {
200

    
201
			if (scope.category && availableUis[scope.category]) {
202
				scope.links = availableUis[scope.category];
203
			} else {
204
				scope.links = [];
205
			}
206
			
207
			scope.finalValues = [];
208

    
209
			scope.ngModel = scope.initValue.split(',');
210
			scope.ngOriginalModel = scope.initValue.split(',');
211

    
212
			scope.isRequired = (scope.mandatory == "true");
213

    
214
			if (scope.values) {
215
				scope.finalValues = scope.values;
216
			} else if (scope.valuesFunction) {
217
				scope.finalValues = cacheParameters.listValidValuesForUserParam(scope.valuesFunction);
218
			}
219
			
220
			scope.refreshValues = function() {
221
				scope.finalValues = cacheParameters.listValidValuesForUserParam(scope.valuesFunction, true);
222
			}
223
		}
224
	}
225
});
226

    
227

    
228
wfFormFields.directive('wfFormRowText', function (availableUis) {
229
	return {
230
		restrict: 'E',
231
		templateUrl: '../resources/html/wf/wf-form-row-text.html',
232
		//require: '^ngModel',
233
		scope: {
234
			name            : '@',
235
			mandatory       : '@',
236
			description     : '@',
237
			initValue       : '@',
238
			type            : '@',
239
			regex           : '@',
240
			ngModel         : '=',
241
			ngOriginalModel : '=',
242
			category        : '@'
243
		},
244
		link: function (scope) {
245
	
246
			if (scope.category && availableUis[scope.category]) {
247
				scope.links = availableUis[scope.category];
248
			} else {
249
				scope.links = [];
250
			}
251
			
252
			scope.ngModel = "";
253
			scope.ngOriginalModel = "";
254

    
255
			if (scope.initValue) {
256
				scope.ngModel = scope.initValue;
257
				scope.ngOriginalModel = scope.initValue;
258
			}
259

    
260
			scope.isRequired = (scope.mandatory == "true");
261
			
262
			if (scope.regex) {
263
				scope.mypattern = new RegExp(scope.regex);
264
			} else if (scope.type == 'boolean') {
265
				scope.mypattern = new RegExp("^(true|false)$");
266
			} else if (scope.type == 'int') {
267
				scope.mypattern = new RegExp("^[-+]?[0-9]+$");
268
			} else if (scope.type == 'float') {
269
				scope.mypattern = new RegExp("^[-+]?[0-9]+(\.[0-9]+)?$");
270
			} else if (scope.type == 'date') {
271
				scope.mypattern = new RegExp("^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$");
272
			} else {
273
				scope.mypattern = new RegExp("^.+$");
274
			}
275
		}
276
	}
277
});
(3-3/6)