@stemy/ngx-dynamic-form 10.1.0 → 10.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +27 -27
  2. package/bundles/stemy-ngx-dynamic-form.umd.js +2247 -2247
  3. package/bundles/stemy-ngx-dynamic-form.umd.js.map +1 -1
  4. package/bundles/stemy-ngx-dynamic-form.umd.min.js +2 -2
  5. package/bundles/stemy-ngx-dynamic-form.umd.min.js.map +1 -1
  6. package/esm2015/ngx-dynamic-form/common-types.js +591 -591
  7. package/esm2015/ngx-dynamic-form/components/base/dynamic-form-base.component.js +87 -87
  8. package/esm2015/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.js +91 -91
  9. package/esm2015/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.js +112 -112
  10. package/esm2015/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.js +19 -19
  11. package/esm2015/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.js +73 -73
  12. package/esm2015/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.js +23 -23
  13. package/esm2015/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.js +73 -73
  14. package/esm2015/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.js +20 -20
  15. package/esm2015/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.js +134 -134
  16. package/esm2015/ngx-dynamic-form/directives/async-submit.directive.js +89 -89
  17. package/esm2015/ngx-dynamic-form/directives/dynamic-form-control.directive.js +32 -32
  18. package/esm2015/ngx-dynamic-form/directives/dynamic-form-group.directive.js +40 -40
  19. package/esm2015/ngx-dynamic-form/directives/dynamic-form-template.directive.js +38 -38
  20. package/esm2015/ngx-dynamic-form/ngx-dynamic-form.module.js +85 -85
  21. package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +48 -48
  22. package/esm2015/ngx-dynamic-form/services/form-utilities.js +108 -108
  23. package/esm2015/ngx-dynamic-form/services/open-api.service.js +130 -130
  24. package/esm2015/public_api.js +18 -18
  25. package/esm2015/stemy-ngx-dynamic-form.js +8 -8
  26. package/fesm2015/stemy-ngx-dynamic-form.js +1690 -1690
  27. package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
  28. package/ngx-dynamic-form/common-types.d.ts +307 -307
  29. package/ngx-dynamic-form/components/base/dynamic-form-base.component.d.ts +44 -44
  30. package/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.d.ts +21 -21
  31. package/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.d.ts +16 -16
  32. package/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.d.ts +6 -6
  33. package/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.d.ts +13 -13
  34. package/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.d.ts +6 -6
  35. package/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.d.ts +9 -9
  36. package/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.d.ts +5 -5
  37. package/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.d.ts +26 -26
  38. package/ngx-dynamic-form/directives/async-submit.directive.d.ts +23 -23
  39. package/ngx-dynamic-form/directives/dynamic-form-control.directive.d.ts +12 -12
  40. package/ngx-dynamic-form/directives/dynamic-form-group.directive.d.ts +14 -14
  41. package/ngx-dynamic-form/directives/dynamic-form-template.directive.d.ts +16 -16
  42. package/ngx-dynamic-form/ngx-dynamic-form.module.d.ts +20 -20
  43. package/ngx-dynamic-form/services/dynamic-form.service.d.ts +12 -12
  44. package/ngx-dynamic-form/services/form-utilities.d.ts +19 -19
  45. package/ngx-dynamic-form/services/open-api.service.d.ts +37 -37
  46. package/package.json +15 -15
  47. package/public_api.d.ts +17 -17
  48. package/stemy-ngx-dynamic-form.d.ts +7 -7
  49. package/stemy-ngx-dynamic-form.metadata.json +1 -1
@@ -4,2291 +4,2291 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy['ngx-dynamic-form'] = {}), global.ng.core, global.ng.forms, global.ngxUtils, global.ng.common, global.rxjs.operators, global.angular2TextMask));
5
5
  }(this, (function (exports, core, forms, ngxUtils, common, operators, angular2TextMask) { 'use strict';
6
6
 
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise */
22
- var extendStatics = function (d, b) {
23
- extendStatics = Object.setPrototypeOf ||
24
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
- function (d, b) { for (var p in b)
26
- if (Object.prototype.hasOwnProperty.call(b, p))
27
- d[p] = b[p]; };
28
- return extendStatics(d, b);
29
- };
30
- function __extends(d, b) {
31
- extendStatics(d, b);
32
- function __() { this.constructor = d; }
33
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
- }
35
- var __assign = function () {
36
- __assign = Object.assign || function __assign(t) {
37
- for (var s, i = 1, n = arguments.length; i < n; i++) {
38
- s = arguments[i];
39
- for (var p in s)
40
- if (Object.prototype.hasOwnProperty.call(s, p))
41
- t[p] = s[p];
42
- }
43
- return t;
44
- };
45
- return __assign.apply(this, arguments);
46
- };
47
- function __rest(s, e) {
48
- var t = {};
49
- for (var p in s)
50
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- }
59
- function __decorate(decorators, target, key, desc) {
60
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
62
- r = Reflect.decorate(decorators, target, key, desc);
63
- else
64
- for (var i = decorators.length - 1; i >= 0; i--)
65
- if (d = decorators[i])
66
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
67
- return c > 3 && r && Object.defineProperty(target, key, r), r;
68
- }
69
- function __param(paramIndex, decorator) {
70
- return function (target, key) { decorator(target, key, paramIndex); };
71
- }
72
- function __metadata(metadataKey, metadataValue) {
73
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
74
- return Reflect.metadata(metadataKey, metadataValue);
75
- }
76
- function __awaiter(thisArg, _arguments, P, generator) {
77
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
78
- return new (P || (P = Promise))(function (resolve, reject) {
79
- function fulfilled(value) { try {
80
- step(generator.next(value));
81
- }
82
- catch (e) {
83
- reject(e);
84
- } }
85
- function rejected(value) { try {
86
- step(generator["throw"](value));
87
- }
88
- catch (e) {
89
- reject(e);
90
- } }
91
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
92
- step((generator = generator.apply(thisArg, _arguments || [])).next());
93
- });
94
- }
95
- function __generator(thisArg, body) {
96
- var _ = { label: 0, sent: function () { if (t[0] & 1)
97
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
98
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
99
- function verb(n) { return function (v) { return step([n, v]); }; }
100
- function step(op) {
101
- if (f)
102
- throw new TypeError("Generator is already executing.");
103
- while (_)
104
- try {
105
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
106
- return t;
107
- if (y = 0, t)
108
- op = [op[0] & 2, t.value];
109
- switch (op[0]) {
110
- case 0:
111
- case 1:
112
- t = op;
113
- break;
114
- case 4:
115
- _.label++;
116
- return { value: op[1], done: false };
117
- case 5:
118
- _.label++;
119
- y = op[1];
120
- op = [0];
121
- continue;
122
- case 7:
123
- op = _.ops.pop();
124
- _.trys.pop();
125
- continue;
126
- default:
127
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
128
- _ = 0;
129
- continue;
130
- }
131
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
132
- _.label = op[1];
133
- break;
134
- }
135
- if (op[0] === 6 && _.label < t[1]) {
136
- _.label = t[1];
137
- t = op;
138
- break;
139
- }
140
- if (t && _.label < t[2]) {
141
- _.label = t[2];
142
- _.ops.push(op);
143
- break;
144
- }
145
- if (t[2])
146
- _.ops.pop();
147
- _.trys.pop();
148
- continue;
149
- }
150
- op = body.call(thisArg, _);
151
- }
152
- catch (e) {
153
- op = [6, e];
154
- y = 0;
155
- }
156
- finally {
157
- f = t = 0;
158
- }
159
- if (op[0] & 5)
160
- throw op[1];
161
- return { value: op[0] ? op[1] : void 0, done: true };
162
- }
163
- }
164
- var __createBinding = Object.create ? (function (o, m, k, k2) {
165
- if (k2 === undefined)
166
- k2 = k;
167
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
168
- }) : (function (o, m, k, k2) {
169
- if (k2 === undefined)
170
- k2 = k;
171
- o[k2] = m[k];
172
- });
173
- function __exportStar(m, o) {
174
- for (var p in m)
175
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
176
- __createBinding(o, m, p);
177
- }
178
- function __values(o) {
179
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
180
- if (m)
181
- return m.call(o);
182
- if (o && typeof o.length === "number")
183
- return {
184
- next: function () {
185
- if (o && i >= o.length)
186
- o = void 0;
187
- return { value: o && o[i++], done: !o };
188
- }
189
- };
190
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
191
- }
192
- function __read(o, n) {
193
- var m = typeof Symbol === "function" && o[Symbol.iterator];
194
- if (!m)
195
- return o;
196
- var i = m.call(o), r, ar = [], e;
197
- try {
198
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
199
- ar.push(r.value);
200
- }
201
- catch (error) {
202
- e = { error: error };
203
- }
204
- finally {
205
- try {
206
- if (r && !r.done && (m = i["return"]))
207
- m.call(i);
208
- }
209
- finally {
210
- if (e)
211
- throw e.error;
212
- }
213
- }
214
- return ar;
215
- }
216
- function __spread() {
217
- for (var ar = [], i = 0; i < arguments.length; i++)
218
- ar = ar.concat(__read(arguments[i]));
219
- return ar;
220
- }
221
- function __spreadArrays() {
222
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
223
- s += arguments[i].length;
224
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
225
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
226
- r[k] = a[j];
227
- return r;
228
- }
229
- ;
230
- function __await(v) {
231
- return this instanceof __await ? (this.v = v, this) : new __await(v);
232
- }
233
- function __asyncGenerator(thisArg, _arguments, generator) {
234
- if (!Symbol.asyncIterator)
235
- throw new TypeError("Symbol.asyncIterator is not defined.");
236
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
237
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
238
- function verb(n) { if (g[n])
239
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
240
- function resume(n, v) { try {
241
- step(g[n](v));
242
- }
243
- catch (e) {
244
- settle(q[0][3], e);
245
- } }
246
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
247
- function fulfill(value) { resume("next", value); }
248
- function reject(value) { resume("throw", value); }
249
- function settle(f, v) { if (f(v), q.shift(), q.length)
250
- resume(q[0][0], q[0][1]); }
251
- }
252
- function __asyncDelegator(o) {
253
- var i, p;
254
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
255
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
256
- }
257
- function __asyncValues(o) {
258
- if (!Symbol.asyncIterator)
259
- throw new TypeError("Symbol.asyncIterator is not defined.");
260
- var m = o[Symbol.asyncIterator], i;
261
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
262
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
263
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
264
- }
265
- function __makeTemplateObject(cooked, raw) {
266
- if (Object.defineProperty) {
267
- Object.defineProperty(cooked, "raw", { value: raw });
268
- }
269
- else {
270
- cooked.raw = raw;
271
- }
272
- return cooked;
273
- }
274
- ;
275
- var __setModuleDefault = Object.create ? (function (o, v) {
276
- Object.defineProperty(o, "default", { enumerable: true, value: v });
277
- }) : function (o, v) {
278
- o["default"] = v;
279
- };
280
- function __importStar(mod) {
281
- if (mod && mod.__esModule)
282
- return mod;
283
- var result = {};
284
- if (mod != null)
285
- for (var k in mod)
286
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
287
- __createBinding(result, mod, k);
288
- __setModuleDefault(result, mod);
289
- return result;
290
- }
291
- function __importDefault(mod) {
292
- return (mod && mod.__esModule) ? mod : { default: mod };
293
- }
294
- function __classPrivateFieldGet(receiver, privateMap) {
295
- if (!privateMap.has(receiver)) {
296
- throw new TypeError("attempted to get private field on non-instance");
297
- }
298
- return privateMap.get(receiver);
299
- }
300
- function __classPrivateFieldSet(receiver, privateMap, value) {
301
- if (!privateMap.has(receiver)) {
302
- throw new TypeError("attempted to set private field on non-instance");
303
- }
304
- privateMap.set(receiver, value);
305
- return value;
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise */
22
+ var extendStatics = function (d, b) {
23
+ extendStatics = Object.setPrototypeOf ||
24
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
+ function (d, b) { for (var p in b)
26
+ if (Object.prototype.hasOwnProperty.call(b, p))
27
+ d[p] = b[p]; };
28
+ return extendStatics(d, b);
29
+ };
30
+ function __extends(d, b) {
31
+ extendStatics(d, b);
32
+ function __() { this.constructor = d; }
33
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
+ }
35
+ var __assign = function () {
36
+ __assign = Object.assign || function __assign(t) {
37
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
38
+ s = arguments[i];
39
+ for (var p in s)
40
+ if (Object.prototype.hasOwnProperty.call(s, p))
41
+ t[p] = s[p];
42
+ }
43
+ return t;
44
+ };
45
+ return __assign.apply(this, arguments);
46
+ };
47
+ function __rest(s, e) {
48
+ var t = {};
49
+ for (var p in s)
50
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ }
59
+ function __decorate(decorators, target, key, desc) {
60
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
62
+ r = Reflect.decorate(decorators, target, key, desc);
63
+ else
64
+ for (var i = decorators.length - 1; i >= 0; i--)
65
+ if (d = decorators[i])
66
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
67
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
68
+ }
69
+ function __param(paramIndex, decorator) {
70
+ return function (target, key) { decorator(target, key, paramIndex); };
71
+ }
72
+ function __metadata(metadataKey, metadataValue) {
73
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
74
+ return Reflect.metadata(metadataKey, metadataValue);
75
+ }
76
+ function __awaiter(thisArg, _arguments, P, generator) {
77
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
78
+ return new (P || (P = Promise))(function (resolve, reject) {
79
+ function fulfilled(value) { try {
80
+ step(generator.next(value));
81
+ }
82
+ catch (e) {
83
+ reject(e);
84
+ } }
85
+ function rejected(value) { try {
86
+ step(generator["throw"](value));
87
+ }
88
+ catch (e) {
89
+ reject(e);
90
+ } }
91
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
92
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
93
+ });
94
+ }
95
+ function __generator(thisArg, body) {
96
+ var _ = { label: 0, sent: function () { if (t[0] & 1)
97
+ throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
98
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
99
+ function verb(n) { return function (v) { return step([n, v]); }; }
100
+ function step(op) {
101
+ if (f)
102
+ throw new TypeError("Generator is already executing.");
103
+ while (_)
104
+ try {
105
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
106
+ return t;
107
+ if (y = 0, t)
108
+ op = [op[0] & 2, t.value];
109
+ switch (op[0]) {
110
+ case 0:
111
+ case 1:
112
+ t = op;
113
+ break;
114
+ case 4:
115
+ _.label++;
116
+ return { value: op[1], done: false };
117
+ case 5:
118
+ _.label++;
119
+ y = op[1];
120
+ op = [0];
121
+ continue;
122
+ case 7:
123
+ op = _.ops.pop();
124
+ _.trys.pop();
125
+ continue;
126
+ default:
127
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
128
+ _ = 0;
129
+ continue;
130
+ }
131
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
132
+ _.label = op[1];
133
+ break;
134
+ }
135
+ if (op[0] === 6 && _.label < t[1]) {
136
+ _.label = t[1];
137
+ t = op;
138
+ break;
139
+ }
140
+ if (t && _.label < t[2]) {
141
+ _.label = t[2];
142
+ _.ops.push(op);
143
+ break;
144
+ }
145
+ if (t[2])
146
+ _.ops.pop();
147
+ _.trys.pop();
148
+ continue;
149
+ }
150
+ op = body.call(thisArg, _);
151
+ }
152
+ catch (e) {
153
+ op = [6, e];
154
+ y = 0;
155
+ }
156
+ finally {
157
+ f = t = 0;
158
+ }
159
+ if (op[0] & 5)
160
+ throw op[1];
161
+ return { value: op[0] ? op[1] : void 0, done: true };
162
+ }
163
+ }
164
+ var __createBinding = Object.create ? (function (o, m, k, k2) {
165
+ if (k2 === undefined)
166
+ k2 = k;
167
+ Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
168
+ }) : (function (o, m, k, k2) {
169
+ if (k2 === undefined)
170
+ k2 = k;
171
+ o[k2] = m[k];
172
+ });
173
+ function __exportStar(m, o) {
174
+ for (var p in m)
175
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
176
+ __createBinding(o, m, p);
177
+ }
178
+ function __values(o) {
179
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
180
+ if (m)
181
+ return m.call(o);
182
+ if (o && typeof o.length === "number")
183
+ return {
184
+ next: function () {
185
+ if (o && i >= o.length)
186
+ o = void 0;
187
+ return { value: o && o[i++], done: !o };
188
+ }
189
+ };
190
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
191
+ }
192
+ function __read(o, n) {
193
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
194
+ if (!m)
195
+ return o;
196
+ var i = m.call(o), r, ar = [], e;
197
+ try {
198
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
199
+ ar.push(r.value);
200
+ }
201
+ catch (error) {
202
+ e = { error: error };
203
+ }
204
+ finally {
205
+ try {
206
+ if (r && !r.done && (m = i["return"]))
207
+ m.call(i);
208
+ }
209
+ finally {
210
+ if (e)
211
+ throw e.error;
212
+ }
213
+ }
214
+ return ar;
215
+ }
216
+ function __spread() {
217
+ for (var ar = [], i = 0; i < arguments.length; i++)
218
+ ar = ar.concat(__read(arguments[i]));
219
+ return ar;
220
+ }
221
+ function __spreadArrays() {
222
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++)
223
+ s += arguments[i].length;
224
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
225
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
226
+ r[k] = a[j];
227
+ return r;
228
+ }
229
+ ;
230
+ function __await(v) {
231
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
232
+ }
233
+ function __asyncGenerator(thisArg, _arguments, generator) {
234
+ if (!Symbol.asyncIterator)
235
+ throw new TypeError("Symbol.asyncIterator is not defined.");
236
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
237
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
238
+ function verb(n) { if (g[n])
239
+ i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
240
+ function resume(n, v) { try {
241
+ step(g[n](v));
242
+ }
243
+ catch (e) {
244
+ settle(q[0][3], e);
245
+ } }
246
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
247
+ function fulfill(value) { resume("next", value); }
248
+ function reject(value) { resume("throw", value); }
249
+ function settle(f, v) { if (f(v), q.shift(), q.length)
250
+ resume(q[0][0], q[0][1]); }
251
+ }
252
+ function __asyncDelegator(o) {
253
+ var i, p;
254
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
255
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
256
+ }
257
+ function __asyncValues(o) {
258
+ if (!Symbol.asyncIterator)
259
+ throw new TypeError("Symbol.asyncIterator is not defined.");
260
+ var m = o[Symbol.asyncIterator], i;
261
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
262
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
263
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
264
+ }
265
+ function __makeTemplateObject(cooked, raw) {
266
+ if (Object.defineProperty) {
267
+ Object.defineProperty(cooked, "raw", { value: raw });
268
+ }
269
+ else {
270
+ cooked.raw = raw;
271
+ }
272
+ return cooked;
273
+ }
274
+ ;
275
+ var __setModuleDefault = Object.create ? (function (o, v) {
276
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
277
+ }) : function (o, v) {
278
+ o["default"] = v;
279
+ };
280
+ function __importStar(mod) {
281
+ if (mod && mod.__esModule)
282
+ return mod;
283
+ var result = {};
284
+ if (mod != null)
285
+ for (var k in mod)
286
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
287
+ __createBinding(result, mod, k);
288
+ __setModuleDefault(result, mod);
289
+ return result;
290
+ }
291
+ function __importDefault(mod) {
292
+ return (mod && mod.__esModule) ? mod : { default: mod };
293
+ }
294
+ function __classPrivateFieldGet(receiver, privateMap) {
295
+ if (!privateMap.has(receiver)) {
296
+ throw new TypeError("attempted to get private field on non-instance");
297
+ }
298
+ return privateMap.get(receiver);
299
+ }
300
+ function __classPrivateFieldSet(receiver, privateMap, value) {
301
+ if (!privateMap.has(receiver)) {
302
+ throw new TypeError("attempted to set private field on non-instance");
303
+ }
304
+ privateMap.set(receiver, value);
305
+ return value;
306
306
  }
307
307
 
308
- var FORM_GROUP_TYPE = new core.InjectionToken("form-group-provider");
309
- var FORM_CONTROL_PROVIDER = new core.InjectionToken("form-control-provider");
310
- var FormControlComponent = /** @class */ (function () {
311
- function FormControlComponent() {
312
- }
313
- Object.defineProperty(FormControlComponent.prototype, "form", {
314
- get: function () {
315
- return !this.control ? null : this.control.form;
316
- },
317
- enumerable: false,
318
- configurable: true
319
- });
320
- Object.defineProperty(FormControlComponent.prototype, "data", {
321
- get: function () {
322
- return (!this.control ? {} : this.control.data);
323
- },
324
- enumerable: false,
325
- configurable: true
326
- });
327
- Object.defineProperty(FormControlComponent.prototype, "value", {
328
- get: function () {
329
- return !this.control ? null : this.control.value;
330
- },
331
- enumerable: false,
332
- configurable: true
333
- });
334
- Object.defineProperty(FormControlComponent.prototype, "meta", {
335
- get: function () {
336
- return !this.control ? null : this.control.meta;
337
- },
338
- enumerable: false,
339
- configurable: true
340
- });
341
- Object.defineProperty(FormControlComponent.prototype, "inputClass", {
342
- get: function () {
343
- return true;
344
- },
345
- enumerable: false,
346
- configurable: true
347
- });
348
- return FormControlComponent;
349
- }());
350
- FormControlComponent.decorators = [
351
- { type: core.Directive }
352
- ];
353
- FormControlComponent.propDecorators = {
354
- inputClass: [{ type: core.HostBinding, args: ["class.form-input",] }]
355
- };
356
- function createValidator(control) {
357
- var data = control.data || {};
358
- var validators = [data.validator].concat(data.validators || []).filter(ngxUtils.ObjectUtils.isDefined).map(function (v) {
359
- return ngxUtils.ReflectUtils.resolve(v, control.injector);
360
- });
361
- return function (ctrl) { return new Promise(function (resolve) {
362
- var control = ctrl;
363
- control.shouldValidate().then(function (should) {
364
- if (!should) {
365
- resolve(null);
366
- return;
367
- }
368
- var validate = validators.map(function (v) { return v(control); });
369
- var metaValidator = control.meta.validator;
370
- if (ngxUtils.ObjectUtils.isFunction(metaValidator)) {
371
- validate.push(metaValidator(control));
372
- }
373
- Promise.all(validate).then(function (results) {
374
- results = results.filter(function (error) { return ngxUtils.ObjectUtils.isObject(error) || ngxUtils.ObjectUtils.isString(error); });
375
- var result = null;
376
- if (results.length > 0) {
377
- result = {};
378
- results.forEach(function (error) {
379
- if (ngxUtils.ObjectUtils.isString(error)) {
380
- result[error] = {};
381
- return;
382
- }
383
- result = Object.assign(result, error);
384
- });
385
- }
386
- resolve(result);
387
- });
388
- });
389
- }); };
390
- }
391
- var DynamicFormControlHelper = /** @class */ (function () {
392
- function DynamicFormControlHelper(form, control) {
393
- if (control === void 0) { control = null; }
394
- this.form = form;
395
- this.control = control;
396
- this.formId = ngxUtils.UniqueUtils.uuid();
397
- this.meta = {};
398
- this.hidden = false;
399
- this.dummyData = {};
400
- this.readonlyTester = this.createTester("readonly");
401
- this.hideTester = this.createTester("hidden");
402
- this.serializeTester = this.createTester("shouldSerialize", function (control) {
403
- return Promise.resolve(control.visible);
404
- });
405
- this.validateTester = this.createTester("shouldValidate", function (control) {
406
- return Promise.resolve(control.visible);
407
- });
408
- }
409
- Object.defineProperty(DynamicFormControlHelper.prototype, "id", {
410
- get: function () {
411
- return !this.control ? null : this.control.id;
412
- },
413
- enumerable: false,
414
- configurable: true
415
- });
416
- Object.defineProperty(DynamicFormControlHelper.prototype, "type", {
417
- get: function () {
418
- return !this.control ? "" : this.control.type;
419
- },
420
- enumerable: false,
421
- configurable: true
422
- });
423
- Object.defineProperty(DynamicFormControlHelper.prototype, "data", {
424
- get: function () {
425
- return !this.control ? this.dummyData : this.control.data || this.dummyData;
426
- },
427
- enumerable: false,
428
- configurable: true
429
- });
430
- Object.defineProperty(DynamicFormControlHelper.prototype, "visible", {
431
- get: function () {
432
- return !this.hidden;
433
- },
434
- enumerable: false,
435
- configurable: true
436
- });
437
- Object.defineProperty(DynamicFormControlHelper.prototype, "provider", {
438
- get: function () {
439
- return this.ctrlProvider;
440
- },
441
- enumerable: false,
442
- configurable: true
443
- });
444
- DynamicFormControlHelper.prototype.load = function (control) {
445
- return !this.ctrlProvider ? Promise.resolve() : this.ctrlProvider.loader(control);
446
- };
447
- DynamicFormControlHelper.prototype.check = function (control) {
448
- var _this = this;
449
- return new Promise(function (resolve) {
450
- _this.hideTester(control).then(function (hide) {
451
- _this.hidden = hide;
452
- _this.readonlyTester(control).then(function (readonly) {
453
- resolve(control.form.readonly || readonly);
454
- });
455
- });
456
- });
457
- };
458
- DynamicFormControlHelper.prototype.shouldSerialize = function (control) {
459
- return this.serializeTester(control);
460
- };
461
- DynamicFormControlHelper.prototype.shouldValidate = function (control) {
462
- return this.validateTester(control);
463
- };
464
- DynamicFormControlHelper.prototype.findProvider = function (control) {
465
- this.ctrlProvider = !this.control || !this.control.type ? null : this.form.findProvider(control);
466
- };
467
- DynamicFormControlHelper.prototype.createTester = function (test, defaultFunc) {
468
- if (defaultFunc === void 0) { defaultFunc = null; }
469
- var tester = this.data[test]
470
- ? ngxUtils.ReflectUtils.resolve(this.data[test], this.form.injector)
471
- : (defaultFunc || (function () { return Promise.resolve(false); }));
472
- return function (control) { return tester(control); };
473
- };
474
- return DynamicFormControlHelper;
475
- }());
476
- var DynamicFormGroup = /** @class */ (function (_super) {
477
- __extends(DynamicFormGroup, _super);
478
- function DynamicFormGroup(form, control) {
479
- if (control === void 0) { control = null; }
480
- var _this = _super.call(this, {}, { updateOn: ((!control || !control.data) ? null : control.data.updateOn) || form.updateOn || "blur" }) || this;
481
- _this.form = form;
482
- _this.mName = "";
483
- _this.mModel = {};
484
- _this.mControls = [];
485
- _this.mSerializers = [];
486
- _this.mFieldSets = {};
487
- _this.helper = new DynamicFormControlHelper(form, control);
488
- _this.helper.findProvider(_this);
489
- _this.initialized = false;
490
- _this.loading = false;
491
- _this.changeTimer = ngxUtils.TimerUtils.createTimeout();
492
- _this.statusChanges.subscribe(function () {
493
- var root = _this.form.root;
494
- root.onStatusChange.emit(root);
495
- });
496
- _this.setAsyncValidators(createValidator(_this));
497
- return _this;
498
- }
499
- Object.defineProperty(DynamicFormGroup.prototype, "id", {
500
- get: function () {
501
- return this.helper.id;
502
- },
503
- enumerable: false,
504
- configurable: true
505
- });
506
- Object.defineProperty(DynamicFormGroup.prototype, "type", {
507
- get: function () {
508
- return this.helper.type;
509
- },
510
- enumerable: false,
511
- configurable: true
512
- });
513
- Object.defineProperty(DynamicFormGroup.prototype, "data", {
514
- get: function () {
515
- return this.helper.data;
516
- },
517
- enumerable: false,
518
- configurable: true
519
- });
520
- Object.defineProperty(DynamicFormGroup.prototype, "visible", {
521
- get: function () {
522
- return this.helper.visible;
523
- },
524
- enumerable: false,
525
- configurable: true
526
- });
527
- Object.defineProperty(DynamicFormGroup.prototype, "meta", {
528
- get: function () {
529
- return this.helper.meta;
530
- },
531
- enumerable: false,
532
- configurable: true
533
- });
534
- Object.defineProperty(DynamicFormGroup.prototype, "injector", {
535
- get: function () {
536
- return this.form.injector;
537
- },
538
- enumerable: false,
539
- configurable: true
540
- });
541
- Object.defineProperty(DynamicFormGroup.prototype, "label", {
542
- get: function () {
543
- return this.data.label !== "" ? "" + this.prefix + this.data.label : "";
544
- },
545
- enumerable: false,
546
- configurable: true
547
- });
548
- Object.defineProperty(DynamicFormGroup.prototype, "provider", {
549
- get: function () {
550
- return this.helper.provider;
551
- },
552
- enumerable: false,
553
- configurable: true
554
- });
555
- Object.defineProperty(DynamicFormGroup.prototype, "model", {
556
- get: function () {
557
- return this.mModel;
558
- },
559
- enumerable: false,
560
- configurable: true
561
- });
562
- Object.defineProperty(DynamicFormGroup.prototype, "formId", {
563
- get: function () {
564
- return this.helper.formId;
565
- },
566
- enumerable: false,
567
- configurable: true
568
- });
569
- Object.defineProperty(DynamicFormGroup.prototype, "formControls", {
570
- get: function () {
571
- return this.mControls || [];
572
- },
573
- enumerable: false,
574
- configurable: true
575
- });
576
- Object.defineProperty(DynamicFormGroup.prototype, "formFields", {
577
- get: function () {
578
- return this.mFieldSets || {};
579
- },
580
- enumerable: false,
581
- configurable: true
582
- });
583
- Object.defineProperty(DynamicFormGroup.prototype, "prefix", {
584
- get: function () {
585
- return !this.name ? "" : this.name + ".";
586
- },
587
- enumerable: false,
588
- configurable: true
589
- });
590
- Object.defineProperty(DynamicFormGroup.prototype, "name", {
591
- get: function () {
592
- return this.mName;
593
- },
594
- enumerable: false,
595
- configurable: true
596
- });
597
- Object.defineProperty(DynamicFormGroup.prototype, "state", {
598
- get: function () {
599
- return (this.loading ? "LOADING" : this.status);
600
- },
601
- enumerable: false,
602
- configurable: true
603
- });
604
- DynamicFormGroup.createFormControls = function (group, controls) {
605
- if (!controls && ngxUtils.ObjectUtils.isObject(group.model)) {
606
- var props = Object.keys(group.model);
607
- controls = props.map(function (id) {
608
- return getFormControl(group.model, id);
609
- }).filter(ngxUtils.ObjectUtils.isDefined);
610
- }
611
- if (!controls)
612
- return [];
613
- return controls.map(function (ctrl) {
614
- if (ctrl.type == "model") {
615
- var subGroup = new DynamicFormGroup(group.form, ctrl);
616
- var model = group.model[ctrl.id] || {};
617
- var data = subGroup.getData();
618
- data.name = data.name || group.name;
619
- subGroup.setup(model, data);
620
- group.model[ctrl.id] = model;
621
- group.addControl(subGroup.id, subGroup);
622
- return subGroup;
623
- }
624
- return new DynamicFormControl(ctrl, group);
625
- });
626
- };
627
- DynamicFormGroup.createFormSerializers = function (group, serializers) {
628
- if (!serializers && ngxUtils.ObjectUtils.isObject(group.model)) {
629
- var props = Object.keys(group.model);
630
- serializers = props.reduce(function (result, id) {
631
- var serializer = getFormSerializer(group.model, id);
632
- if (!serializer)
633
- return result;
634
- result[id] = serializer;
635
- return result;
636
- }, {});
637
- }
638
- if (!serializers)
639
- return [];
640
- return Object.keys(serializers).map(function (id) {
641
- var serializer = serializers[id] || defaultSerializer;
642
- return !serializer ? null : {
643
- id: id,
644
- func: ngxUtils.ReflectUtils.resolve(serializer, group.injector)
645
- };
646
- });
647
- };
648
- DynamicFormGroup.prototype.getData = function () {
649
- return this.data;
650
- };
651
- DynamicFormGroup.prototype.getControl = function (id) {
652
- return this.get(id);
653
- };
654
- DynamicFormGroup.prototype.load = function () {
655
- var promises = this.mControls.map(function (c) { return c.load(); });
656
- promises.push(this.helper.load(this));
657
- return Promise.all(promises);
658
- };
659
- DynamicFormGroup.prototype.check = function () {
660
- var _this = this;
661
- return new Promise(function (resolve) {
662
- _this.helper.check(_this).then(function (readonly) {
663
- if (readonly)
664
- _this.disable({ emitEvent: false });
665
- else
666
- _this.enable({ emitEvent: false });
667
- var promises = _this.mControls.map(function (c) { return c.check(); });
668
- Promise.all(promises).then(resolve);
669
- });
670
- });
671
- };
672
- DynamicFormGroup.prototype.shouldSerialize = function () {
673
- return this.helper.shouldSerialize(this);
674
- };
675
- DynamicFormGroup.prototype.shouldValidate = function () {
676
- return this.helper.shouldValidate(this);
677
- };
678
- DynamicFormGroup.prototype.serialize = function () {
679
- var _this = this;
680
- return new Promise(function (resolve) {
681
- var result = {};
682
- var serializers = _this.mSerializers.map(function (s) {
683
- return new Promise(function (resolve) {
684
- s.func(s.id, _this).then(function (res) {
685
- var ctrl = _this.getControl(s.id);
686
- var promise = !ctrl ? Promise.resolve(true) : ctrl.shouldSerialize();
687
- promise.then(function (should) {
688
- if (should)
689
- result[s.id] = res;
690
- resolve();
691
- });
692
- });
693
- });
694
- });
695
- Promise.all(serializers).then(function () { return resolve(result); });
696
- });
697
- };
698
- DynamicFormGroup.prototype.onFocus = function () {
699
- this.markAsUntouched({ onlySelf: true });
700
- };
701
- DynamicFormGroup.prototype.onBlur = function () {
702
- this.markAsTouched({ onlySelf: true });
703
- };
704
- DynamicFormGroup.prototype.showErrors = function () {
705
- this.markAsTouched({ onlySelf: true });
706
- this.mControls.forEach(function (ctrl) { return ctrl.showErrors(); });
707
- };
708
- DynamicFormGroup.prototype.reloadControls = function () {
709
- var _this = this;
710
- var callback = function () { };
711
- if (this.initialized === false) {
712
- this.initialized = true;
713
- this.loading = true;
714
- callback = function () {
715
- _this.loading = false;
716
- // this.cdr.detectChanges();
717
- var root = _this.form.root;
718
- root.onInit.emit(root);
719
- root.onStatusChange.emit(root);
720
- // https://github.com/angular/angular/issues/14542
721
- var statusTimer = ngxUtils.TimerUtils.createInterval();
722
- statusTimer.set(function () {
723
- if (_this.status == "PENDING")
724
- return;
725
- statusTimer.clear();
726
- root.onStatusChange.emit(root);
727
- }, 50);
728
- setTimeout(statusTimer.clear, 5000);
729
- };
730
- }
731
- var promise = new Promise(function (resolve) {
732
- _this.load().then(function () { return _this.check().then(resolve); });
733
- });
734
- promise.then(callback, callback);
735
- return promise;
736
- };
737
- DynamicFormGroup.prototype.setup = function (model, info) {
738
- var _this = this;
739
- this.mName = info.name || "";
740
- this.mModel = model;
741
- this.mControls.forEach(function (ctrl) { return _this.removeControl(ctrl.id); });
742
- this.mControls = DynamicFormGroup.createFormControls(this, info.controls);
743
- this.mControls.forEach(function (ctrl) { return _this.addControl(ctrl.id, ctrl); });
744
- this.mSerializers = DynamicFormGroup.createFormSerializers(this, info.serializers);
745
- this.mFieldSets = info.fieldSets ? info.fieldSets.reduce(function (result, fs) {
746
- result[fs.id] = fs;
747
- return result;
748
- }, {}) : getFormFieldSets(Object.getPrototypeOf(model).constructor);
749
- };
750
- DynamicFormGroup.prototype.updateModel = function (control) {
751
- var _this = this;
752
- this.model[control.id] = control.value;
753
- this.changeTimer.clear();
754
- this.changeTimer.set(function () {
755
- _this.check().then(function () { return _this.reloadControlsFrom(control, new Set()).then(function () {
756
- _this.form.root.onChange.emit(control);
757
- }); });
758
- }, 250);
759
- };
760
- DynamicFormGroup.prototype.reloadControlsFrom = function (control, controls) {
761
- var _this = this;
762
- var data = control.data;
763
- if (!data || !data.reload)
764
- return Promise.resolve();
765
- var reload = ngxUtils.ObjectUtils.isArray(data.reload) ? data.reload : [data.reload];
766
- return Promise.all(reload.map(function (id) {
767
- var nextControl = _this.getControl(id);
768
- if (!nextControl || controls.has(nextControl))
769
- return Promise.resolve();
770
- controls.add(nextControl);
771
- return new Promise(function (resolve) {
772
- nextControl.load().then(function () {
773
- _this.reloadControlsFrom(nextControl, controls).then(resolve);
774
- });
775
- });
776
- }));
777
- };
778
- return DynamicFormGroup;
779
- }(forms.FormGroup));
780
- var DynamicFormControl = /** @class */ (function (_super) {
781
- __extends(DynamicFormControl, _super);
782
- function DynamicFormControl(control, group) {
783
- var _this = _super.call(this, group.model[control.id], { updateOn: control.data.updateOn || group.updateOn }) || this;
784
- _this.control = control;
785
- _this.group = group;
786
- _this.group.addControl(control.id, _this);
787
- _this.helper = new DynamicFormControlHelper(_this.form, control);
788
- _this.helper.findProvider(_this);
789
- _this.valueChanges.subscribe(function () { return _this.group.updateModel(_this); });
790
- _this.setAsyncValidators(createValidator(_this));
791
- return _this;
792
- }
793
- Object.defineProperty(DynamicFormControl.prototype, "id", {
794
- get: function () {
795
- return this.helper.id;
796
- },
797
- enumerable: false,
798
- configurable: true
799
- });
800
- Object.defineProperty(DynamicFormControl.prototype, "type", {
801
- get: function () {
802
- return this.helper.type;
803
- },
804
- enumerable: false,
805
- configurable: true
806
- });
807
- Object.defineProperty(DynamicFormControl.prototype, "data", {
808
- get: function () {
809
- return this.helper.data;
810
- },
811
- enumerable: false,
812
- configurable: true
813
- });
814
- Object.defineProperty(DynamicFormControl.prototype, "visible", {
815
- get: function () {
816
- return this.helper.visible;
817
- },
818
- enumerable: false,
819
- configurable: true
820
- });
821
- Object.defineProperty(DynamicFormControl.prototype, "meta", {
822
- get: function () {
823
- return this.helper.meta;
824
- },
825
- enumerable: false,
826
- configurable: true
827
- });
828
- Object.defineProperty(DynamicFormControl.prototype, "form", {
829
- get: function () {
830
- return this.group.form;
831
- },
832
- enumerable: false,
833
- configurable: true
834
- });
835
- Object.defineProperty(DynamicFormControl.prototype, "injector", {
836
- get: function () {
837
- return this.form.injector;
838
- },
839
- enumerable: false,
840
- configurable: true
841
- });
842
- Object.defineProperty(DynamicFormControl.prototype, "label", {
843
- get: function () {
844
- return this.data.label !== "" ? "" + this.group.prefix + this.data.label : "";
845
- },
846
- enumerable: false,
847
- configurable: true
848
- });
849
- Object.defineProperty(DynamicFormControl.prototype, "provider", {
850
- get: function () {
851
- return this.helper.provider;
852
- },
853
- enumerable: false,
854
- configurable: true
855
- });
856
- Object.defineProperty(DynamicFormControl.prototype, "model", {
857
- get: function () {
858
- return this.group.model;
859
- },
860
- enumerable: false,
861
- configurable: true
862
- });
863
- Object.defineProperty(DynamicFormControl.prototype, "formId", {
864
- get: function () {
865
- return this.helper.formId;
866
- },
867
- enumerable: false,
868
- configurable: true
869
- });
870
- DynamicFormControl.prototype.getData = function () {
871
- return this.data;
872
- };
873
- DynamicFormControl.prototype.getControl = function (id) {
874
- return null;
875
- };
876
- DynamicFormControl.prototype.load = function () {
877
- return this.helper.load(this);
878
- };
879
- DynamicFormControl.prototype.check = function () {
880
- var _this = this;
881
- var check = this.helper.check(this);
882
- check.then(function (readonly) {
883
- if (readonly || _this.group.disabled)
884
- _this.disable({ emitEvent: false });
885
- else
886
- _this.enable({ emitEvent: false });
887
- });
888
- return check;
889
- };
890
- DynamicFormControl.prototype.shouldSerialize = function () {
891
- return this.helper.shouldSerialize(this);
892
- };
893
- DynamicFormControl.prototype.shouldValidate = function () {
894
- return this.helper.shouldValidate(this);
895
- };
896
- DynamicFormControl.prototype.serialize = function () {
897
- return Promise.resolve(this.value);
898
- };
899
- DynamicFormControl.prototype.onFocus = function () {
900
- this.markAsUntouched({ onlySelf: true });
901
- };
902
- DynamicFormControl.prototype.onBlur = function () {
903
- this.markAsTouched({ onlySelf: true });
904
- };
905
- DynamicFormControl.prototype.showErrors = function () {
906
- this.markAsTouched({ onlySelf: true });
907
- };
908
- return DynamicFormControl;
909
- }(forms.FormControl));
910
- // --- Decorator functions ---
911
- var emptyArray = [];
912
- var emptyTester = function () {
913
- return Promise.resolve(false);
914
- };
915
- var ɵ0 = emptyTester;
916
- function defaultSerializer(id, parent) {
917
- var control = parent.getControl(id);
918
- return !control ? Promise.resolve(parent.model[id]) : control.serialize();
919
- }
920
- function FormSerializable(serializer) {
921
- return function (target, propertyKey) {
922
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
923
- };
924
- }
925
- function FormInput(data) {
926
- return function (target, propertyKey) {
927
- var meta = ngxUtils.ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
928
- var type = meta ? meta.name : "";
929
- var inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
930
- switch (type) {
931
- case "Number":
932
- inputType = "number";
933
- break;
934
- case "Boolean":
935
- inputType = "checkbox";
936
- break;
937
- }
938
- defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
939
- };
940
- }
941
- function FormSelect(data) {
942
- return function (target, propertyKey) {
943
- defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
944
- };
945
- }
946
- function FormStatic(data) {
947
- return function (target, propertyKey) {
948
- defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
949
- };
950
- }
951
- function FormModel(data) {
952
- return function (target, propertyKey) {
953
- defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
954
- };
955
- }
956
- function FormFile(data) {
957
- return function (target, propertyKey) {
958
- defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
959
- };
960
- }
961
- function FormFieldSet(data) {
962
- return function (target) {
963
- var sets = getFormFieldSets(target);
964
- data.classes = data.classes || "";
965
- sets[data.id] = data;
966
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormFieldSets", sets, target);
967
- };
968
- }
969
- function provideFormGroup(component) {
970
- return {
971
- provide: FORM_GROUP_TYPE,
972
- useValue: component
973
- };
974
- }
975
- function provideFormControl(component, acceptor, loader, priority) {
976
- if (priority === void 0) { priority = 0; }
977
- return {
978
- provide: FORM_CONTROL_PROVIDER,
979
- multi: true,
980
- useValue: {
981
- component: component,
982
- priority: priority,
983
- acceptor: acceptor,
984
- loader: loader
985
- }
986
- };
987
- }
988
- function defineFormControl(target, propertyKey, control) {
989
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
990
- }
991
- function getFormFieldSets(target) {
992
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormFieldSets", target) || {};
993
- }
994
- function getFormControl(target, propertyKey) {
995
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
996
- }
997
- function getFormSerializer(target, propertyKey) {
998
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
999
- }
1000
- function createFormControl(id, type, data) {
1001
- data = data || {};
1002
- data.label = ngxUtils.ObjectUtils.isNullOrUndefined(data.label) ? id : data.label;
1003
- data.labelAlign = data.labelAlign || "left";
1004
- data.fieldSet = data.fieldSet || ngxUtils.UniqueUtils.uuid();
1005
- data.classes = data.classes || "";
1006
- data.readonly = data.readonly || emptyTester;
1007
- data.hidden = data.hidden || emptyTester;
1008
- data.validators = data.validators || emptyArray;
1009
- return {
1010
- id: id,
1011
- type: type,
1012
- data: data
1013
- };
1014
- }
1015
- function createFormInput(id, data, type) {
1016
- if (type === void 0) { type = "text"; }
1017
- var control = createFormControl(id, "input", data);
1018
- data = control.data;
1019
- data.type = data.type || type;
1020
- data.classes = !data.classes ? "form-group-" + data.type : data.classes + " form-group-" + data.type;
1021
- data.placeholder = data.placeholder || (data.type == "mask" ? "_" : "");
1022
- data.step = data.step || 1;
1023
- data.mask = data.mask || [/\w*/gi];
1024
- return control;
1025
- }
1026
- function createFormSelect(id, data) {
1027
- var control = createFormControl(id, "select", data);
1028
- data = control.data;
1029
- data.options = data.options || (function () { return Promise.resolve([]); });
1030
- data.type = data.type || "select";
1031
- var classType = data.type == "select" ? "select" : "select-" + data.type;
1032
- data.classes = !data.classes ? "form-group-" + classType : data.classes + " form-group-" + classType;
1033
- return control;
1034
- }
1035
- function createFormStatic(id, data) {
1036
- var control = createFormControl(id, "static", data);
1037
- data = control.data;
1038
- data.style = data.style || "table";
1039
- return control;
1040
- }
1041
- function createFormModel(id, data) {
1042
- var control = createFormControl(id, "model", data);
1043
- data = control.data;
1044
- data.name = data.name || "";
1045
- return control;
1046
- }
1047
- function createFormFile(id, data) {
1048
- var control = createFormControl(id, "file", data);
1049
- data = control.data;
1050
- data.accept = data.accept || ".jpg,.jpeg,.png";
1051
- data.multi = data.multi || false;
1052
- data.baseUrl = ngxUtils.ObjectUtils.isString(data.baseUrl) ? data.baseUrl : "assets/";
1053
- data.uploadUrl = ngxUtils.ObjectUtils.isString(data.uploadUrl) ? data.uploadUrl : "assets";
1054
- data.createUploadData = data.createUploadData || (function (file) {
1055
- var form = new FormData();
1056
- form.append("file", file);
1057
- return form;
1058
- });
1059
- return control;
308
+ var FORM_GROUP_TYPE = new core.InjectionToken("form-group-provider");
309
+ var FORM_CONTROL_PROVIDER = new core.InjectionToken("form-control-provider");
310
+ var FormControlComponent = /** @class */ (function () {
311
+ function FormControlComponent() {
312
+ }
313
+ Object.defineProperty(FormControlComponent.prototype, "form", {
314
+ get: function () {
315
+ return !this.control ? null : this.control.form;
316
+ },
317
+ enumerable: false,
318
+ configurable: true
319
+ });
320
+ Object.defineProperty(FormControlComponent.prototype, "data", {
321
+ get: function () {
322
+ return (!this.control ? {} : this.control.data);
323
+ },
324
+ enumerable: false,
325
+ configurable: true
326
+ });
327
+ Object.defineProperty(FormControlComponent.prototype, "value", {
328
+ get: function () {
329
+ return !this.control ? null : this.control.value;
330
+ },
331
+ enumerable: false,
332
+ configurable: true
333
+ });
334
+ Object.defineProperty(FormControlComponent.prototype, "meta", {
335
+ get: function () {
336
+ return !this.control ? null : this.control.meta;
337
+ },
338
+ enumerable: false,
339
+ configurable: true
340
+ });
341
+ Object.defineProperty(FormControlComponent.prototype, "inputClass", {
342
+ get: function () {
343
+ return true;
344
+ },
345
+ enumerable: false,
346
+ configurable: true
347
+ });
348
+ return FormControlComponent;
349
+ }());
350
+ FormControlComponent.decorators = [
351
+ { type: core.Directive }
352
+ ];
353
+ FormControlComponent.propDecorators = {
354
+ inputClass: [{ type: core.HostBinding, args: ["class.form-input",] }]
355
+ };
356
+ function createValidator(control) {
357
+ var data = control.data || {};
358
+ var validators = [data.validator].concat(data.validators || []).filter(ngxUtils.ObjectUtils.isDefined).map(function (v) {
359
+ return ngxUtils.ReflectUtils.resolve(v, control.injector);
360
+ });
361
+ return function (ctrl) { return new Promise(function (resolve) {
362
+ var control = ctrl;
363
+ control.shouldValidate().then(function (should) {
364
+ if (!should) {
365
+ resolve(null);
366
+ return;
367
+ }
368
+ var validate = validators.map(function (v) { return v(control); });
369
+ var metaValidator = control.meta.validator;
370
+ if (ngxUtils.ObjectUtils.isFunction(metaValidator)) {
371
+ validate.push(metaValidator(control));
372
+ }
373
+ Promise.all(validate).then(function (results) {
374
+ results = results.filter(function (error) { return ngxUtils.ObjectUtils.isObject(error) || ngxUtils.ObjectUtils.isString(error); });
375
+ var result = null;
376
+ if (results.length > 0) {
377
+ result = {};
378
+ results.forEach(function (error) {
379
+ if (ngxUtils.ObjectUtils.isString(error)) {
380
+ result[error] = {};
381
+ return;
382
+ }
383
+ result = Object.assign(result, error);
384
+ });
385
+ }
386
+ resolve(result);
387
+ });
388
+ });
389
+ }); };
390
+ }
391
+ var DynamicFormControlHelper = /** @class */ (function () {
392
+ function DynamicFormControlHelper(form, control) {
393
+ if (control === void 0) { control = null; }
394
+ this.form = form;
395
+ this.control = control;
396
+ this.formId = ngxUtils.UniqueUtils.uuid();
397
+ this.meta = {};
398
+ this.hidden = false;
399
+ this.dummyData = {};
400
+ this.readonlyTester = this.createTester("readonly");
401
+ this.hideTester = this.createTester("hidden");
402
+ this.serializeTester = this.createTester("shouldSerialize", function (control) {
403
+ return Promise.resolve(control.visible);
404
+ });
405
+ this.validateTester = this.createTester("shouldValidate", function (control) {
406
+ return Promise.resolve(control.visible);
407
+ });
408
+ }
409
+ Object.defineProperty(DynamicFormControlHelper.prototype, "id", {
410
+ get: function () {
411
+ return !this.control ? null : this.control.id;
412
+ },
413
+ enumerable: false,
414
+ configurable: true
415
+ });
416
+ Object.defineProperty(DynamicFormControlHelper.prototype, "type", {
417
+ get: function () {
418
+ return !this.control ? "" : this.control.type;
419
+ },
420
+ enumerable: false,
421
+ configurable: true
422
+ });
423
+ Object.defineProperty(DynamicFormControlHelper.prototype, "data", {
424
+ get: function () {
425
+ return !this.control ? this.dummyData : this.control.data || this.dummyData;
426
+ },
427
+ enumerable: false,
428
+ configurable: true
429
+ });
430
+ Object.defineProperty(DynamicFormControlHelper.prototype, "visible", {
431
+ get: function () {
432
+ return !this.hidden;
433
+ },
434
+ enumerable: false,
435
+ configurable: true
436
+ });
437
+ Object.defineProperty(DynamicFormControlHelper.prototype, "provider", {
438
+ get: function () {
439
+ return this.ctrlProvider;
440
+ },
441
+ enumerable: false,
442
+ configurable: true
443
+ });
444
+ DynamicFormControlHelper.prototype.load = function (control) {
445
+ return !this.ctrlProvider ? Promise.resolve() : this.ctrlProvider.loader(control);
446
+ };
447
+ DynamicFormControlHelper.prototype.check = function (control) {
448
+ var _this = this;
449
+ return new Promise(function (resolve) {
450
+ _this.hideTester(control).then(function (hide) {
451
+ _this.hidden = hide;
452
+ _this.readonlyTester(control).then(function (readonly) {
453
+ resolve(control.form.readonly || readonly);
454
+ });
455
+ });
456
+ });
457
+ };
458
+ DynamicFormControlHelper.prototype.shouldSerialize = function (control) {
459
+ return this.serializeTester(control);
460
+ };
461
+ DynamicFormControlHelper.prototype.shouldValidate = function (control) {
462
+ return this.validateTester(control);
463
+ };
464
+ DynamicFormControlHelper.prototype.findProvider = function (control) {
465
+ this.ctrlProvider = !this.control || !this.control.type ? null : this.form.findProvider(control);
466
+ };
467
+ DynamicFormControlHelper.prototype.createTester = function (test, defaultFunc) {
468
+ if (defaultFunc === void 0) { defaultFunc = null; }
469
+ var tester = this.data[test]
470
+ ? ngxUtils.ReflectUtils.resolve(this.data[test], this.form.injector)
471
+ : (defaultFunc || (function () { return Promise.resolve(false); }));
472
+ return function (control) { return tester(control); };
473
+ };
474
+ return DynamicFormControlHelper;
475
+ }());
476
+ var DynamicFormGroup = /** @class */ (function (_super) {
477
+ __extends(DynamicFormGroup, _super);
478
+ function DynamicFormGroup(form, control) {
479
+ if (control === void 0) { control = null; }
480
+ var _this = _super.call(this, {}, { updateOn: ((!control || !control.data) ? null : control.data.updateOn) || form.updateOn || "blur" }) || this;
481
+ _this.form = form;
482
+ _this.mName = "";
483
+ _this.mModel = {};
484
+ _this.mControls = [];
485
+ _this.mSerializers = [];
486
+ _this.mFieldSets = {};
487
+ _this.helper = new DynamicFormControlHelper(form, control);
488
+ _this.helper.findProvider(_this);
489
+ _this.initialized = false;
490
+ _this.loading = false;
491
+ _this.changeTimer = ngxUtils.TimerUtils.createTimeout();
492
+ _this.statusChanges.subscribe(function () {
493
+ var root = _this.form.root;
494
+ root.onStatusChange.emit(root);
495
+ });
496
+ _this.setAsyncValidators(createValidator(_this));
497
+ return _this;
498
+ }
499
+ Object.defineProperty(DynamicFormGroup.prototype, "id", {
500
+ get: function () {
501
+ return this.helper.id;
502
+ },
503
+ enumerable: false,
504
+ configurable: true
505
+ });
506
+ Object.defineProperty(DynamicFormGroup.prototype, "type", {
507
+ get: function () {
508
+ return this.helper.type;
509
+ },
510
+ enumerable: false,
511
+ configurable: true
512
+ });
513
+ Object.defineProperty(DynamicFormGroup.prototype, "data", {
514
+ get: function () {
515
+ return this.helper.data;
516
+ },
517
+ enumerable: false,
518
+ configurable: true
519
+ });
520
+ Object.defineProperty(DynamicFormGroup.prototype, "visible", {
521
+ get: function () {
522
+ return this.helper.visible;
523
+ },
524
+ enumerable: false,
525
+ configurable: true
526
+ });
527
+ Object.defineProperty(DynamicFormGroup.prototype, "meta", {
528
+ get: function () {
529
+ return this.helper.meta;
530
+ },
531
+ enumerable: false,
532
+ configurable: true
533
+ });
534
+ Object.defineProperty(DynamicFormGroup.prototype, "injector", {
535
+ get: function () {
536
+ return this.form.injector;
537
+ },
538
+ enumerable: false,
539
+ configurable: true
540
+ });
541
+ Object.defineProperty(DynamicFormGroup.prototype, "label", {
542
+ get: function () {
543
+ return this.data.label !== "" ? "" + this.prefix + this.data.label : "";
544
+ },
545
+ enumerable: false,
546
+ configurable: true
547
+ });
548
+ Object.defineProperty(DynamicFormGroup.prototype, "provider", {
549
+ get: function () {
550
+ return this.helper.provider;
551
+ },
552
+ enumerable: false,
553
+ configurable: true
554
+ });
555
+ Object.defineProperty(DynamicFormGroup.prototype, "model", {
556
+ get: function () {
557
+ return this.mModel;
558
+ },
559
+ enumerable: false,
560
+ configurable: true
561
+ });
562
+ Object.defineProperty(DynamicFormGroup.prototype, "formId", {
563
+ get: function () {
564
+ return this.helper.formId;
565
+ },
566
+ enumerable: false,
567
+ configurable: true
568
+ });
569
+ Object.defineProperty(DynamicFormGroup.prototype, "formControls", {
570
+ get: function () {
571
+ return this.mControls || [];
572
+ },
573
+ enumerable: false,
574
+ configurable: true
575
+ });
576
+ Object.defineProperty(DynamicFormGroup.prototype, "formFields", {
577
+ get: function () {
578
+ return this.mFieldSets || {};
579
+ },
580
+ enumerable: false,
581
+ configurable: true
582
+ });
583
+ Object.defineProperty(DynamicFormGroup.prototype, "prefix", {
584
+ get: function () {
585
+ return !this.name ? "" : this.name + ".";
586
+ },
587
+ enumerable: false,
588
+ configurable: true
589
+ });
590
+ Object.defineProperty(DynamicFormGroup.prototype, "name", {
591
+ get: function () {
592
+ return this.mName;
593
+ },
594
+ enumerable: false,
595
+ configurable: true
596
+ });
597
+ Object.defineProperty(DynamicFormGroup.prototype, "state", {
598
+ get: function () {
599
+ return (this.loading ? "LOADING" : this.status);
600
+ },
601
+ enumerable: false,
602
+ configurable: true
603
+ });
604
+ DynamicFormGroup.createFormControls = function (group, controls) {
605
+ if (!controls && ngxUtils.ObjectUtils.isObject(group.model)) {
606
+ var props = Object.keys(group.model);
607
+ controls = props.map(function (id) {
608
+ return getFormControl(group.model, id);
609
+ }).filter(ngxUtils.ObjectUtils.isDefined);
610
+ }
611
+ if (!controls)
612
+ return [];
613
+ return controls.map(function (ctrl) {
614
+ if (ctrl.type == "model") {
615
+ var subGroup = new DynamicFormGroup(group.form, ctrl);
616
+ var model = group.model[ctrl.id] || {};
617
+ var data = subGroup.getData();
618
+ data.name = data.name || group.name;
619
+ subGroup.setup(model, data);
620
+ group.model[ctrl.id] = model;
621
+ group.addControl(subGroup.id, subGroup);
622
+ return subGroup;
623
+ }
624
+ return new DynamicFormControl(ctrl, group);
625
+ });
626
+ };
627
+ DynamicFormGroup.createFormSerializers = function (group, serializers) {
628
+ if (!serializers && ngxUtils.ObjectUtils.isObject(group.model)) {
629
+ var props = Object.keys(group.model);
630
+ serializers = props.reduce(function (result, id) {
631
+ var serializer = getFormSerializer(group.model, id);
632
+ if (!serializer)
633
+ return result;
634
+ result[id] = serializer;
635
+ return result;
636
+ }, {});
637
+ }
638
+ if (!serializers)
639
+ return [];
640
+ return Object.keys(serializers).map(function (id) {
641
+ var serializer = serializers[id] || defaultSerializer;
642
+ return !serializer ? null : {
643
+ id: id,
644
+ func: ngxUtils.ReflectUtils.resolve(serializer, group.injector)
645
+ };
646
+ });
647
+ };
648
+ DynamicFormGroup.prototype.getData = function () {
649
+ return this.data;
650
+ };
651
+ DynamicFormGroup.prototype.getControl = function (id) {
652
+ return this.get(id);
653
+ };
654
+ DynamicFormGroup.prototype.load = function () {
655
+ var promises = this.mControls.map(function (c) { return c.load(); });
656
+ promises.push(this.helper.load(this));
657
+ return Promise.all(promises);
658
+ };
659
+ DynamicFormGroup.prototype.check = function () {
660
+ var _this = this;
661
+ return new Promise(function (resolve) {
662
+ _this.helper.check(_this).then(function (readonly) {
663
+ if (readonly)
664
+ _this.disable({ emitEvent: false });
665
+ else
666
+ _this.enable({ emitEvent: false });
667
+ var promises = _this.mControls.map(function (c) { return c.check(); });
668
+ Promise.all(promises).then(resolve);
669
+ });
670
+ });
671
+ };
672
+ DynamicFormGroup.prototype.shouldSerialize = function () {
673
+ return this.helper.shouldSerialize(this);
674
+ };
675
+ DynamicFormGroup.prototype.shouldValidate = function () {
676
+ return this.helper.shouldValidate(this);
677
+ };
678
+ DynamicFormGroup.prototype.serialize = function () {
679
+ var _this = this;
680
+ return new Promise(function (resolve) {
681
+ var result = {};
682
+ var serializers = _this.mSerializers.map(function (s) {
683
+ return new Promise(function (resolve) {
684
+ s.func(s.id, _this).then(function (res) {
685
+ var ctrl = _this.getControl(s.id);
686
+ var promise = !ctrl ? Promise.resolve(true) : ctrl.shouldSerialize();
687
+ promise.then(function (should) {
688
+ if (should)
689
+ result[s.id] = res;
690
+ resolve();
691
+ });
692
+ });
693
+ });
694
+ });
695
+ Promise.all(serializers).then(function () { return resolve(result); });
696
+ });
697
+ };
698
+ DynamicFormGroup.prototype.onFocus = function () {
699
+ this.markAsUntouched({ onlySelf: true });
700
+ };
701
+ DynamicFormGroup.prototype.onBlur = function () {
702
+ this.markAsTouched({ onlySelf: true });
703
+ };
704
+ DynamicFormGroup.prototype.showErrors = function () {
705
+ this.markAsTouched({ onlySelf: true });
706
+ this.mControls.forEach(function (ctrl) { return ctrl.showErrors(); });
707
+ };
708
+ DynamicFormGroup.prototype.reloadControls = function () {
709
+ var _this = this;
710
+ var callback = function () { };
711
+ if (this.initialized === false) {
712
+ this.initialized = true;
713
+ this.loading = true;
714
+ callback = function () {
715
+ _this.loading = false;
716
+ // this.cdr.detectChanges();
717
+ var root = _this.form.root;
718
+ root.onInit.emit(root);
719
+ root.onStatusChange.emit(root);
720
+ // https://github.com/angular/angular/issues/14542
721
+ var statusTimer = ngxUtils.TimerUtils.createInterval();
722
+ statusTimer.set(function () {
723
+ if (_this.status == "PENDING")
724
+ return;
725
+ statusTimer.clear();
726
+ root.onStatusChange.emit(root);
727
+ }, 50);
728
+ setTimeout(statusTimer.clear, 5000);
729
+ };
730
+ }
731
+ var promise = new Promise(function (resolve) {
732
+ _this.load().then(function () { return _this.check().then(resolve); });
733
+ });
734
+ promise.then(callback, callback);
735
+ return promise;
736
+ };
737
+ DynamicFormGroup.prototype.setup = function (model, info) {
738
+ var _this = this;
739
+ this.mName = info.name || "";
740
+ this.mModel = model;
741
+ this.mControls.forEach(function (ctrl) { return _this.removeControl(ctrl.id); });
742
+ this.mControls = DynamicFormGroup.createFormControls(this, info.controls);
743
+ this.mControls.forEach(function (ctrl) { return _this.addControl(ctrl.id, ctrl); });
744
+ this.mSerializers = DynamicFormGroup.createFormSerializers(this, info.serializers);
745
+ this.mFieldSets = info.fieldSets ? info.fieldSets.reduce(function (result, fs) {
746
+ result[fs.id] = fs;
747
+ return result;
748
+ }, {}) : getFormFieldSets(Object.getPrototypeOf(model).constructor);
749
+ };
750
+ DynamicFormGroup.prototype.updateModel = function (control) {
751
+ var _this = this;
752
+ this.model[control.id] = control.value;
753
+ this.changeTimer.clear();
754
+ this.changeTimer.set(function () {
755
+ _this.check().then(function () { return _this.reloadControlsFrom(control, new Set()).then(function () {
756
+ _this.form.root.onChange.emit(control);
757
+ }); });
758
+ }, 250);
759
+ };
760
+ DynamicFormGroup.prototype.reloadControlsFrom = function (control, controls) {
761
+ var _this = this;
762
+ var data = control.data;
763
+ if (!data || !data.reload)
764
+ return Promise.resolve();
765
+ var reload = ngxUtils.ObjectUtils.isArray(data.reload) ? data.reload : [data.reload];
766
+ return Promise.all(reload.map(function (id) {
767
+ var nextControl = _this.getControl(id);
768
+ if (!nextControl || controls.has(nextControl))
769
+ return Promise.resolve();
770
+ controls.add(nextControl);
771
+ return new Promise(function (resolve) {
772
+ nextControl.load().then(function () {
773
+ _this.reloadControlsFrom(nextControl, controls).then(resolve);
774
+ });
775
+ });
776
+ }));
777
+ };
778
+ return DynamicFormGroup;
779
+ }(forms.FormGroup));
780
+ var DynamicFormControl = /** @class */ (function (_super) {
781
+ __extends(DynamicFormControl, _super);
782
+ function DynamicFormControl(control, group) {
783
+ var _this = _super.call(this, group.model[control.id], { updateOn: control.data.updateOn || group.updateOn }) || this;
784
+ _this.control = control;
785
+ _this.group = group;
786
+ _this.group.addControl(control.id, _this);
787
+ _this.helper = new DynamicFormControlHelper(_this.form, control);
788
+ _this.helper.findProvider(_this);
789
+ _this.valueChanges.subscribe(function () { return _this.group.updateModel(_this); });
790
+ _this.setAsyncValidators(createValidator(_this));
791
+ return _this;
792
+ }
793
+ Object.defineProperty(DynamicFormControl.prototype, "id", {
794
+ get: function () {
795
+ return this.helper.id;
796
+ },
797
+ enumerable: false,
798
+ configurable: true
799
+ });
800
+ Object.defineProperty(DynamicFormControl.prototype, "type", {
801
+ get: function () {
802
+ return this.helper.type;
803
+ },
804
+ enumerable: false,
805
+ configurable: true
806
+ });
807
+ Object.defineProperty(DynamicFormControl.prototype, "data", {
808
+ get: function () {
809
+ return this.helper.data;
810
+ },
811
+ enumerable: false,
812
+ configurable: true
813
+ });
814
+ Object.defineProperty(DynamicFormControl.prototype, "visible", {
815
+ get: function () {
816
+ return this.helper.visible;
817
+ },
818
+ enumerable: false,
819
+ configurable: true
820
+ });
821
+ Object.defineProperty(DynamicFormControl.prototype, "meta", {
822
+ get: function () {
823
+ return this.helper.meta;
824
+ },
825
+ enumerable: false,
826
+ configurable: true
827
+ });
828
+ Object.defineProperty(DynamicFormControl.prototype, "form", {
829
+ get: function () {
830
+ return this.group.form;
831
+ },
832
+ enumerable: false,
833
+ configurable: true
834
+ });
835
+ Object.defineProperty(DynamicFormControl.prototype, "injector", {
836
+ get: function () {
837
+ return this.form.injector;
838
+ },
839
+ enumerable: false,
840
+ configurable: true
841
+ });
842
+ Object.defineProperty(DynamicFormControl.prototype, "label", {
843
+ get: function () {
844
+ return this.data.label !== "" ? "" + this.group.prefix + this.data.label : "";
845
+ },
846
+ enumerable: false,
847
+ configurable: true
848
+ });
849
+ Object.defineProperty(DynamicFormControl.prototype, "provider", {
850
+ get: function () {
851
+ return this.helper.provider;
852
+ },
853
+ enumerable: false,
854
+ configurable: true
855
+ });
856
+ Object.defineProperty(DynamicFormControl.prototype, "model", {
857
+ get: function () {
858
+ return this.group.model;
859
+ },
860
+ enumerable: false,
861
+ configurable: true
862
+ });
863
+ Object.defineProperty(DynamicFormControl.prototype, "formId", {
864
+ get: function () {
865
+ return this.helper.formId;
866
+ },
867
+ enumerable: false,
868
+ configurable: true
869
+ });
870
+ DynamicFormControl.prototype.getData = function () {
871
+ return this.data;
872
+ };
873
+ DynamicFormControl.prototype.getControl = function (id) {
874
+ return null;
875
+ };
876
+ DynamicFormControl.prototype.load = function () {
877
+ return this.helper.load(this);
878
+ };
879
+ DynamicFormControl.prototype.check = function () {
880
+ var _this = this;
881
+ var check = this.helper.check(this);
882
+ check.then(function (readonly) {
883
+ if (readonly || _this.group.disabled)
884
+ _this.disable({ emitEvent: false });
885
+ else
886
+ _this.enable({ emitEvent: false });
887
+ });
888
+ return check;
889
+ };
890
+ DynamicFormControl.prototype.shouldSerialize = function () {
891
+ return this.helper.shouldSerialize(this);
892
+ };
893
+ DynamicFormControl.prototype.shouldValidate = function () {
894
+ return this.helper.shouldValidate(this);
895
+ };
896
+ DynamicFormControl.prototype.serialize = function () {
897
+ return Promise.resolve(this.value);
898
+ };
899
+ DynamicFormControl.prototype.onFocus = function () {
900
+ this.markAsUntouched({ onlySelf: true });
901
+ };
902
+ DynamicFormControl.prototype.onBlur = function () {
903
+ this.markAsTouched({ onlySelf: true });
904
+ };
905
+ DynamicFormControl.prototype.showErrors = function () {
906
+ this.markAsTouched({ onlySelf: true });
907
+ };
908
+ return DynamicFormControl;
909
+ }(forms.FormControl));
910
+ // --- Decorator functions ---
911
+ var emptyArray = [];
912
+ var emptyTester = function () {
913
+ return Promise.resolve(false);
914
+ };
915
+ var ɵ0 = emptyTester;
916
+ function defaultSerializer(id, parent) {
917
+ var control = parent.getControl(id);
918
+ return !control ? Promise.resolve(parent.model[id]) : control.serialize();
919
+ }
920
+ function FormSerializable(serializer) {
921
+ return function (target, propertyKey) {
922
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
923
+ };
924
+ }
925
+ function FormInput(data) {
926
+ return function (target, propertyKey) {
927
+ var meta = ngxUtils.ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
928
+ var type = meta ? meta.name : "";
929
+ var inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
930
+ switch (type) {
931
+ case "Number":
932
+ inputType = "number";
933
+ break;
934
+ case "Boolean":
935
+ inputType = "checkbox";
936
+ break;
937
+ }
938
+ defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
939
+ };
940
+ }
941
+ function FormSelect(data) {
942
+ return function (target, propertyKey) {
943
+ defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
944
+ };
945
+ }
946
+ function FormStatic(data) {
947
+ return function (target, propertyKey) {
948
+ defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
949
+ };
950
+ }
951
+ function FormModel(data) {
952
+ return function (target, propertyKey) {
953
+ defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
954
+ };
955
+ }
956
+ function FormFile(data) {
957
+ return function (target, propertyKey) {
958
+ defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
959
+ };
960
+ }
961
+ function FormFieldSet(data) {
962
+ return function (target) {
963
+ var sets = getFormFieldSets(target);
964
+ data.classes = data.classes || "";
965
+ sets[data.id] = data;
966
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormFieldSets", sets, target);
967
+ };
968
+ }
969
+ function provideFormGroup(component) {
970
+ return {
971
+ provide: FORM_GROUP_TYPE,
972
+ useValue: component
973
+ };
974
+ }
975
+ function provideFormControl(component, acceptor, loader, priority) {
976
+ if (priority === void 0) { priority = 0; }
977
+ return {
978
+ provide: FORM_CONTROL_PROVIDER,
979
+ multi: true,
980
+ useValue: {
981
+ component: component,
982
+ priority: priority,
983
+ acceptor: acceptor,
984
+ loader: loader
985
+ }
986
+ };
987
+ }
988
+ function defineFormControl(target, propertyKey, control) {
989
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
990
+ }
991
+ function getFormFieldSets(target) {
992
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormFieldSets", target) || {};
993
+ }
994
+ function getFormControl(target, propertyKey) {
995
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
996
+ }
997
+ function getFormSerializer(target, propertyKey) {
998
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
999
+ }
1000
+ function createFormControl(id, type, data) {
1001
+ data = data || {};
1002
+ data.label = ngxUtils.ObjectUtils.isNullOrUndefined(data.label) ? id : data.label;
1003
+ data.labelAlign = data.labelAlign || "left";
1004
+ data.fieldSet = data.fieldSet || ngxUtils.UniqueUtils.uuid();
1005
+ data.classes = data.classes || "";
1006
+ data.readonly = data.readonly || emptyTester;
1007
+ data.hidden = data.hidden || emptyTester;
1008
+ data.validators = data.validators || emptyArray;
1009
+ return {
1010
+ id: id,
1011
+ type: type,
1012
+ data: data
1013
+ };
1014
+ }
1015
+ function createFormInput(id, data, type) {
1016
+ if (type === void 0) { type = "text"; }
1017
+ var control = createFormControl(id, "input", data);
1018
+ data = control.data;
1019
+ data.type = data.type || type;
1020
+ data.classes = !data.classes ? "form-group-" + data.type : data.classes + " form-group-" + data.type;
1021
+ data.placeholder = data.placeholder || (data.type == "mask" ? "_" : "");
1022
+ data.step = data.step || 1;
1023
+ data.mask = data.mask || [/\w*/gi];
1024
+ return control;
1025
+ }
1026
+ function createFormSelect(id, data) {
1027
+ var control = createFormControl(id, "select", data);
1028
+ data = control.data;
1029
+ data.options = data.options || (function () { return Promise.resolve([]); });
1030
+ data.type = data.type || "select";
1031
+ var classType = data.type == "select" ? "select" : "select-" + data.type;
1032
+ data.classes = !data.classes ? "form-group-" + classType : data.classes + " form-group-" + classType;
1033
+ return control;
1034
+ }
1035
+ function createFormStatic(id, data) {
1036
+ var control = createFormControl(id, "static", data);
1037
+ data = control.data;
1038
+ data.style = data.style || "table";
1039
+ return control;
1040
+ }
1041
+ function createFormModel(id, data) {
1042
+ var control = createFormControl(id, "model", data);
1043
+ data = control.data;
1044
+ data.name = data.name || "";
1045
+ return control;
1046
+ }
1047
+ function createFormFile(id, data) {
1048
+ var control = createFormControl(id, "file", data);
1049
+ data = control.data;
1050
+ data.accept = data.accept || ".jpg,.jpeg,.png";
1051
+ data.multi = data.multi || false;
1052
+ data.baseUrl = ngxUtils.ObjectUtils.isString(data.baseUrl) ? data.baseUrl : "assets/";
1053
+ data.uploadUrl = ngxUtils.ObjectUtils.isString(data.uploadUrl) ? data.uploadUrl : "assets";
1054
+ data.createUploadData = data.createUploadData || (function (file) {
1055
+ var form = new FormData();
1056
+ form.append("file", file);
1057
+ return form;
1058
+ });
1059
+ return control;
1060
1060
  }
1061
1061
 
1062
- var DynamicFormService = /** @class */ (function () {
1063
- function DynamicFormService(components, groupType, resolver, injector) {
1064
- this.components = components;
1065
- this.groupType = groupType;
1066
- this.resolver = resolver;
1067
- this.injector = injector;
1068
- }
1069
- DynamicFormService.prototype.findProvider = function (control) {
1070
- if (!control)
1071
- return null;
1072
- var providers = this.components.filter(function (p) { return p.acceptor(control); });
1073
- if (providers.length == 0) {
1074
- throw new Error("No component provider for control: " + JSON.stringify({
1075
- id: control.id,
1076
- type: control.type,
1077
- data: control.data
1078
- }));
1079
- }
1080
- // Sort providers
1081
- providers.sort(function (a, b) { return ngxUtils.ObjectUtils.compare(a.priority, b.priority); });
1082
- return providers[0];
1083
- };
1084
- DynamicFormService.prototype.createComponent = function (vcr, provider) {
1085
- vcr.clear();
1086
- if (!provider)
1087
- return null;
1088
- var factory = this.resolver.resolveComponentFactory(provider.component);
1089
- return vcr.createComponent(factory).instance;
1090
- };
1091
- DynamicFormService.prototype.createGroup = function (vcr) {
1092
- vcr.clear();
1093
- var factory = this.resolver.resolveComponentFactory(this.groupType);
1094
- return vcr.createComponent(factory).instance;
1095
- };
1096
- return DynamicFormService;
1097
- }());
1098
- DynamicFormService.decorators = [
1099
- { type: core.Injectable }
1100
- ];
1101
- DynamicFormService.ctorParameters = function () { return [
1102
- { type: Array, decorators: [{ type: core.Inject, args: [FORM_CONTROL_PROVIDER,] }] },
1103
- { type: core.Type, decorators: [{ type: core.Inject, args: [FORM_GROUP_TYPE,] }] },
1104
- { type: core.ComponentFactoryResolver },
1105
- { type: core.Injector }
1062
+ var DynamicFormService = /** @class */ (function () {
1063
+ function DynamicFormService(components, groupType, resolver, injector) {
1064
+ this.components = components;
1065
+ this.groupType = groupType;
1066
+ this.resolver = resolver;
1067
+ this.injector = injector;
1068
+ }
1069
+ DynamicFormService.prototype.findProvider = function (control) {
1070
+ if (!control)
1071
+ return null;
1072
+ var providers = this.components.filter(function (p) { return p.acceptor(control); });
1073
+ if (providers.length == 0) {
1074
+ throw new Error("No component provider for control: " + JSON.stringify({
1075
+ id: control.id,
1076
+ type: control.type,
1077
+ data: control.data
1078
+ }));
1079
+ }
1080
+ // Sort providers
1081
+ providers.sort(function (a, b) { return ngxUtils.ObjectUtils.compare(a.priority, b.priority); });
1082
+ return providers[0];
1083
+ };
1084
+ DynamicFormService.prototype.createComponent = function (vcr, provider) {
1085
+ vcr.clear();
1086
+ if (!provider)
1087
+ return null;
1088
+ var factory = this.resolver.resolveComponentFactory(provider.component);
1089
+ return vcr.createComponent(factory).instance;
1090
+ };
1091
+ DynamicFormService.prototype.createGroup = function (vcr) {
1092
+ vcr.clear();
1093
+ var factory = this.resolver.resolveComponentFactory(this.groupType);
1094
+ return vcr.createComponent(factory).instance;
1095
+ };
1096
+ return DynamicFormService;
1097
+ }());
1098
+ DynamicFormService.decorators = [
1099
+ { type: core.Injectable }
1100
+ ];
1101
+ DynamicFormService.ctorParameters = function () { return [
1102
+ { type: Array, decorators: [{ type: core.Inject, args: [FORM_CONTROL_PROVIDER,] }] },
1103
+ { type: core.Type, decorators: [{ type: core.Inject, args: [FORM_GROUP_TYPE,] }] },
1104
+ { type: core.ComponentFactoryResolver },
1105
+ { type: core.Injector }
1106
1106
  ]; };
1107
1107
 
1108
- var FormUtilities = /** @class */ (function () {
1109
- function FormUtilities() {
1110
- }
1111
- FormUtilities.checkField = function (expression) {
1112
- if (expression === void 0) { expression = "true"; }
1113
- // @dynamic
1114
- var lambda = function (control) {
1115
- return Promise.resolve(ngxUtils.ObjectUtils.evaluate(expression, { control: control }));
1116
- };
1117
- return lambda;
1118
- };
1119
- FormUtilities.checkReadonly = function (control) {
1120
- return Promise.resolve(control.visible && !control.disabled);
1121
- };
1122
- FormUtilities.readonly = function () {
1123
- return Promise.resolve(true);
1124
- };
1125
- FormUtilities.validateJSON = function (control) {
1126
- var value = control.value;
1127
- if (!value)
1128
- return Promise.resolve(null);
1129
- try {
1130
- JSON.parse(value);
1131
- return Promise.resolve(null);
1132
- }
1133
- catch (e) {
1134
- return Promise.resolve("error.not-valid-json");
1135
- }
1136
- };
1137
- FormUtilities.validateRequired = function (control) {
1138
- var value = control.value;
1139
- return Promise.resolve(!ngxUtils.ObjectUtils.isNumber(value) && !value ? "error.required" : null);
1140
- };
1141
- FormUtilities.validateMinLength = function (length) {
1142
- // @dynamic
1143
- var lambda = function (control) {
1144
- var value = control.value;
1145
- if (!ngxUtils.ObjectUtils.isString(value) || value.length < length) {
1146
- return Promise.resolve({ "error.min-length": { length: length } });
1147
- }
1148
- return Promise.resolve(null);
1149
- };
1150
- return lambda;
1151
- };
1152
- FormUtilities.validateMaxLength = function (length) {
1153
- // @dynamic
1154
- var lambda = function (control) {
1155
- var value = control.value;
1156
- if (!ngxUtils.ObjectUtils.isString(value) || value.length > length) {
1157
- return Promise.resolve({ "error.max-length": { length: length } });
1158
- }
1159
- return Promise.resolve(null);
1160
- };
1161
- return lambda;
1162
- };
1163
- FormUtilities.validateRequiredTranslation = function (control) {
1164
- var value = control.value;
1165
- if (!value || value.length == 0)
1166
- return Promise.resolve("error.required");
1167
- return Promise.resolve(value.findIndex(function (t) { return (t.lang == "de" || t.lang == "en") && !t.translation; }) < 0 ? null : "error.required");
1168
- };
1169
- FormUtilities.validateEmail = function (control) {
1170
- var value = control.value;
1171
- if (!value)
1172
- return Promise.resolve(null);
1173
- var emailRegexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1174
- return Promise.resolve(emailRegexp.test(value) ? null : "error.invalid-email");
1175
- };
1176
- FormUtilities.validatePhone = function (control) {
1177
- var value = control.value;
1178
- if (!value)
1179
- return Promise.resolve(null);
1180
- var phoneRegexp = /^(?:\d){10,12}$/;
1181
- return Promise.resolve(phoneRegexp.test(value) ? null : "error.invalid-phone");
1182
- };
1183
- FormUtilities.serializeLogo = function (id, parent) {
1184
- var value = parent.model[id];
1185
- return Promise.resolve(!value || value.length == 0 ? null : value);
1186
- };
1187
- FormUtilities.serializeFile = function (id, parent) {
1188
- var value = parent.model[id];
1189
- if (ngxUtils.ObjectUtils.isBlob(value))
1190
- return Promise.resolve(value);
1191
- return Promise.resolve(!ngxUtils.ObjectUtils.isString(value) || !value.startsWith("data:") ? null : ngxUtils.FileUtils.dataToBlob(value));
1192
- };
1193
- FormUtilities.serializeNumber = function (id, parent) {
1194
- var value = parent.model[id];
1195
- return Promise.resolve(!value || value.length == 0 ? 0 : parseFloat(value));
1196
- };
1197
- FormUtilities.serializeJSON = function (id, parent) {
1198
- var value = parent.model[id];
1199
- return Promise.resolve(!value ? {} : JSON.parse(value));
1200
- };
1201
- FormUtilities.serializeDate = function (date, format, defaultValue) {
1202
- if (format === void 0) { format = "yyyy-MM-dd"; }
1203
- if (defaultValue === void 0) { defaultValue = ""; }
1204
- // @dynamic
1205
- var lambda = function (id, parent) {
1206
- var value = parent.model[id];
1207
- if (!ngxUtils.ObjectUtils.isDate(value))
1208
- return Promise.resolve(value || defaultValue);
1209
- return Promise.resolve(!format ? value : date.transform(value, format));
1210
- };
1211
- return lambda;
1212
- };
1213
- return FormUtilities;
1214
- }());
1215
- __decorate([
1216
- ngxUtils.FactoryDependencies(common.DatePipe)
1108
+ var FormUtilities = /** @class */ (function () {
1109
+ function FormUtilities() {
1110
+ }
1111
+ FormUtilities.checkField = function (expression) {
1112
+ if (expression === void 0) { expression = "true"; }
1113
+ // @dynamic
1114
+ var lambda = function (control) {
1115
+ return Promise.resolve(ngxUtils.ObjectUtils.evaluate(expression, { control: control }));
1116
+ };
1117
+ return lambda;
1118
+ };
1119
+ FormUtilities.checkReadonly = function (control) {
1120
+ return Promise.resolve(control.visible && !control.disabled);
1121
+ };
1122
+ FormUtilities.readonly = function () {
1123
+ return Promise.resolve(true);
1124
+ };
1125
+ FormUtilities.validateJSON = function (control) {
1126
+ var value = control.value;
1127
+ if (!value)
1128
+ return Promise.resolve(null);
1129
+ try {
1130
+ JSON.parse(value);
1131
+ return Promise.resolve(null);
1132
+ }
1133
+ catch (e) {
1134
+ return Promise.resolve("error.not-valid-json");
1135
+ }
1136
+ };
1137
+ FormUtilities.validateRequired = function (control) {
1138
+ var value = control.value;
1139
+ return Promise.resolve(!ngxUtils.ObjectUtils.isNumber(value) && !value ? "error.required" : null);
1140
+ };
1141
+ FormUtilities.validateMinLength = function (length) {
1142
+ // @dynamic
1143
+ var lambda = function (control) {
1144
+ var value = control.value;
1145
+ if (!ngxUtils.ObjectUtils.isString(value) || value.length < length) {
1146
+ return Promise.resolve({ "error.min-length": { length: length } });
1147
+ }
1148
+ return Promise.resolve(null);
1149
+ };
1150
+ return lambda;
1151
+ };
1152
+ FormUtilities.validateMaxLength = function (length) {
1153
+ // @dynamic
1154
+ var lambda = function (control) {
1155
+ var value = control.value;
1156
+ if (!ngxUtils.ObjectUtils.isString(value) || value.length > length) {
1157
+ return Promise.resolve({ "error.max-length": { length: length } });
1158
+ }
1159
+ return Promise.resolve(null);
1160
+ };
1161
+ return lambda;
1162
+ };
1163
+ FormUtilities.validateRequiredTranslation = function (control) {
1164
+ var value = control.value;
1165
+ if (!value || value.length == 0)
1166
+ return Promise.resolve("error.required");
1167
+ return Promise.resolve(value.findIndex(function (t) { return (t.lang == "de" || t.lang == "en") && !t.translation; }) < 0 ? null : "error.required");
1168
+ };
1169
+ FormUtilities.validateEmail = function (control) {
1170
+ var value = control.value;
1171
+ if (!value)
1172
+ return Promise.resolve(null);
1173
+ var emailRegexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1174
+ return Promise.resolve(emailRegexp.test(value) ? null : "error.invalid-email");
1175
+ };
1176
+ FormUtilities.validatePhone = function (control) {
1177
+ var value = control.value;
1178
+ if (!value)
1179
+ return Promise.resolve(null);
1180
+ var phoneRegexp = /^(?:\d){10,12}$/;
1181
+ return Promise.resolve(phoneRegexp.test(value) ? null : "error.invalid-phone");
1182
+ };
1183
+ FormUtilities.serializeLogo = function (id, parent) {
1184
+ var value = parent.model[id];
1185
+ return Promise.resolve(!value || value.length == 0 ? null : value);
1186
+ };
1187
+ FormUtilities.serializeFile = function (id, parent) {
1188
+ var value = parent.model[id];
1189
+ if (ngxUtils.ObjectUtils.isBlob(value))
1190
+ return Promise.resolve(value);
1191
+ return Promise.resolve(!ngxUtils.ObjectUtils.isString(value) || !value.startsWith("data:") ? null : ngxUtils.FileUtils.dataToBlob(value));
1192
+ };
1193
+ FormUtilities.serializeNumber = function (id, parent) {
1194
+ var value = parent.model[id];
1195
+ return Promise.resolve(!value || value.length == 0 ? 0 : parseFloat(value));
1196
+ };
1197
+ FormUtilities.serializeJSON = function (id, parent) {
1198
+ var value = parent.model[id];
1199
+ return Promise.resolve(!value ? {} : JSON.parse(value));
1200
+ };
1201
+ FormUtilities.serializeDate = function (date, format, defaultValue) {
1202
+ if (format === void 0) { format = "yyyy-MM-dd"; }
1203
+ if (defaultValue === void 0) { defaultValue = ""; }
1204
+ // @dynamic
1205
+ var lambda = function (id, parent) {
1206
+ var value = parent.model[id];
1207
+ if (!ngxUtils.ObjectUtils.isDate(value))
1208
+ return Promise.resolve(value || defaultValue);
1209
+ return Promise.resolve(!format ? value : date.transform(value, format));
1210
+ };
1211
+ return lambda;
1212
+ };
1213
+ return FormUtilities;
1214
+ }());
1215
+ __decorate([
1216
+ ngxUtils.FactoryDependencies(common.DatePipe)
1217
1217
  ], FormUtilities, "serializeDate", null);
1218
1218
 
1219
- var OpenApiService = /** @class */ (function () {
1220
- function OpenApiService(api) {
1221
- var _this = this;
1222
- this.api = api;
1223
- var baseUrl = this.api.url("").replace("api/", "api-docs");
1224
- this.schemas = {};
1225
- this.schemasPromise = new Promise((function (resolve) {
1226
- _this.api.client.get(baseUrl).subscribe(function (res) {
1227
- _this.schemas = res.definitions || {};
1228
- resolve(_this.schemas);
1229
- }, function () {
1230
- resolve({});
1231
- });
1232
- }));
1233
- }
1234
- OpenApiService.prototype.getFormInputsForSchema = function (name) {
1235
- var _this = this;
1236
- this.api.cache = {};
1237
- return this.schemasPromise.then(function (schemas) {
1238
- var schema = schemas[name];
1239
- var inputs = _this.getFormInputsForSchemaDef(schema);
1240
- return inputs;
1241
- });
1242
- };
1243
- OpenApiService.prototype.getFormInputsForSchemaDef = function (schema) {
1244
- var _this = this;
1245
- var inputs = {};
1246
- if (!schema)
1247
- return inputs;
1248
- inputs.schema = schema;
1249
- inputs.serializers = {};
1250
- inputs.controls = Object.keys(schema.properties || {}).map(function (p) {
1251
- var property = schema.properties[p];
1252
- property.id = p;
1253
- inputs.serializers[p] = function (id, parent) {
1254
- return Promise.resolve(parent.model[id]);
1255
- };
1256
- return _this.getFormControlForProperty(property, schema);
1257
- }).filter(function (t) { return null !== t; });
1258
- return inputs;
1259
- };
1260
- OpenApiService.prototype.getFormControlForProperty = function (property, schema) {
1261
- if (Array.isArray(property.enum)) {
1262
- return createFormSelect(property.id, this.getFormSelectData(property, schema));
1263
- }
1264
- switch (property.type) {
1265
- case "string":
1266
- case "number":
1267
- case "boolean":
1268
- case "textarea":
1269
- return createFormInput(property.id, this.getFormInputData(property, schema));
1270
- case "list":
1271
- return createFormSelect(property.id, this.getFormSelectData(property, schema));
1272
- case "file":
1273
- return createFormFile(property.id, this.getFormFileData(property, schema));
1274
- }
1275
- return null;
1276
- };
1277
- OpenApiService.prototype.getBaseFormData = function (property, schema) {
1278
- return {
1279
- readonly: property.readonly ? FormUtilities.readonly : null,
1280
- shouldSerialize: FormUtilities.checkReadonly,
1281
- validators: this.getValidators(property, schema)
1282
- };
1283
- };
1284
- OpenApiService.prototype.getFormInputData = function (property, schema) {
1285
- var type = ngxUtils.StringUtils.has(property.id, "password", "Password") ? "password" : property.type;
1286
- switch (property.type) {
1287
- case "boolean":
1288
- type = "checkbox";
1289
- break;
1290
- case "textarea":
1291
- type = "textarea";
1292
- break;
1293
- }
1294
- return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { type: type });
1295
- };
1296
- OpenApiService.prototype.getFormSelectData = function (property, schema) {
1297
- var _this = this;
1298
- var options = Array.isArray(property.enum)
1299
- ? function () {
1300
- return Promise.resolve(property.enum.map(function (id) { return ({ id: id, label: property.id + "." + id }); }));
1301
- }
1302
- : function () {
1303
- _this.api.cache[property.endpoint] = _this.api.cache[property.endpoint] || _this.api.list(property.endpoint, _this.api.makeListParams(1, -1)).then(function (result) {
1304
- return result.items.map(function (i) {
1305
- return { id: i._id, label: i.name };
1306
- });
1307
- });
1308
- return _this.api.cache[property.endpoint];
1309
- };
1310
- return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { options: options });
1311
- };
1312
- OpenApiService.prototype.getFormFileData = function (property, schema) {
1313
- return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { multi: property.multi });
1314
- };
1315
- OpenApiService.prototype.getValidators = function (property, schema) {
1316
- var validators = [];
1317
- if (schema.required.indexOf(property.id) >= 0) {
1318
- validators.push(FormUtilities.validateRequired);
1319
- }
1320
- if (property.minLength) {
1321
- validators.push({
1322
- type: FormUtilities,
1323
- func: FormUtilities.validateMinLength,
1324
- params: [property.minLength]
1325
- });
1326
- }
1327
- if (property.maxLength) {
1328
- validators.push({
1329
- type: FormUtilities,
1330
- func: FormUtilities.validateMaxLength,
1331
- params: [property.maxLength]
1332
- });
1333
- }
1334
- switch (property.format) {
1335
- case "email":
1336
- validators.push(FormUtilities.validateEmail);
1337
- break;
1338
- }
1339
- return validators;
1340
- };
1341
- return OpenApiService;
1342
- }());
1343
- OpenApiService.decorators = [
1344
- { type: core.Injectable }
1345
- ];
1346
- OpenApiService.ctorParameters = function () { return [
1347
- { type: ngxUtils.ApiService }
1219
+ var OpenApiService = /** @class */ (function () {
1220
+ function OpenApiService(api) {
1221
+ var _this = this;
1222
+ this.api = api;
1223
+ var baseUrl = this.api.url("").replace("api/", "api-docs");
1224
+ this.schemas = {};
1225
+ this.schemasPromise = new Promise((function (resolve) {
1226
+ _this.api.client.get(baseUrl).subscribe(function (res) {
1227
+ _this.schemas = res.definitions || {};
1228
+ resolve(_this.schemas);
1229
+ }, function () {
1230
+ resolve({});
1231
+ });
1232
+ }));
1233
+ }
1234
+ OpenApiService.prototype.getFormInputsForSchema = function (name) {
1235
+ var _this = this;
1236
+ this.api.cache = {};
1237
+ return this.schemasPromise.then(function (schemas) {
1238
+ var schema = schemas[name];
1239
+ var inputs = _this.getFormInputsForSchemaDef(schema);
1240
+ return inputs;
1241
+ });
1242
+ };
1243
+ OpenApiService.prototype.getFormInputsForSchemaDef = function (schema) {
1244
+ var _this = this;
1245
+ var inputs = {};
1246
+ if (!schema)
1247
+ return inputs;
1248
+ inputs.schema = schema;
1249
+ inputs.serializers = {};
1250
+ inputs.controls = Object.keys(schema.properties || {}).map(function (p) {
1251
+ var property = schema.properties[p];
1252
+ property.id = p;
1253
+ inputs.serializers[p] = function (id, parent) {
1254
+ return Promise.resolve(parent.model[id]);
1255
+ };
1256
+ return _this.getFormControlForProperty(property, schema);
1257
+ }).filter(function (t) { return null !== t; });
1258
+ return inputs;
1259
+ };
1260
+ OpenApiService.prototype.getFormControlForProperty = function (property, schema) {
1261
+ if (Array.isArray(property.enum)) {
1262
+ return createFormSelect(property.id, this.getFormSelectData(property, schema));
1263
+ }
1264
+ switch (property.type) {
1265
+ case "string":
1266
+ case "number":
1267
+ case "boolean":
1268
+ case "textarea":
1269
+ return createFormInput(property.id, this.getFormInputData(property, schema));
1270
+ case "list":
1271
+ return createFormSelect(property.id, this.getFormSelectData(property, schema));
1272
+ case "file":
1273
+ return createFormFile(property.id, this.getFormFileData(property, schema));
1274
+ }
1275
+ return null;
1276
+ };
1277
+ OpenApiService.prototype.getBaseFormData = function (property, schema) {
1278
+ return {
1279
+ readonly: property.readonly ? FormUtilities.readonly : null,
1280
+ shouldSerialize: FormUtilities.checkReadonly,
1281
+ validators: this.getValidators(property, schema)
1282
+ };
1283
+ };
1284
+ OpenApiService.prototype.getFormInputData = function (property, schema) {
1285
+ var type = ngxUtils.StringUtils.has(property.id, "password", "Password") ? "password" : property.type;
1286
+ switch (property.type) {
1287
+ case "boolean":
1288
+ type = "checkbox";
1289
+ break;
1290
+ case "textarea":
1291
+ type = "textarea";
1292
+ break;
1293
+ }
1294
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { type: type });
1295
+ };
1296
+ OpenApiService.prototype.getFormSelectData = function (property, schema) {
1297
+ var _this = this;
1298
+ var options = Array.isArray(property.enum)
1299
+ ? function () {
1300
+ return Promise.resolve(property.enum.map(function (id) { return ({ id: id, label: property.id + "." + id }); }));
1301
+ }
1302
+ : function () {
1303
+ _this.api.cache[property.endpoint] = _this.api.cache[property.endpoint] || _this.api.list(property.endpoint, _this.api.makeListParams(1, -1)).then(function (result) {
1304
+ return result.items.map(function (i) {
1305
+ return { id: i._id, label: i.name };
1306
+ });
1307
+ });
1308
+ return _this.api.cache[property.endpoint];
1309
+ };
1310
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { options: options });
1311
+ };
1312
+ OpenApiService.prototype.getFormFileData = function (property, schema) {
1313
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { multi: property.multi });
1314
+ };
1315
+ OpenApiService.prototype.getValidators = function (property, schema) {
1316
+ var validators = [];
1317
+ if (schema.required.indexOf(property.id) >= 0) {
1318
+ validators.push(FormUtilities.validateRequired);
1319
+ }
1320
+ if (property.minLength) {
1321
+ validators.push({
1322
+ type: FormUtilities,
1323
+ func: FormUtilities.validateMinLength,
1324
+ params: [property.minLength]
1325
+ });
1326
+ }
1327
+ if (property.maxLength) {
1328
+ validators.push({
1329
+ type: FormUtilities,
1330
+ func: FormUtilities.validateMaxLength,
1331
+ params: [property.maxLength]
1332
+ });
1333
+ }
1334
+ switch (property.format) {
1335
+ case "email":
1336
+ validators.push(FormUtilities.validateEmail);
1337
+ break;
1338
+ }
1339
+ return validators;
1340
+ };
1341
+ return OpenApiService;
1342
+ }());
1343
+ OpenApiService.decorators = [
1344
+ { type: core.Injectable }
1345
+ ];
1346
+ OpenApiService.ctorParameters = function () { return [
1347
+ { type: ngxUtils.ApiService }
1348
1348
  ]; };
1349
1349
 
1350
- var AsyncSubmitDirective = /** @class */ (function () {
1351
- function AsyncSubmitDirective(toaster, cdr, elem, renderer) {
1352
- this.toaster = toaster;
1353
- this.cdr = cdr;
1354
- this.onSuccess = new core.EventEmitter();
1355
- this.onError = new core.EventEmitter();
1356
- if (elem.nativeElement.tagName !== "BUTTON")
1357
- return;
1358
- renderer.setAttribute(elem.nativeElement, "type", "button");
1359
- }
1360
- Object.defineProperty(AsyncSubmitDirective.prototype, "isDisabled", {
1361
- get: function () {
1362
- return this.disabled;
1363
- },
1364
- enumerable: false,
1365
- configurable: true
1366
- });
1367
- Object.defineProperty(AsyncSubmitDirective.prototype, "isLoading", {
1368
- get: function () {
1369
- return this.loading;
1370
- },
1371
- enumerable: false,
1372
- configurable: true
1373
- });
1374
- AsyncSubmitDirective.prototype.ngOnInit = function () {
1375
- var _this = this;
1376
- if (!this.form)
1377
- return;
1378
- this.disabled = this.form.status !== "VALID";
1379
- this.cdr.detectChanges();
1380
- this.onStatusChange = this.form.onStatusChange.subscribe(function (form) {
1381
- _this.disabled = form.status !== "VALID";
1382
- _this.cdr.detectChanges();
1383
- if (!_this.callback || form.status == "PENDING")
1384
- return;
1385
- if (!_this.disabled) {
1386
- _this.callback();
1387
- }
1388
- _this.callback = null;
1389
- });
1390
- this.onSubmit = this.form.onSubmit.subscribe(function () { return _this.callMethod(); });
1391
- };
1392
- AsyncSubmitDirective.prototype.ngOnDestroy = function () {
1393
- if (this.onStatusChange)
1394
- this.onStatusChange.unsubscribe();
1395
- if (this.onSubmit)
1396
- this.onSubmit.unsubscribe();
1397
- };
1398
- AsyncSubmitDirective.prototype.click = function () {
1399
- var _this = this;
1400
- this.callback = function () { return _this.callMethod(); };
1401
- if (this.form.status !== "VALID" && this.form.status !== "INVALID")
1402
- return;
1403
- this.callback();
1404
- this.callback = null;
1405
- };
1406
- AsyncSubmitDirective.prototype.callMethod = function () {
1407
- var _this = this;
1408
- if (this.loading)
1409
- return;
1410
- this.loading = true;
1411
- this.method(this.form).then(function (result) {
1412
- _this.loading = false;
1413
- if (result) {
1414
- _this.onSuccess.emit(result);
1415
- _this.toaster.success(result.message, result.context);
1416
- }
1417
- }, function (reason) {
1418
- if (!reason || !reason.message)
1419
- throw new Error("Reason must implement IAsyncMessage interface");
1420
- _this.loading = false;
1421
- _this.onError.emit(reason);
1422
- _this.toaster.error(reason.message, reason.context);
1423
- });
1424
- };
1425
- return AsyncSubmitDirective;
1426
- }());
1427
- AsyncSubmitDirective.decorators = [
1428
- { type: core.Directive, args: [{
1429
- selector: "[async-submit]",
1430
- exportAs: "async-submit"
1431
- },] }
1432
- ];
1433
- AsyncSubmitDirective.ctorParameters = function () { return [
1434
- { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] },
1435
- { type: core.ChangeDetectorRef },
1436
- { type: core.ElementRef },
1437
- { type: core.Renderer2 }
1438
- ]; };
1439
- AsyncSubmitDirective.propDecorators = {
1440
- method: [{ type: core.Input, args: ["async-submit",] }],
1441
- form: [{ type: core.Input }],
1442
- onSuccess: [{ type: core.Output }],
1443
- onError: [{ type: core.Output }],
1444
- isDisabled: [{ type: core.HostBinding, args: ["class.disabled",] }],
1445
- isLoading: [{ type: core.HostBinding, args: ["class.loading",] }],
1446
- click: [{ type: core.HostListener, args: ["click",] }]
1350
+ var AsyncSubmitDirective = /** @class */ (function () {
1351
+ function AsyncSubmitDirective(toaster, cdr, elem, renderer) {
1352
+ this.toaster = toaster;
1353
+ this.cdr = cdr;
1354
+ this.onSuccess = new core.EventEmitter();
1355
+ this.onError = new core.EventEmitter();
1356
+ if (elem.nativeElement.tagName !== "BUTTON")
1357
+ return;
1358
+ renderer.setAttribute(elem.nativeElement, "type", "button");
1359
+ }
1360
+ Object.defineProperty(AsyncSubmitDirective.prototype, "isDisabled", {
1361
+ get: function () {
1362
+ return this.disabled;
1363
+ },
1364
+ enumerable: false,
1365
+ configurable: true
1366
+ });
1367
+ Object.defineProperty(AsyncSubmitDirective.prototype, "isLoading", {
1368
+ get: function () {
1369
+ return this.loading;
1370
+ },
1371
+ enumerable: false,
1372
+ configurable: true
1373
+ });
1374
+ AsyncSubmitDirective.prototype.ngOnInit = function () {
1375
+ var _this = this;
1376
+ if (!this.form)
1377
+ return;
1378
+ this.disabled = this.form.status !== "VALID";
1379
+ this.cdr.detectChanges();
1380
+ this.onStatusChange = this.form.onStatusChange.subscribe(function (form) {
1381
+ _this.disabled = form.status !== "VALID";
1382
+ _this.cdr.detectChanges();
1383
+ if (!_this.callback || form.status == "PENDING")
1384
+ return;
1385
+ if (!_this.disabled) {
1386
+ _this.callback();
1387
+ }
1388
+ _this.callback = null;
1389
+ });
1390
+ this.onSubmit = this.form.onSubmit.subscribe(function () { return _this.callMethod(); });
1391
+ };
1392
+ AsyncSubmitDirective.prototype.ngOnDestroy = function () {
1393
+ if (this.onStatusChange)
1394
+ this.onStatusChange.unsubscribe();
1395
+ if (this.onSubmit)
1396
+ this.onSubmit.unsubscribe();
1397
+ };
1398
+ AsyncSubmitDirective.prototype.click = function () {
1399
+ var _this = this;
1400
+ this.callback = function () { return _this.callMethod(); };
1401
+ if (this.form.status !== "VALID" && this.form.status !== "INVALID")
1402
+ return;
1403
+ this.callback();
1404
+ this.callback = null;
1405
+ };
1406
+ AsyncSubmitDirective.prototype.callMethod = function () {
1407
+ var _this = this;
1408
+ if (this.loading)
1409
+ return;
1410
+ this.loading = true;
1411
+ this.method(this.form).then(function (result) {
1412
+ _this.loading = false;
1413
+ if (result) {
1414
+ _this.onSuccess.emit(result);
1415
+ _this.toaster.success(result.message, result.context);
1416
+ }
1417
+ }, function (reason) {
1418
+ if (!reason || !reason.message)
1419
+ throw new Error("Reason must implement IAsyncMessage interface");
1420
+ _this.loading = false;
1421
+ _this.onError.emit(reason);
1422
+ _this.toaster.error(reason.message, reason.context);
1423
+ });
1424
+ };
1425
+ return AsyncSubmitDirective;
1426
+ }());
1427
+ AsyncSubmitDirective.decorators = [
1428
+ { type: core.Directive, args: [{
1429
+ selector: "[async-submit]",
1430
+ exportAs: "async-submit"
1431
+ },] }
1432
+ ];
1433
+ AsyncSubmitDirective.ctorParameters = function () { return [
1434
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] },
1435
+ { type: core.ChangeDetectorRef },
1436
+ { type: core.ElementRef },
1437
+ { type: core.Renderer2 }
1438
+ ]; };
1439
+ AsyncSubmitDirective.propDecorators = {
1440
+ method: [{ type: core.Input, args: ["async-submit",] }],
1441
+ form: [{ type: core.Input }],
1442
+ onSuccess: [{ type: core.Output }],
1443
+ onError: [{ type: core.Output }],
1444
+ isDisabled: [{ type: core.HostBinding, args: ["class.disabled",] }],
1445
+ isLoading: [{ type: core.HostBinding, args: ["class.loading",] }],
1446
+ click: [{ type: core.HostListener, args: ["click",] }]
1447
1447
  };
1448
1448
 
1449
- var DynamicFormControlDirective = /** @class */ (function () {
1450
- function DynamicFormControlDirective(vcr, forms) {
1451
- this.vcr = vcr;
1452
- this.forms = forms;
1453
- }
1454
- Object.defineProperty(DynamicFormControlDirective.prototype, "component", {
1455
- get: function () {
1456
- return this.comp;
1457
- },
1458
- enumerable: false,
1459
- configurable: true
1460
- });
1461
- DynamicFormControlDirective.prototype.ngOnChanges = function (changes) {
1462
- if (changes.control) {
1463
- this.comp = this.forms.createComponent(this.vcr, this.control.provider);
1464
- }
1465
- if (!this.comp)
1466
- return;
1467
- this.comp.control = this.control;
1468
- };
1469
- return DynamicFormControlDirective;
1470
- }());
1471
- DynamicFormControlDirective.decorators = [
1472
- { type: core.Directive, args: [{
1473
- selector: "[form-control]",
1474
- },] }
1475
- ];
1476
- DynamicFormControlDirective.ctorParameters = function () { return [
1477
- { type: core.ViewContainerRef },
1478
- { type: DynamicFormService }
1479
- ]; };
1480
- DynamicFormControlDirective.propDecorators = {
1481
- control: [{ type: core.Input, args: ["form-control",] }]
1449
+ var DynamicFormControlDirective = /** @class */ (function () {
1450
+ function DynamicFormControlDirective(vcr, forms) {
1451
+ this.vcr = vcr;
1452
+ this.forms = forms;
1453
+ }
1454
+ Object.defineProperty(DynamicFormControlDirective.prototype, "component", {
1455
+ get: function () {
1456
+ return this.comp;
1457
+ },
1458
+ enumerable: false,
1459
+ configurable: true
1460
+ });
1461
+ DynamicFormControlDirective.prototype.ngOnChanges = function (changes) {
1462
+ if (changes.control) {
1463
+ this.comp = this.forms.createComponent(this.vcr, this.control.provider);
1464
+ }
1465
+ if (!this.comp)
1466
+ return;
1467
+ this.comp.control = this.control;
1468
+ };
1469
+ return DynamicFormControlDirective;
1470
+ }());
1471
+ DynamicFormControlDirective.decorators = [
1472
+ { type: core.Directive, args: [{
1473
+ selector: "[form-control]",
1474
+ },] }
1475
+ ];
1476
+ DynamicFormControlDirective.ctorParameters = function () { return [
1477
+ { type: core.ViewContainerRef },
1478
+ { type: DynamicFormService }
1479
+ ]; };
1480
+ DynamicFormControlDirective.propDecorators = {
1481
+ control: [{ type: core.Input, args: ["form-control",] }]
1482
1482
  };
1483
1483
 
1484
- var DynamicFormTemplateDirective = /** @class */ (function () {
1485
- function DynamicFormTemplateDirective(template) {
1486
- this.template = template;
1487
- }
1488
- return DynamicFormTemplateDirective;
1489
- }());
1490
- DynamicFormTemplateDirective.decorators = [
1491
- { type: core.Directive, args: [{
1492
- selector: "ng-template[control],\n ng-template[label],\n ng-template[input],\n ng-template[prefix],\n ng-template[suffix],\n ng-template[setPrefix],\n ng-template[setSuffix],\n ng-template[formPrefix],\n ng-template[formSuffix],\n ng-template[innerFormPrefix],\n ng-template[innerFormSuffix]"
1493
- },] }
1494
- ];
1495
- DynamicFormTemplateDirective.ctorParameters = function () { return [
1496
- { type: core.TemplateRef }
1497
- ]; };
1498
- DynamicFormTemplateDirective.propDecorators = {
1499
- control: [{ type: core.Input }],
1500
- label: [{ type: core.Input }],
1501
- input: [{ type: core.Input }],
1502
- prefix: [{ type: core.Input }],
1503
- suffix: [{ type: core.Input }],
1504
- setPrefix: [{ type: core.Input }],
1505
- setSuffix: [{ type: core.Input }],
1506
- formPrefix: [{ type: core.Input }],
1507
- formSuffix: [{ type: core.Input }],
1508
- innerFormPrefix: [{ type: core.Input }],
1509
- innerFormSuffix: [{ type: core.Input }]
1484
+ var DynamicFormTemplateDirective = /** @class */ (function () {
1485
+ function DynamicFormTemplateDirective(template) {
1486
+ this.template = template;
1487
+ }
1488
+ return DynamicFormTemplateDirective;
1489
+ }());
1490
+ DynamicFormTemplateDirective.decorators = [
1491
+ { type: core.Directive, args: [{
1492
+ selector: "ng-template[control],\n ng-template[label],\n ng-template[input],\n ng-template[prefix],\n ng-template[suffix],\n ng-template[setPrefix],\n ng-template[setSuffix],\n ng-template[formPrefix],\n ng-template[formSuffix],\n ng-template[innerFormPrefix],\n ng-template[innerFormSuffix]"
1493
+ },] }
1494
+ ];
1495
+ DynamicFormTemplateDirective.ctorParameters = function () { return [
1496
+ { type: core.TemplateRef }
1497
+ ]; };
1498
+ DynamicFormTemplateDirective.propDecorators = {
1499
+ control: [{ type: core.Input }],
1500
+ label: [{ type: core.Input }],
1501
+ input: [{ type: core.Input }],
1502
+ prefix: [{ type: core.Input }],
1503
+ suffix: [{ type: core.Input }],
1504
+ setPrefix: [{ type: core.Input }],
1505
+ setSuffix: [{ type: core.Input }],
1506
+ formPrefix: [{ type: core.Input }],
1507
+ formSuffix: [{ type: core.Input }],
1508
+ innerFormPrefix: [{ type: core.Input }],
1509
+ innerFormSuffix: [{ type: core.Input }]
1510
1510
  };
1511
1511
 
1512
- var DynamicFormBaseComponent = /** @class */ (function () {
1513
- function DynamicFormBaseComponent(cdr, formService) {
1514
- this.formService = formService;
1515
- this.name = "";
1516
- this.controlTemplates = {};
1517
- this.labelTemplates = {};
1518
- this.inputTemplates = {};
1519
- this.prefixTemplates = {};
1520
- this.suffixTemplates = {};
1521
- this.onChange = new core.EventEmitter();
1522
- this.onStatusChange = new core.EventEmitter();
1523
- this.onInit = new core.EventEmitter();
1524
- this.onSubmit = new core.EventEmitter();
1525
- this.injector = formService.injector;
1526
- this.cdr = cdr;
1527
- }
1528
- Object.defineProperty(DynamicFormBaseComponent.prototype, "root", {
1529
- get: function () {
1530
- var form = this;
1531
- while (ngxUtils.ObjectUtils.isDefined(form.parent)) {
1532
- form = form.parent;
1533
- }
1534
- return form;
1535
- },
1536
- enumerable: false,
1537
- configurable: true
1538
- });
1539
- DynamicFormBaseComponent.prototype.findProvider = function (control) {
1540
- return this.formService.findProvider(control);
1541
- };
1542
- // --- Lifecycle hooks
1543
- DynamicFormBaseComponent.prototype.ngAfterContentInit = function () {
1544
- this.wrapperTemplate = this.wrapperTemplate || this.cWrapperTemplate;
1545
- this.fieldSetTemplate = this.fieldSetTemplate || this.cFieldSetTemplate;
1546
- this.controlTemplate = this.controlTemplate || this.cControlTemplate;
1547
- this.controlTemplates = this.filterTemplates(this.controlTemplates, "control");
1548
- this.labelTemplates = this.filterTemplates(this.labelTemplates, "label");
1549
- this.inputTemplates = this.filterTemplates(this.inputTemplates, "input");
1550
- this.prefixTemplates = this.filterTemplates(this.prefixTemplates, "prefix");
1551
- this.suffixTemplates = this.filterTemplates(this.suffixTemplates, "suffix");
1552
- this.setPrefixTemplates = this.filterTemplates(this.setPrefixTemplates, "setPrefix");
1553
- this.setSuffixTemplates = this.filterTemplates(this.setSuffixTemplates, "setSuffix");
1554
- };
1555
- DynamicFormBaseComponent.prototype.filterTemplates = function (templates, type) {
1556
- if (ngxUtils.ObjectUtils.isObject(templates) && Object.keys(templates).length > 0)
1557
- return templates;
1558
- return this.templates.filter(function (t) { return !!t[type]; }).reduce(function (result, directive) {
1559
- result[directive[type]] = directive.template;
1560
- return result;
1561
- }, {});
1562
- };
1563
- return DynamicFormBaseComponent;
1564
- }());
1565
- DynamicFormBaseComponent.decorators = [
1566
- { type: core.Directive }
1567
- ];
1568
- DynamicFormBaseComponent.ctorParameters = function () { return [
1569
- { type: core.ChangeDetectorRef },
1570
- { type: DynamicFormService }
1571
- ]; };
1572
- DynamicFormBaseComponent.propDecorators = {
1573
- name: [{ type: core.Input }],
1574
- readonly: [{ type: core.Input }],
1575
- updateOn: [{ type: core.Input }],
1576
- classes: [{ type: core.Input }],
1577
- parent: [{ type: core.Input }],
1578
- wrapperTemplate: [{ type: core.Input }],
1579
- fieldSetTemplate: [{ type: core.Input }],
1580
- controlTemplate: [{ type: core.Input }],
1581
- controlTemplates: [{ type: core.Input }],
1582
- labelTemplates: [{ type: core.Input }],
1583
- inputTemplates: [{ type: core.Input }],
1584
- prefixTemplates: [{ type: core.Input }],
1585
- suffixTemplates: [{ type: core.Input }],
1586
- setPrefixTemplates: [{ type: core.Input }],
1587
- setSuffixTemplates: [{ type: core.Input }],
1588
- onChange: [{ type: core.Output }],
1589
- onStatusChange: [{ type: core.Output }],
1590
- onInit: [{ type: core.Output }],
1591
- onSubmit: [{ type: core.Output }],
1592
- prefixTemplate: [{ type: core.ContentChild, args: ["prefixTemplate",] }],
1593
- suffixTemplate: [{ type: core.ContentChild, args: ["suffixTemplate",] }],
1594
- templates: [{ type: core.ContentChildren, args: [DynamicFormTemplateDirective,] }],
1595
- cWrapperTemplate: [{ type: core.ContentChild, args: ["wrapperTemplate",] }],
1596
- cFieldSetTemplate: [{ type: core.ContentChild, args: ["fieldSetTemplate",] }],
1597
- cControlTemplate: [{ type: core.ContentChild, args: ["controlTemplate",] }]
1512
+ var DynamicFormBaseComponent = /** @class */ (function () {
1513
+ function DynamicFormBaseComponent(cdr, formService) {
1514
+ this.formService = formService;
1515
+ this.name = "";
1516
+ this.controlTemplates = {};
1517
+ this.labelTemplates = {};
1518
+ this.inputTemplates = {};
1519
+ this.prefixTemplates = {};
1520
+ this.suffixTemplates = {};
1521
+ this.onChange = new core.EventEmitter();
1522
+ this.onStatusChange = new core.EventEmitter();
1523
+ this.onInit = new core.EventEmitter();
1524
+ this.onSubmit = new core.EventEmitter();
1525
+ this.injector = formService.injector;
1526
+ this.cdr = cdr;
1527
+ }
1528
+ Object.defineProperty(DynamicFormBaseComponent.prototype, "root", {
1529
+ get: function () {
1530
+ var form = this;
1531
+ while (ngxUtils.ObjectUtils.isDefined(form.parent)) {
1532
+ form = form.parent;
1533
+ }
1534
+ return form;
1535
+ },
1536
+ enumerable: false,
1537
+ configurable: true
1538
+ });
1539
+ DynamicFormBaseComponent.prototype.findProvider = function (control) {
1540
+ return this.formService.findProvider(control);
1541
+ };
1542
+ // --- Lifecycle hooks
1543
+ DynamicFormBaseComponent.prototype.ngAfterContentInit = function () {
1544
+ this.wrapperTemplate = this.wrapperTemplate || this.cWrapperTemplate;
1545
+ this.fieldSetTemplate = this.fieldSetTemplate || this.cFieldSetTemplate;
1546
+ this.controlTemplate = this.controlTemplate || this.cControlTemplate;
1547
+ this.controlTemplates = this.filterTemplates(this.controlTemplates, "control");
1548
+ this.labelTemplates = this.filterTemplates(this.labelTemplates, "label");
1549
+ this.inputTemplates = this.filterTemplates(this.inputTemplates, "input");
1550
+ this.prefixTemplates = this.filterTemplates(this.prefixTemplates, "prefix");
1551
+ this.suffixTemplates = this.filterTemplates(this.suffixTemplates, "suffix");
1552
+ this.setPrefixTemplates = this.filterTemplates(this.setPrefixTemplates, "setPrefix");
1553
+ this.setSuffixTemplates = this.filterTemplates(this.setSuffixTemplates, "setSuffix");
1554
+ };
1555
+ DynamicFormBaseComponent.prototype.filterTemplates = function (templates, type) {
1556
+ if (ngxUtils.ObjectUtils.isObject(templates) && Object.keys(templates).length > 0)
1557
+ return templates;
1558
+ return this.templates.filter(function (t) { return !!t[type]; }).reduce(function (result, directive) {
1559
+ result[directive[type]] = directive.template;
1560
+ return result;
1561
+ }, {});
1562
+ };
1563
+ return DynamicFormBaseComponent;
1564
+ }());
1565
+ DynamicFormBaseComponent.decorators = [
1566
+ { type: core.Directive }
1567
+ ];
1568
+ DynamicFormBaseComponent.ctorParameters = function () { return [
1569
+ { type: core.ChangeDetectorRef },
1570
+ { type: DynamicFormService }
1571
+ ]; };
1572
+ DynamicFormBaseComponent.propDecorators = {
1573
+ name: [{ type: core.Input }],
1574
+ readonly: [{ type: core.Input }],
1575
+ updateOn: [{ type: core.Input }],
1576
+ classes: [{ type: core.Input }],
1577
+ parent: [{ type: core.Input }],
1578
+ wrapperTemplate: [{ type: core.Input }],
1579
+ fieldSetTemplate: [{ type: core.Input }],
1580
+ controlTemplate: [{ type: core.Input }],
1581
+ controlTemplates: [{ type: core.Input }],
1582
+ labelTemplates: [{ type: core.Input }],
1583
+ inputTemplates: [{ type: core.Input }],
1584
+ prefixTemplates: [{ type: core.Input }],
1585
+ suffixTemplates: [{ type: core.Input }],
1586
+ setPrefixTemplates: [{ type: core.Input }],
1587
+ setSuffixTemplates: [{ type: core.Input }],
1588
+ onChange: [{ type: core.Output }],
1589
+ onStatusChange: [{ type: core.Output }],
1590
+ onInit: [{ type: core.Output }],
1591
+ onSubmit: [{ type: core.Output }],
1592
+ prefixTemplate: [{ type: core.ContentChild, args: ["prefixTemplate",] }],
1593
+ suffixTemplate: [{ type: core.ContentChild, args: ["suffixTemplate",] }],
1594
+ templates: [{ type: core.ContentChildren, args: [DynamicFormTemplateDirective,] }],
1595
+ cWrapperTemplate: [{ type: core.ContentChild, args: ["wrapperTemplate",] }],
1596
+ cFieldSetTemplate: [{ type: core.ContentChild, args: ["fieldSetTemplate",] }],
1597
+ cControlTemplate: [{ type: core.ContentChild, args: ["controlTemplate",] }]
1598
1598
  };
1599
1599
 
1600
- var DynamicFormComponent = /** @class */ (function (_super) {
1601
- __extends(DynamicFormComponent, _super);
1602
- function DynamicFormComponent(cdr, forms) {
1603
- var _this = _super.call(this, cdr, forms) || this;
1604
- _this.group = new DynamicFormGroup(_this);
1605
- _this.defaultFieldSet = {
1606
- id: "",
1607
- title: "",
1608
- classes: ""
1609
- };
1610
- return _this;
1611
- }
1612
- Object.defineProperty(DynamicFormComponent.prototype, "status", {
1613
- get: function () {
1614
- return this.group.state;
1615
- },
1616
- enumerable: false,
1617
- configurable: true
1618
- });
1619
- Object.defineProperty(DynamicFormComponent.prototype, "formControls", {
1620
- get: function () {
1621
- return this.group.formControls;
1622
- },
1623
- enumerable: false,
1624
- configurable: true
1625
- });
1626
- // --- Lifecycle hooks
1627
- DynamicFormComponent.prototype.ngOnChanges = function (changes) {
1628
- if (!this.data)
1629
- return;
1630
- if (changes.data || changes.controls || changes.serializers || changes.formGroup) {
1631
- if (this.group.id)
1632
- return;
1633
- this.group.setup(this.data, this);
1634
- this.group.reloadControls();
1635
- }
1636
- };
1637
- // --- Custom ---
1638
- DynamicFormComponent.prototype.onFormSubmit = function () {
1639
- var _this = this;
1640
- var root = this.root;
1641
- root.validate().then(function () { return root.onSubmit.emit(_this); }, function () { });
1642
- };
1643
- // --- IDynamicForm ---
1644
- DynamicFormComponent.prototype.validate = function (showErrors) {
1645
- var _this = this;
1646
- if (showErrors === void 0) { showErrors = true; }
1647
- return new Promise(function (resolve, reject) {
1648
- _this.group.statusChanges.pipe(operators.first(function (status) { return status == "VALID" || status == "INVALID"; })).subscribe(function (status) {
1649
- if (showErrors)
1650
- _this.group.showErrors();
1651
- if (status == "VALID") {
1652
- resolve(null);
1653
- return;
1654
- }
1655
- reject(null);
1656
- });
1657
- _this.group.updateValueAndValidity();
1658
- });
1659
- };
1660
- DynamicFormComponent.prototype.serialize = function (validate) {
1661
- var _this = this;
1662
- return new Promise(function (resolve, reject) {
1663
- var serialize = function () {
1664
- _this.group.serialize().then(resolve);
1665
- };
1666
- if (validate) {
1667
- _this.validate().then(serialize, reject);
1668
- return;
1669
- }
1670
- serialize();
1671
- });
1672
- };
1673
- DynamicFormComponent.prototype.check = function () {
1674
- return this.group.check();
1675
- };
1676
- DynamicFormComponent.prototype.getControl = function (id) {
1677
- return this.group.getControl(id);
1678
- };
1679
- return DynamicFormComponent;
1680
- }(DynamicFormBaseComponent));
1681
- DynamicFormComponent.decorators = [
1682
- { type: core.Component, args: [{
1683
- moduleId: module.id,
1684
- selector: "dynamic-form, [dynamic-form]",
1685
- template: "<ng-template #defaultFieldSetTemplate let-id=\"id\" let-controls=\"controls\" let-fieldSet=\"fieldSet\">\n <div [ngClass]=\"['form-fields', 'form-fields-' + id, fieldSet.classes]\">\n <ng-container [ngxTemplateOutlet]=\"setPrefixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\n <div *ngIf=\"fieldSet.title\" [ngClass]=\"['form-title', fieldSet.titleClasses || '']\">\n {{ group.prefix + fieldSet.title | translate }}\n </div>\n <ng-template #subControls>\n <ng-container *ngFor=\"let control of controls\" [form-group]=\"control\" [visible]=\"control.visible\" [form]=\"this\">\n\n </ng-container>\n </ng-template>\n <div *ngIf=\"fieldSet.setClasses; else subControls\" [ngClass]=\"fieldSet.setClasses\">\n <div *ngIf=\"fieldSet.controlClasses; else subControls\" [ngClass]=\"fieldSet.controlClasses\">\n <ng-container [ngTemplateOutlet]=\"subControls\"></ng-container>\n </div>\n </div>\n <ng-container [ngxTemplateOutlet]=\"setSuffixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\n </div>\n</ng-template>\n\n<ng-template #fieldSetsTemplate>\n <ng-container *ngFor=\"let fs of formControls | groupBy:'data.fieldSet'\"\n [ngxTemplateOutlet]=\"fieldSetTemplate || defaultFieldSetTemplate\"\n [context]=\"{form: this, id: fs.group, controls: fs.items, fieldSet: group.formFields[fs.group] || defaultFieldSet}\">\n </ng-container>\n</ng-template>\n<ng-template #defaultWrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\n <form class=\"dynamic-form\" [ngClass]=\"form.classes || ''\" [formGroup]=\"group\" (submit)=\"onFormSubmit()\">\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\n <ng-content></ng-content>\n <div *ngIf=\"form.status == 'PENDING'\" class=\"dynamic-form-validator\">\n {{ group.prefix + 'message.pending' | translate }}\n </div>\n <button [ngStyle]=\"{display: 'none'}\">Submit</button>\n </form>\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\n</ng-template>\n<ng-template #loadingTemplate>\n <div *ngIf=\"status == 'LOADING'\" class=\"dynamic-form-loader\">\n {{ group.prefix + 'message.loading' | translate }}\n </div>\n</ng-template>\n<ng-container [ngTemplateOutlet]=\"wrapperTemplate || defaultWrapperTemplate\"\n [ngTemplateOutletContext]=\"{form: this, fieldSetsTemplate: fieldSetsTemplate}\"\n *ngIf=\"status !== 'LOADING'; else loadingTemplate\">\n</ng-container>\n",
1686
- providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormComponent }]
1687
- },] }
1688
- ];
1689
- DynamicFormComponent.ctorParameters = function () { return [
1690
- { type: core.ChangeDetectorRef },
1691
- { type: DynamicFormService }
1692
- ]; };
1693
- DynamicFormComponent.propDecorators = {
1694
- group: [{ type: core.Input }],
1695
- controls: [{ type: core.Input }],
1696
- serializers: [{ type: core.Input }],
1697
- fieldSets: [{ type: core.Input }],
1698
- data: [{ type: core.Input }]
1600
+ var DynamicFormComponent = /** @class */ (function (_super) {
1601
+ __extends(DynamicFormComponent, _super);
1602
+ function DynamicFormComponent(cdr, forms) {
1603
+ var _this = _super.call(this, cdr, forms) || this;
1604
+ _this.group = new DynamicFormGroup(_this);
1605
+ _this.defaultFieldSet = {
1606
+ id: "",
1607
+ title: "",
1608
+ classes: ""
1609
+ };
1610
+ return _this;
1611
+ }
1612
+ Object.defineProperty(DynamicFormComponent.prototype, "status", {
1613
+ get: function () {
1614
+ return this.group.state;
1615
+ },
1616
+ enumerable: false,
1617
+ configurable: true
1618
+ });
1619
+ Object.defineProperty(DynamicFormComponent.prototype, "formControls", {
1620
+ get: function () {
1621
+ return this.group.formControls;
1622
+ },
1623
+ enumerable: false,
1624
+ configurable: true
1625
+ });
1626
+ // --- Lifecycle hooks
1627
+ DynamicFormComponent.prototype.ngOnChanges = function (changes) {
1628
+ if (!this.data)
1629
+ return;
1630
+ if (changes.data || changes.controls || changes.serializers || changes.formGroup) {
1631
+ if (this.group.id)
1632
+ return;
1633
+ this.group.setup(this.data, this);
1634
+ this.group.reloadControls();
1635
+ }
1636
+ };
1637
+ // --- Custom ---
1638
+ DynamicFormComponent.prototype.onFormSubmit = function () {
1639
+ var _this = this;
1640
+ var root = this.root;
1641
+ root.validate().then(function () { return root.onSubmit.emit(_this); }, function () { });
1642
+ };
1643
+ // --- IDynamicForm ---
1644
+ DynamicFormComponent.prototype.validate = function (showErrors) {
1645
+ var _this = this;
1646
+ if (showErrors === void 0) { showErrors = true; }
1647
+ return new Promise(function (resolve, reject) {
1648
+ _this.group.statusChanges.pipe(operators.first(function (status) { return status == "VALID" || status == "INVALID"; })).subscribe(function (status) {
1649
+ if (showErrors)
1650
+ _this.group.showErrors();
1651
+ if (status == "VALID") {
1652
+ resolve(null);
1653
+ return;
1654
+ }
1655
+ reject(null);
1656
+ });
1657
+ _this.group.updateValueAndValidity();
1658
+ });
1659
+ };
1660
+ DynamicFormComponent.prototype.serialize = function (validate) {
1661
+ var _this = this;
1662
+ return new Promise(function (resolve, reject) {
1663
+ var serialize = function () {
1664
+ _this.group.serialize().then(resolve);
1665
+ };
1666
+ if (validate) {
1667
+ _this.validate().then(serialize, reject);
1668
+ return;
1669
+ }
1670
+ serialize();
1671
+ });
1672
+ };
1673
+ DynamicFormComponent.prototype.check = function () {
1674
+ return this.group.check();
1675
+ };
1676
+ DynamicFormComponent.prototype.getControl = function (id) {
1677
+ return this.group.getControl(id);
1678
+ };
1679
+ return DynamicFormComponent;
1680
+ }(DynamicFormBaseComponent));
1681
+ DynamicFormComponent.decorators = [
1682
+ { type: core.Component, args: [{
1683
+ moduleId: module.id,
1684
+ selector: "dynamic-form, [dynamic-form]",
1685
+ template: "<ng-template #defaultFieldSetTemplate let-id=\"id\" let-controls=\"controls\" let-fieldSet=\"fieldSet\">\r\n <div [ngClass]=\"['form-fields', 'form-fields-' + id, fieldSet.classes]\">\r\n <ng-container [ngxTemplateOutlet]=\"setPrefixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\r\n <div *ngIf=\"fieldSet.title\" [ngClass]=\"['form-title', fieldSet.titleClasses || '']\">\r\n {{ group.prefix + fieldSet.title | translate }}\r\n </div>\r\n <ng-template #subControls>\r\n <ng-container *ngFor=\"let control of controls\" [form-group]=\"control\" [visible]=\"control.visible\" [form]=\"this\">\r\n\r\n </ng-container>\r\n </ng-template>\r\n <div *ngIf=\"fieldSet.setClasses; else subControls\" [ngClass]=\"fieldSet.setClasses\">\r\n <div *ngIf=\"fieldSet.controlClasses; else subControls\" [ngClass]=\"fieldSet.controlClasses\">\r\n <ng-container [ngTemplateOutlet]=\"subControls\"></ng-container>\r\n </div>\r\n </div>\r\n <ng-container [ngxTemplateOutlet]=\"setSuffixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\r\n </div>\r\n</ng-template>\r\n\r\n<ng-template #fieldSetsTemplate>\r\n <ng-container *ngFor=\"let fs of formControls | groupBy:'data.fieldSet'\"\r\n [ngxTemplateOutlet]=\"fieldSetTemplate || defaultFieldSetTemplate\"\r\n [context]=\"{form: this, id: fs.group, controls: fs.items, fieldSet: group.formFields[fs.group] || defaultFieldSet}\">\r\n </ng-container>\r\n</ng-template>\r\n<ng-template #defaultWrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\r\n <form class=\"dynamic-form\" [ngClass]=\"form.classes || ''\" [formGroup]=\"group\" (submit)=\"onFormSubmit()\">\r\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\r\n <ng-content></ng-content>\r\n <div *ngIf=\"form.status == 'PENDING'\" class=\"dynamic-form-validator\">\r\n {{ group.prefix + 'message.pending' | translate }}\r\n </div>\r\n <button [ngStyle]=\"{display: 'none'}\">Submit</button>\r\n </form>\r\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\r\n</ng-template>\r\n<ng-template #loadingTemplate>\r\n <div *ngIf=\"status == 'LOADING'\" class=\"dynamic-form-loader\">\r\n {{ group.prefix + 'message.loading' | translate }}\r\n </div>\r\n</ng-template>\r\n<ng-container [ngTemplateOutlet]=\"wrapperTemplate || defaultWrapperTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this, fieldSetsTemplate: fieldSetsTemplate}\"\r\n *ngIf=\"status !== 'LOADING'; else loadingTemplate\">\r\n</ng-container>\r\n",
1686
+ providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormComponent }]
1687
+ },] }
1688
+ ];
1689
+ DynamicFormComponent.ctorParameters = function () { return [
1690
+ { type: core.ChangeDetectorRef },
1691
+ { type: DynamicFormService }
1692
+ ]; };
1693
+ DynamicFormComponent.propDecorators = {
1694
+ group: [{ type: core.Input }],
1695
+ controls: [{ type: core.Input }],
1696
+ serializers: [{ type: core.Input }],
1697
+ fieldSets: [{ type: core.Input }],
1698
+ data: [{ type: core.Input }]
1699
1699
  };
1700
1700
 
1701
- var statusPriority = ["LOADING", "PENDING", "DISABLED", "INVALID"];
1702
- var DynamicFormsComponent = /** @class */ (function (_super) {
1703
- __extends(DynamicFormsComponent, _super);
1704
- function DynamicFormsComponent(cdr, formService) {
1705
- var _this = _super.call(this, cdr, formService) || this;
1706
- _this.formPrefixTemplates = {};
1707
- _this.formSuffixTemplates = {};
1708
- _this.innerFormPrefixTemplates = {};
1709
- _this.innerFormSuffixTemplates = {};
1710
- return _this;
1711
- }
1712
- Object.defineProperty(DynamicFormsComponent.prototype, "status", {
1713
- get: function () {
1714
- var _loop_1 = function (i) {
1715
- var status = statusPriority[i];
1716
- if (this_1.checkForms(function (f) { return f.status == status; }))
1717
- return { value: status };
1718
- };
1719
- var this_1 = this;
1720
- for (var i = 0; i < statusPriority.length; i++) {
1721
- var state_1 = _loop_1(i);
1722
- if (typeof state_1 === "object")
1723
- return state_1.value;
1724
- }
1725
- return "VALID";
1726
- },
1727
- enumerable: false,
1728
- configurable: true
1729
- });
1730
- // --- Lifecycle hooks
1731
- DynamicFormsComponent.prototype.ngAfterContentInit = function () {
1732
- _super.prototype.ngAfterContentInit.call(this);
1733
- this.containerTemplate = this.containerTemplate || this.cContainerTemplate;
1734
- this.formPrefixTemplates = this.filterTemplates(this.formPrefixTemplates, "formPrefix");
1735
- this.formSuffixTemplates = this.filterTemplates(this.formSuffixTemplates, "formSuffix");
1736
- this.innerFormPrefixTemplates = this.filterTemplates(this.innerFormPrefixTemplates, "innerFormPrefix");
1737
- this.innerFormSuffixTemplates = this.filterTemplates(this.innerFormSuffixTemplates, "innerFormSuffix");
1738
- };
1739
- DynamicFormsComponent.prototype.ngOnChanges = function (changes) {
1740
- this.configs = this.createFormGroups(this.data);
1741
- };
1742
- // --- IDynamicFormBase ---
1743
- DynamicFormsComponent.prototype.validate = function (showErrors) {
1744
- if (showErrors === void 0) { showErrors = true; }
1745
- if (!this.forms)
1746
- return Promise.reject(null);
1747
- return Promise.all(this.forms.map(function (f) { return f.validate(showErrors); }));
1748
- };
1749
- DynamicFormsComponent.prototype.serialize = function (validate) {
1750
- var _this = this;
1751
- if (!this.forms)
1752
- return validate ? Promise.reject(null) : Promise.resolve({});
1753
- return new Promise(function (resolve, reject) {
1754
- var promises = _this.forms.map(function (f) { return f.serialize(validate); });
1755
- Promise.all(promises).then(function (results) {
1756
- var result = {};
1757
- results.forEach(function (data, ix) {
1758
- var config = _this.data[ix];
1759
- var path = null;
1760
- if (ngxUtils.ObjectUtils.isArray(config.path) && config.path.length > 0) {
1761
- path = config.path;
1762
- }
1763
- else if (ngxUtils.ObjectUtils.isString(config.path) && config.path.length > 0) {
1764
- path = config.path.split(".");
1765
- }
1766
- else if (ngxUtils.ObjectUtils.isNumber(config.path)) {
1767
- path = [config.path];
1768
- }
1769
- if (!path) {
1770
- result = ngxUtils.ObjectUtils.assign(result, data);
1771
- return;
1772
- }
1773
- result = ngxUtils.ObjectUtils.mapToPath(result, data, path.map(function (p) { return "" + p; }));
1774
- });
1775
- resolve(result);
1776
- }, reject);
1777
- });
1778
- };
1779
- DynamicFormsComponent.prototype.check = function () {
1780
- if (!this.forms)
1781
- return Promise.resolve(null);
1782
- return Promise.all(this.forms.map(function (t) { return t.check(); }));
1783
- };
1784
- DynamicFormsComponent.prototype.getControl = function (id) {
1785
- return this.getFromValue(function (f) { return f.getControl(id); });
1786
- };
1787
- DynamicFormsComponent.prototype.checkForms = function (check) {
1788
- this.cdr.detectChanges();
1789
- if (!this.forms)
1790
- return false;
1791
- return ngxUtils.ObjectUtils.isDefined(this.forms.find(check));
1792
- };
1793
- DynamicFormsComponent.prototype.getFromValue = function (check) {
1794
- if (!this.forms)
1795
- return null;
1796
- var value = null;
1797
- this.forms.find(function (f) {
1798
- value = check(f);
1799
- return ngxUtils.ObjectUtils.isDefined(value);
1800
- });
1801
- return value;
1802
- };
1803
- DynamicFormsComponent.prototype.createFormGroups = function (configs) {
1804
- var _this = this;
1805
- return (configs || []).map(function (c) {
1806
- if (c.multi)
1807
- return c;
1808
- var config = c;
1809
- var group = new DynamicFormGroup(_this, {
1810
- id: config.id || ngxUtils.UniqueUtils.uuid(),
1811
- type: "model",
1812
- data: config.controlData
1813
- });
1814
- config.group = group;
1815
- config.name = config.name || _this.name;
1816
- group.setup(config.data, config);
1817
- group.reloadControls();
1818
- return config;
1819
- });
1820
- };
1821
- return DynamicFormsComponent;
1822
- }(DynamicFormBaseComponent));
1823
- DynamicFormsComponent.decorators = [
1824
- { type: core.Component, args: [{
1825
- moduleId: module.id,
1826
- selector: "dynamic-forms, [dynamic-forms]",
1827
- template: "<ng-template #configTemplate let-formTemplate=\"formTemplate\" let-form=\"form\" let-config=\"config\" let-configTemplate>\n <div [ngClass]=\"config.classes || ''\">\n <ng-container [ngTemplateOutlet]=\"formPrefixTemplates[config.id]\"\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\n <ng-template #singleFormTemplate>\n <div dynamic-form\n [hidden]=\"!config.group?.visible\"\n [ngClass]=\"config.formClasses || ''\"\n [name]=\"config.name || form.name\"\n [readonly]=\"form.readonly\"\n [updateOn]=\"form.updateOn\"\n [classes]=\"config.innerFormClasses\"\n [parent]=\"form\"\n\n [wrapperTemplate]=\"form.wrapperTemplate\"\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\n [controlTemplates]=\"form.controlTemplates\"\n\n [controlTemplate]=\"form.controlTemplate\"\n [labelTemplates]=\"form.labelTemplates\"\n [inputTemplates]=\"form.inputTemplates\"\n [prefixTemplates]=\"form.prefixTemplates\"\n [suffixTemplates]=\"form.suffixTemplates\"\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\n\n [group]=\"config.group\"\n [fieldSets]=\"config.fieldSets\">\n <ng-template #prefixTemplate let-subForm=\"form\">\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\n </ng-template>\n <ng-template #suffixTemplate let-subForm=\"form\">\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\n </ng-template>\n </div>\n </ng-template>\n <div dynamic-forms\n [ngClass]=\"config.formClasses || ''\"\n [name]=\"config.name || name\"\n [readonly]=\"form.readonly\"\n [updateOn]=\"form.updateOn\"\n [classes]=\"config.innerFormClasses\"\n [parent]=\"form\"\n\n [wrapperTemplate]=\"form.wrapperTemplate\"\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\n [controlTemplates]=\"form.controlTemplates\"\n\n [controlTemplate]=\"form.controlTemplate\"\n [labelTemplates]=\"form.labelTemplates\"\n [inputTemplates]=\"form.inputTemplates\"\n [prefixTemplates]=\"form.prefixTemplates\"\n [suffixTemplates]=\"form.suffixTemplates\"\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\n\n [data]=\"config.data\"\n [containerTemplate]=\"form.containerTemplate\"\n [formPrefixTemplates]=\"form.formPrefixTemplates\"\n [formSuffixTemplates]=\"form.formSuffixTemplates\"\n [innerFormPrefixTemplates]=\"form.innerFormPrefixTemplates\"\n [innerFormSuffixTemplates]=\"form.innerFormSuffixTemplates\"\n\n *ngIf=\"config.multi; else singleFormTemplate\">\n <ng-template #prefixTemplate let-subForm=\"form\">\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\n </ng-template>\n <ng-template #suffixTemplate let-subForm=\"form\">\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\n </ng-template>\n </div>\n <ng-container [ngTemplateOutlet]=\"formSuffixTemplates[config.id]\"\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\n </div>\n</ng-template>\n<ng-template let-form=\"form\" let-configTemplate=\"configTemplate\" #defaultContainerTemplate>\n <div class=\"dynamic-forms\" [ngClass]=\"classes || ''\">\n <ng-container *ngFor=\"let config of form.configs\"\n [ngTemplateOutlet]=\"configTemplate\"\n [ngTemplateOutletContext]=\"{form: form, config: config}\"></ng-container>\n <ng-content></ng-content>\n </div>\n</ng-template>\n<ng-container [ngTemplateOutlet]=\"prefixTemplate\"\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\n<ng-container [ngTemplateOutlet]=\"containerTemplate || defaultContainerTemplate\"\n [ngTemplateOutletContext]=\"{form: this, configTemplate: configTemplate, defaultContainerTemplate: defaultContainerTemplate}\">\n</ng-container>\n<ng-container [ngTemplateOutlet]=\"suffixTemplate\"\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\n",
1828
- providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormsComponent }]
1829
- },] }
1830
- ];
1831
- DynamicFormsComponent.ctorParameters = function () { return [
1832
- { type: core.ChangeDetectorRef },
1833
- { type: DynamicFormService }
1834
- ]; };
1835
- DynamicFormsComponent.propDecorators = {
1836
- data: [{ type: core.Input }],
1837
- containerTemplate: [{ type: core.Input }],
1838
- formPrefixTemplates: [{ type: core.Input }],
1839
- formSuffixTemplates: [{ type: core.Input }],
1840
- innerFormPrefixTemplates: [{ type: core.Input }],
1841
- innerFormSuffixTemplates: [{ type: core.Input }],
1842
- cContainerTemplate: [{ type: core.ContentChild, args: ["containerTemplate",] }],
1843
- forms: [{ type: core.ViewChildren, args: [DynamicFormBaseComponent,] }]
1701
+ var statusPriority = ["LOADING", "PENDING", "DISABLED", "INVALID"];
1702
+ var DynamicFormsComponent = /** @class */ (function (_super) {
1703
+ __extends(DynamicFormsComponent, _super);
1704
+ function DynamicFormsComponent(cdr, formService) {
1705
+ var _this = _super.call(this, cdr, formService) || this;
1706
+ _this.formPrefixTemplates = {};
1707
+ _this.formSuffixTemplates = {};
1708
+ _this.innerFormPrefixTemplates = {};
1709
+ _this.innerFormSuffixTemplates = {};
1710
+ return _this;
1711
+ }
1712
+ Object.defineProperty(DynamicFormsComponent.prototype, "status", {
1713
+ get: function () {
1714
+ var _loop_1 = function (i) {
1715
+ var status = statusPriority[i];
1716
+ if (this_1.checkForms(function (f) { return f.status == status; }))
1717
+ return { value: status };
1718
+ };
1719
+ var this_1 = this;
1720
+ for (var i = 0; i < statusPriority.length; i++) {
1721
+ var state_1 = _loop_1(i);
1722
+ if (typeof state_1 === "object")
1723
+ return state_1.value;
1724
+ }
1725
+ return "VALID";
1726
+ },
1727
+ enumerable: false,
1728
+ configurable: true
1729
+ });
1730
+ // --- Lifecycle hooks
1731
+ DynamicFormsComponent.prototype.ngAfterContentInit = function () {
1732
+ _super.prototype.ngAfterContentInit.call(this);
1733
+ this.containerTemplate = this.containerTemplate || this.cContainerTemplate;
1734
+ this.formPrefixTemplates = this.filterTemplates(this.formPrefixTemplates, "formPrefix");
1735
+ this.formSuffixTemplates = this.filterTemplates(this.formSuffixTemplates, "formSuffix");
1736
+ this.innerFormPrefixTemplates = this.filterTemplates(this.innerFormPrefixTemplates, "innerFormPrefix");
1737
+ this.innerFormSuffixTemplates = this.filterTemplates(this.innerFormSuffixTemplates, "innerFormSuffix");
1738
+ };
1739
+ DynamicFormsComponent.prototype.ngOnChanges = function (changes) {
1740
+ this.configs = this.createFormGroups(this.data);
1741
+ };
1742
+ // --- IDynamicFormBase ---
1743
+ DynamicFormsComponent.prototype.validate = function (showErrors) {
1744
+ if (showErrors === void 0) { showErrors = true; }
1745
+ if (!this.forms)
1746
+ return Promise.reject(null);
1747
+ return Promise.all(this.forms.map(function (f) { return f.validate(showErrors); }));
1748
+ };
1749
+ DynamicFormsComponent.prototype.serialize = function (validate) {
1750
+ var _this = this;
1751
+ if (!this.forms)
1752
+ return validate ? Promise.reject(null) : Promise.resolve({});
1753
+ return new Promise(function (resolve, reject) {
1754
+ var promises = _this.forms.map(function (f) { return f.serialize(validate); });
1755
+ Promise.all(promises).then(function (results) {
1756
+ var result = {};
1757
+ results.forEach(function (data, ix) {
1758
+ var config = _this.data[ix];
1759
+ var path = null;
1760
+ if (ngxUtils.ObjectUtils.isArray(config.path) && config.path.length > 0) {
1761
+ path = config.path;
1762
+ }
1763
+ else if (ngxUtils.ObjectUtils.isString(config.path) && config.path.length > 0) {
1764
+ path = config.path.split(".");
1765
+ }
1766
+ else if (ngxUtils.ObjectUtils.isNumber(config.path)) {
1767
+ path = [config.path];
1768
+ }
1769
+ if (!path) {
1770
+ result = ngxUtils.ObjectUtils.assign(result, data);
1771
+ return;
1772
+ }
1773
+ result = ngxUtils.ObjectUtils.mapToPath(result, data, path.map(function (p) { return "" + p; }));
1774
+ });
1775
+ resolve(result);
1776
+ }, reject);
1777
+ });
1778
+ };
1779
+ DynamicFormsComponent.prototype.check = function () {
1780
+ if (!this.forms)
1781
+ return Promise.resolve(null);
1782
+ return Promise.all(this.forms.map(function (t) { return t.check(); }));
1783
+ };
1784
+ DynamicFormsComponent.prototype.getControl = function (id) {
1785
+ return this.getFromValue(function (f) { return f.getControl(id); });
1786
+ };
1787
+ DynamicFormsComponent.prototype.checkForms = function (check) {
1788
+ this.cdr.detectChanges();
1789
+ if (!this.forms)
1790
+ return false;
1791
+ return ngxUtils.ObjectUtils.isDefined(this.forms.find(check));
1792
+ };
1793
+ DynamicFormsComponent.prototype.getFromValue = function (check) {
1794
+ if (!this.forms)
1795
+ return null;
1796
+ var value = null;
1797
+ this.forms.find(function (f) {
1798
+ value = check(f);
1799
+ return ngxUtils.ObjectUtils.isDefined(value);
1800
+ });
1801
+ return value;
1802
+ };
1803
+ DynamicFormsComponent.prototype.createFormGroups = function (configs) {
1804
+ var _this = this;
1805
+ return (configs || []).map(function (c) {
1806
+ if (c.multi)
1807
+ return c;
1808
+ var config = c;
1809
+ var group = new DynamicFormGroup(_this, {
1810
+ id: config.id || ngxUtils.UniqueUtils.uuid(),
1811
+ type: "model",
1812
+ data: config.controlData
1813
+ });
1814
+ config.group = group;
1815
+ config.name = config.name || _this.name;
1816
+ group.setup(config.data, config);
1817
+ group.reloadControls();
1818
+ return config;
1819
+ });
1820
+ };
1821
+ return DynamicFormsComponent;
1822
+ }(DynamicFormBaseComponent));
1823
+ DynamicFormsComponent.decorators = [
1824
+ { type: core.Component, args: [{
1825
+ moduleId: module.id,
1826
+ selector: "dynamic-forms, [dynamic-forms]",
1827
+ template: "<ng-template #configTemplate let-formTemplate=\"formTemplate\" let-form=\"form\" let-config=\"config\" let-configTemplate>\r\n <div [ngClass]=\"config.classes || ''\">\r\n <ng-container [ngTemplateOutlet]=\"formPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\r\n <ng-template #singleFormTemplate>\r\n <div dynamic-form\r\n [hidden]=\"!config.group?.visible\"\r\n [ngClass]=\"config.formClasses || ''\"\r\n [name]=\"config.name || form.name\"\r\n [readonly]=\"form.readonly\"\r\n [updateOn]=\"form.updateOn\"\r\n [classes]=\"config.innerFormClasses\"\r\n [parent]=\"form\"\r\n\r\n [wrapperTemplate]=\"form.wrapperTemplate\"\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n [group]=\"config.group\"\r\n [fieldSets]=\"config.fieldSets\">\r\n <ng-template #prefixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n <ng-template #suffixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n </div>\r\n </ng-template>\r\n <div dynamic-forms\r\n [ngClass]=\"config.formClasses || ''\"\r\n [name]=\"config.name || name\"\r\n [readonly]=\"form.readonly\"\r\n [updateOn]=\"form.updateOn\"\r\n [classes]=\"config.innerFormClasses\"\r\n [parent]=\"form\"\r\n\r\n [wrapperTemplate]=\"form.wrapperTemplate\"\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n [data]=\"config.data\"\r\n [containerTemplate]=\"form.containerTemplate\"\r\n [formPrefixTemplates]=\"form.formPrefixTemplates\"\r\n [formSuffixTemplates]=\"form.formSuffixTemplates\"\r\n [innerFormPrefixTemplates]=\"form.innerFormPrefixTemplates\"\r\n [innerFormSuffixTemplates]=\"form.innerFormSuffixTemplates\"\r\n\r\n *ngIf=\"config.multi; else singleFormTemplate\">\r\n <ng-template #prefixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n <ng-template #suffixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n </div>\r\n <ng-container [ngTemplateOutlet]=\"formSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\r\n </div>\r\n</ng-template>\r\n<ng-template let-form=\"form\" let-configTemplate=\"configTemplate\" #defaultContainerTemplate>\r\n <div class=\"dynamic-forms\" [ngClass]=\"classes || ''\">\r\n <ng-container *ngFor=\"let config of form.configs\"\r\n [ngTemplateOutlet]=\"configTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, config: config}\"></ng-container>\r\n <ng-content></ng-content>\r\n </div>\r\n</ng-template>\r\n<ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\r\n<ng-container [ngTemplateOutlet]=\"containerTemplate || defaultContainerTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this, configTemplate: configTemplate, defaultContainerTemplate: defaultContainerTemplate}\">\r\n</ng-container>\r\n<ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\r\n",
1828
+ providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormsComponent }]
1829
+ },] }
1830
+ ];
1831
+ DynamicFormsComponent.ctorParameters = function () { return [
1832
+ { type: core.ChangeDetectorRef },
1833
+ { type: DynamicFormService }
1834
+ ]; };
1835
+ DynamicFormsComponent.propDecorators = {
1836
+ data: [{ type: core.Input }],
1837
+ containerTemplate: [{ type: core.Input }],
1838
+ formPrefixTemplates: [{ type: core.Input }],
1839
+ formSuffixTemplates: [{ type: core.Input }],
1840
+ innerFormPrefixTemplates: [{ type: core.Input }],
1841
+ innerFormSuffixTemplates: [{ type: core.Input }],
1842
+ cContainerTemplate: [{ type: core.ContentChild, args: ["containerTemplate",] }],
1843
+ forms: [{ type: core.ViewChildren, args: [DynamicFormBaseComponent,] }]
1844
1844
  };
1845
1845
 
1846
- var DynamicFormGroupComponent = /** @class */ (function () {
1847
- function DynamicFormGroupComponent() {
1848
- }
1849
- Object.defineProperty(DynamicFormGroupComponent.prototype, "classes", {
1850
- get: function () {
1851
- if (!this.control)
1852
- return "form-group";
1853
- return ["form-group", "form-group-" + this.control.id, this.control.data.classes, this.control.errors && this.control.touched ? "form-group-invalid" : ""].join(" ");
1854
- },
1855
- enumerable: false,
1856
- configurable: true
1857
- });
1858
- return DynamicFormGroupComponent;
1859
- }());
1860
- DynamicFormGroupComponent.decorators = [
1861
- { type: core.Component, args: [{
1862
- moduleId: module.id,
1863
- selector: "div[dynamic-form-group]",
1864
- template: "<ng-template #labelTemplate>\n <label [ngClass]=\"'control-label control-label-' + control.data.labelAlign\" [attr.for]=\"control.formId\">\n {{ control.label | translate: control.model }}\n </label>\n</ng-template>\n<ng-template #errorTemplate>\n <div class=\"error-message\" *ngIf=\"control.errors && control.touched\">\n <span class=\"help-block\" *ngFor=\"let error of control.errors | entries\">\n {{ error.key | translate: error.value }}\n </span>\n </div>\n</ng-template>\n<ng-template #inputTemplate let-control=\"control\">\n <ng-container [form-control]=\"control\"></ng-container>\n</ng-template>\n<ng-template #defaultControlTemplate\n let-context\n let-control=\"control\"\n let-data=\"control.data\"\n let-labelTemplate=\"labelTemplate\"\n let-inputTemplate=\"inputTemplate\"\n let-prefixTemplate=\"prefixTemplate\"\n let-suffixTemplate=\"suffixTemplate\"\n let-errorTemplate=\"errorTemplate\">\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\n [ngTemplateOutletContext]=\"context\"></ng-container>\n <ng-container *ngIf=\"control.label && data.labelAlign == 'left'\"\n [ngTemplateOutlet]=\"labelTemplate\"\n [ngTemplateOutletContext]=\"context\">\n </ng-container>\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"\n [ngTemplateOutletContext]=\"context\"></ng-container>\n <ng-container *ngIf=\"control.label && data.labelAlign == 'right'\"\n [ngTemplateOutlet]=\"labelTemplate\"\n [ngTemplateOutletContext]=\"context\">\n </ng-container>\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\n [ngTemplateOutletContext]=\"context\"></ng-container>\n <ng-container [ngTemplateOutlet]=\"errorTemplate\"\n [ngTemplateOutletContext]=\"context\"></ng-container>\n</ng-template>\n\n<ng-container [ngxTemplateOutlet]=\"form.controlTemplates[control.id] || form.controlTemplate || defaultControlTemplate\"\n [context]=\"{\n control: control,\n labelTemplate: form.labelTemplates[control.id] || labelTemplate,\n inputTemplate: form.inputTemplates[control.id] || inputTemplate,\n prefixTemplate: form.prefixTemplates[control.id],\n suffixTemplate: form.suffixTemplates[control.id],\n errorTemplate: errorTemplate\n }\">\n</ng-container>\n"
1865
- },] }
1866
- ];
1867
- DynamicFormGroupComponent.propDecorators = {
1868
- classes: [{ type: core.HostBinding, args: ["class",] }]
1846
+ var DynamicFormGroupComponent = /** @class */ (function () {
1847
+ function DynamicFormGroupComponent() {
1848
+ }
1849
+ Object.defineProperty(DynamicFormGroupComponent.prototype, "classes", {
1850
+ get: function () {
1851
+ if (!this.control)
1852
+ return "form-group";
1853
+ return ["form-group", "form-group-" + this.control.id, this.control.data.classes, this.control.errors && this.control.touched ? "form-group-invalid" : ""].join(" ");
1854
+ },
1855
+ enumerable: false,
1856
+ configurable: true
1857
+ });
1858
+ return DynamicFormGroupComponent;
1859
+ }());
1860
+ DynamicFormGroupComponent.decorators = [
1861
+ { type: core.Component, args: [{
1862
+ moduleId: module.id,
1863
+ selector: "div[dynamic-form-group]",
1864
+ template: "<ng-template #labelTemplate>\r\n <label [ngClass]=\"'control-label control-label-' + control.data.labelAlign\" [attr.for]=\"control.formId\">\r\n {{ control.label | translate: control.model }}\r\n </label>\r\n</ng-template>\r\n<ng-template #errorTemplate>\r\n <div class=\"error-message\" *ngIf=\"control.errors && control.touched\">\r\n <span class=\"help-block\" *ngFor=\"let error of control.errors | entries\">\r\n {{ error.key | translate: error.value }}\r\n </span>\r\n </div>\r\n</ng-template>\r\n<ng-template #inputTemplate let-control=\"control\">\r\n <ng-container [form-control]=\"control\"></ng-container>\r\n</ng-template>\r\n<ng-template #defaultControlTemplate\r\n let-context\r\n let-control=\"control\"\r\n let-data=\"control.data\"\r\n let-labelTemplate=\"labelTemplate\"\r\n let-inputTemplate=\"inputTemplate\"\r\n let-prefixTemplate=\"prefixTemplate\"\r\n let-suffixTemplate=\"suffixTemplate\"\r\n let-errorTemplate=\"errorTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container *ngIf=\"control.label && data.labelAlign == 'left'\"\r\n [ngTemplateOutlet]=\"labelTemplate\"\r\n [ngTemplateOutletContext]=\"context\">\r\n </ng-container>\r\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container *ngIf=\"control.label && data.labelAlign == 'right'\"\r\n [ngTemplateOutlet]=\"labelTemplate\"\r\n [ngTemplateOutletContext]=\"context\">\r\n </ng-container>\r\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container [ngTemplateOutlet]=\"errorTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n</ng-template>\r\n\r\n<ng-container [ngxTemplateOutlet]=\"form.controlTemplates[control.id] || form.controlTemplate || defaultControlTemplate\"\r\n [context]=\"{\r\n control: control,\r\n labelTemplate: form.labelTemplates[control.id] || labelTemplate,\r\n inputTemplate: form.inputTemplates[control.id] || inputTemplate,\r\n prefixTemplate: form.prefixTemplates[control.id],\r\n suffixTemplate: form.suffixTemplates[control.id],\r\n errorTemplate: errorTemplate\r\n }\">\r\n</ng-container>\r\n"
1865
+ },] }
1866
+ ];
1867
+ DynamicFormGroupComponent.propDecorators = {
1868
+ classes: [{ type: core.HostBinding, args: ["class",] }]
1869
1869
  };
1870
1870
 
1871
- var DynamicFormFileComponent = /** @class */ (function (_super) {
1872
- __extends(DynamicFormFileComponent, _super);
1873
- function DynamicFormFileComponent(api, toaster) {
1874
- var _this = _super.call(this) || this;
1875
- _this.api = api;
1876
- _this.toaster = toaster;
1877
- _this.fileImageCache = [];
1878
- return _this;
1879
- }
1880
- // Acceptor for provider
1881
- DynamicFormFileComponent.acceptor = function (control) {
1882
- return control.type == "file";
1883
- };
1884
- // Loader for provider
1885
- DynamicFormFileComponent.loader = function () {
1886
- return Promise.resolve();
1887
- };
1888
- DynamicFormFileComponent.prototype.onSelect = function (input) {
1889
- this.processFiles(input.files);
1890
- input.value = "";
1891
- };
1892
- DynamicFormFileComponent.prototype.processFiles = function (fileList) {
1893
- var files = [];
1894
- var accept = this.data.accept;
1895
- var types = ngxUtils.ObjectUtils.isString(accept) && accept.length > 0 ? accept.toLowerCase().split(",") : null;
1896
- if (fileList.length == 0)
1897
- return;
1898
- for (var i = 0; i < fileList.length; i++) {
1899
- var file = fileList.item(i);
1900
- var type = file.type.toLowerCase();
1901
- var ext = ngxUtils.FileUtils.getExtension(file);
1902
- if (types && !ngxUtils.ArrayUtils.has(types, type, ext))
1903
- continue;
1904
- files.push(file);
1905
- }
1906
- if (files.length == 0) {
1907
- this.toaster.error("message.error.wrong-files");
1908
- return;
1909
- }
1910
- this.upload(files);
1911
- };
1912
- DynamicFormFileComponent.prototype.upload = function (files) {
1913
- var _this = this;
1914
- var single = !this.data.multi;
1915
- if (single)
1916
- files.length = Math.min(files.length, 1);
1917
- var promises = [];
1918
- files.forEach(function (file, ix) {
1919
- if (_this.data.asDataUrl) {
1920
- promises.push(ngxUtils.FileUtils.readFileAsDataURL(file));
1921
- return;
1922
- }
1923
- if (_this.data.asFile) {
1924
- promises.push(Promise.resolve(file));
1925
- return;
1926
- }
1927
- promises.push(_this.api.upload(_this.data.uploadUrl, _this.data.createUploadData(file), console.log, _this.data.uploadOptions).then(function (asset) { return asset._id || asset; }, function () { return null; }));
1928
- });
1929
- Promise.all(promises).then(function (assets) {
1930
- if (single) {
1931
- _this.control.setValue(assets[0]);
1932
- return;
1933
- }
1934
- var current = _this.value || [];
1935
- _this.control.setValue(current.concat(assets.filter(function (t) { return !!t; })));
1936
- });
1937
- };
1938
- DynamicFormFileComponent.prototype.delete = function (index) {
1939
- if (this.data.multi) {
1940
- var current = Array.from(this.value || []);
1941
- current.splice(index, 1);
1942
- this.control.setValue(current);
1943
- return;
1944
- }
1945
- this.control.setValue(null);
1946
- };
1947
- DynamicFormFileComponent.prototype.getUrl = function (image) {
1948
- return "url('" + this.getImgUrl(image) + "')";
1949
- };
1950
- DynamicFormFileComponent.prototype.getImgUrl = function (image) {
1951
- if (ngxUtils.ObjectUtils.isBlob(image)) {
1952
- var cache = this.fileImageCache.find(function (t) { return t.file == image; });
1953
- if (!cache) {
1954
- cache = { file: image, url: URL.createObjectURL(image) };
1955
- this.fileImageCache.push(cache);
1956
- }
1957
- return cache.url;
1958
- }
1959
- var url = !image ? null : image.imageUrl || image;
1960
- if (!ngxUtils.ObjectUtils.isString(url))
1961
- return null;
1962
- if (url.startsWith("data:"))
1963
- return url;
1964
- if (!this.data.baseUrl) {
1965
- var subUrl = url.startsWith("/") ? url.substr(1) : url;
1966
- return this.api.url(subUrl);
1967
- }
1968
- return this.api.url("" + this.data.baseUrl + url);
1969
- };
1970
- return DynamicFormFileComponent;
1971
- }(FormControlComponent));
1972
- DynamicFormFileComponent.decorators = [
1973
- { type: core.Component, args: [{
1974
- selector: "dynamic-form-file",
1975
- template: "<div class=\"upload\">\n <input type=\"file\" (change)=\"onSelect($event.target)\" [attr.accept]=\"data.accept\" multiple=\"multiple\"/>\n <ul class=\"images\" *ngIf=\"!data.multi\">\n <li class=\"image\" *ngIf=\"value\" [ngStyle]=\"{backgroundImage: getUrl(value)}\">\n <a class=\"btn btn-delete\" (click)=\"delete()\"></a>\n </li>\n </ul>\n <ul class=\"images\" *ngIf=\"data.multi\">\n <li class=\"image\" *ngFor=\"let image of value; let i = index\" [ngStyle]=\"{backgroundImage: getUrl(image)}\">\n <a class=\"btn btn-delete\" (click)=\"delete(i)\"></a>\n </li>\n </ul>\n</div>\n",
1976
- styles: [".upload{display:inline-block}.upload ul{display:inline-flex;list-style:none;margin:10px 0 0;padding:0}.upload ul li{background:repeating-linear-gradient(45deg,grey,grey 10px,#d3d3d3 0,#d3d3d3 20px) 50%;background-size:cover;border:1px solid grey;height:100px;margin-right:5px;position:relative;width:100px}.upload .btn-delete{background:linear-gradient(180deg,#c8607a,#a64d5a);border-color:#a64d5a;color:#fff;height:20px;padding:0;position:absolute;right:5px;top:5px;width:20px}.upload .btn-delete:before{color:#fff;content:\"x\";display:block;position:absolute;right:6px;top:0}"]
1977
- },] }
1978
- ];
1979
- DynamicFormFileComponent.ctorParameters = function () { return [
1980
- { type: ngxUtils.ApiService },
1981
- { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] }
1871
+ var DynamicFormFileComponent = /** @class */ (function (_super) {
1872
+ __extends(DynamicFormFileComponent, _super);
1873
+ function DynamicFormFileComponent(api, toaster) {
1874
+ var _this = _super.call(this) || this;
1875
+ _this.api = api;
1876
+ _this.toaster = toaster;
1877
+ _this.fileImageCache = [];
1878
+ return _this;
1879
+ }
1880
+ // Acceptor for provider
1881
+ DynamicFormFileComponent.acceptor = function (control) {
1882
+ return control.type == "file";
1883
+ };
1884
+ // Loader for provider
1885
+ DynamicFormFileComponent.loader = function () {
1886
+ return Promise.resolve();
1887
+ };
1888
+ DynamicFormFileComponent.prototype.onSelect = function (input) {
1889
+ this.processFiles(input.files);
1890
+ input.value = "";
1891
+ };
1892
+ DynamicFormFileComponent.prototype.processFiles = function (fileList) {
1893
+ var files = [];
1894
+ var accept = this.data.accept;
1895
+ var types = ngxUtils.ObjectUtils.isString(accept) && accept.length > 0 ? accept.toLowerCase().split(",") : null;
1896
+ if (fileList.length == 0)
1897
+ return;
1898
+ for (var i = 0; i < fileList.length; i++) {
1899
+ var file = fileList.item(i);
1900
+ var type = file.type.toLowerCase();
1901
+ var ext = ngxUtils.FileUtils.getExtension(file);
1902
+ if (types && !ngxUtils.ArrayUtils.has(types, type, ext))
1903
+ continue;
1904
+ files.push(file);
1905
+ }
1906
+ if (files.length == 0) {
1907
+ this.toaster.error("message.error.wrong-files");
1908
+ return;
1909
+ }
1910
+ this.upload(files);
1911
+ };
1912
+ DynamicFormFileComponent.prototype.upload = function (files) {
1913
+ var _this = this;
1914
+ var single = !this.data.multi;
1915
+ if (single)
1916
+ files.length = Math.min(files.length, 1);
1917
+ var promises = [];
1918
+ files.forEach(function (file, ix) {
1919
+ if (_this.data.asDataUrl) {
1920
+ promises.push(ngxUtils.FileUtils.readFileAsDataURL(file));
1921
+ return;
1922
+ }
1923
+ if (_this.data.asFile) {
1924
+ promises.push(Promise.resolve(file));
1925
+ return;
1926
+ }
1927
+ promises.push(_this.api.upload(_this.data.uploadUrl, _this.data.createUploadData(file), console.log, _this.data.uploadOptions).then(function (asset) { return asset._id || asset; }, function () { return null; }));
1928
+ });
1929
+ Promise.all(promises).then(function (assets) {
1930
+ if (single) {
1931
+ _this.control.setValue(assets[0]);
1932
+ return;
1933
+ }
1934
+ var current = _this.value || [];
1935
+ _this.control.setValue(current.concat(assets.filter(function (t) { return !!t; })));
1936
+ });
1937
+ };
1938
+ DynamicFormFileComponent.prototype.delete = function (index) {
1939
+ if (this.data.multi) {
1940
+ var current = Array.from(this.value || []);
1941
+ current.splice(index, 1);
1942
+ this.control.setValue(current);
1943
+ return;
1944
+ }
1945
+ this.control.setValue(null);
1946
+ };
1947
+ DynamicFormFileComponent.prototype.getUrl = function (image) {
1948
+ return "url('" + this.getImgUrl(image) + "')";
1949
+ };
1950
+ DynamicFormFileComponent.prototype.getImgUrl = function (image) {
1951
+ if (ngxUtils.ObjectUtils.isBlob(image)) {
1952
+ var cache = this.fileImageCache.find(function (t) { return t.file == image; });
1953
+ if (!cache) {
1954
+ cache = { file: image, url: URL.createObjectURL(image) };
1955
+ this.fileImageCache.push(cache);
1956
+ }
1957
+ return cache.url;
1958
+ }
1959
+ var url = !image ? null : image.imageUrl || image;
1960
+ if (!ngxUtils.ObjectUtils.isString(url))
1961
+ return null;
1962
+ if (url.startsWith("data:"))
1963
+ return url;
1964
+ if (!this.data.baseUrl) {
1965
+ var subUrl = url.startsWith("/") ? url.substr(1) : url;
1966
+ return this.api.url(subUrl);
1967
+ }
1968
+ return this.api.url("" + this.data.baseUrl + url);
1969
+ };
1970
+ return DynamicFormFileComponent;
1971
+ }(FormControlComponent));
1972
+ DynamicFormFileComponent.decorators = [
1973
+ { type: core.Component, args: [{
1974
+ selector: "dynamic-form-file",
1975
+ template: "<div class=\"upload\">\r\n <input type=\"file\" (change)=\"onSelect($event.target)\" [attr.accept]=\"data.accept\" multiple=\"multiple\"/>\r\n <ul class=\"images\" *ngIf=\"!data.multi\">\r\n <li class=\"image\" *ngIf=\"value\" [ngStyle]=\"{backgroundImage: getUrl(value)}\">\r\n <a class=\"btn btn-delete\" (click)=\"delete()\"></a>\r\n </li>\r\n </ul>\r\n <ul class=\"images\" *ngIf=\"data.multi\">\r\n <li class=\"image\" *ngFor=\"let image of value; let i = index\" [ngStyle]=\"{backgroundImage: getUrl(image)}\">\r\n <a class=\"btn btn-delete\" (click)=\"delete(i)\"></a>\r\n </li>\r\n </ul>\r\n</div>\r\n",
1976
+ styles: [".upload{display:inline-block}.upload ul{display:inline-flex;list-style:none;margin:10px 0 0;padding:0}.upload ul li{background:repeating-linear-gradient(45deg,grey,grey 10px,#d3d3d3 0,#d3d3d3 20px) 50%;background-size:cover;border:1px solid grey;height:100px;margin-right:5px;position:relative;width:100px}.upload .btn-delete{background:linear-gradient(180deg,#c8607a,#a64d5a);border-color:#a64d5a;color:#fff;height:20px;padding:0;position:absolute;right:5px;top:5px;width:20px}.upload .btn-delete:before{color:#fff;content:\"x\";display:block;position:absolute;right:6px;top:0}"]
1977
+ },] }
1978
+ ];
1979
+ DynamicFormFileComponent.ctorParameters = function () { return [
1980
+ { type: ngxUtils.ApiService },
1981
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] }
1982
1982
  ]; };
1983
1983
 
1984
- var DynamicFormInputComponent = /** @class */ (function (_super) {
1985
- __extends(DynamicFormInputComponent, _super);
1986
- function DynamicFormInputComponent(language) {
1987
- var _this = _super.call(this) || this;
1988
- _this.language = language;
1989
- return _this;
1990
- }
1991
- // Acceptor for provider
1992
- DynamicFormInputComponent.acceptor = function (control) {
1993
- return control.type == "input";
1994
- };
1995
- // Loader for provider
1996
- DynamicFormInputComponent.loader = function () {
1997
- return Promise.resolve();
1998
- };
1999
- Object.defineProperty(DynamicFormInputComponent.prototype, "isChecked", {
2000
- get: function () {
2001
- return this.data.type == "checkbox" && this.value;
2002
- },
2003
- enumerable: false,
2004
- configurable: true
2005
- });
2006
- DynamicFormInputComponent.prototype.onDateChange = function (value) {
2007
- var date = new Date(value);
2008
- var dateValue = date.valueOf();
2009
- if (isNaN(dateValue) || dateValue < -30610224000000)
2010
- return;
2011
- this.control.setValue(date);
2012
- };
2013
- DynamicFormInputComponent.prototype.onMaskChange = function (value) {
2014
- value = ngxUtils.ObjectUtils.isFunction(this.data.unmask) ? this.data.unmask(value) : value;
2015
- this.control.setValue(value);
2016
- };
2017
- DynamicFormInputComponent.prototype.onTextChange = function (value) {
2018
- var _this = this;
2019
- if (!this.data.useLanguage) {
2020
- this.control.setValue(value);
2021
- return;
2022
- }
2023
- var translations = ngxUtils.ObjectUtils.isArray(this.value) ? Array.from(this.value) : [];
2024
- var translation = translations.find(function (t) { return t.lang == _this.language.editLanguage; });
2025
- if (translation) {
2026
- translation.translation = value;
2027
- }
2028
- else {
2029
- translations.push({
2030
- lang: this.language.editLanguage,
2031
- translation: value
2032
- });
2033
- }
2034
- this.control.setValue(translations);
2035
- };
2036
- DynamicFormInputComponent.prototype.onNumberBlur = function () {
2037
- var value = this.value;
2038
- if (ngxUtils.ObjectUtils.isNumber(this.data.max) && this.data.max < value) {
2039
- this.control.setValue(this.data.max);
2040
- }
2041
- else if (ngxUtils.ObjectUtils.isNumber(this.data.min) && this.data.min > value) {
2042
- this.control.setValue(this.data.min);
2043
- }
2044
- this.control.onBlur();
2045
- };
2046
- return DynamicFormInputComponent;
2047
- }(FormControlComponent));
2048
- DynamicFormInputComponent.decorators = [
2049
- { type: core.Component, args: [{
2050
- moduleId: module.id,
2051
- selector: "dynamic-form-input",
2052
- template: "<ng-container [ngSwitch]=\"data.type\">\n <ng-container *ngSwitchCase=\"'textarea'\">\n <textarea class=\"form-control\"\n rows=\"5\"\n [attr.autocomplete]=\"data.autocomplete\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"value\"\n (ngModelChange)=\"control.setValue($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\">{{ data.placeholder | translate }}</textarea>\n </ng-container>\n <ng-container *ngSwitchCase=\"'date'\">\n <input class=\"form-control\"\n type=\"date\"\n [attr.autocomplete]=\"data.autocomplete\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"value | date: 'y-MM-dd'\"\n (ngModelChange)=\"onDateChange($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\"/>\n </ng-container>\n <ng-container *ngSwitchCase=\"'number'\">\n <input class=\"form-control\"\n type=\"number\"\n [attr.autocomplete]=\"data.autocomplete\"\n [min]=\"data.min\"\n [max]=\"data.max\"\n [step]=\"data.step\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"value\"\n (ngModelChange)=\"control.setValue($event)\"\n (blur)=\"onNumberBlur()\"\n (focus)=\"control.onFocus()\"/>\n </ng-container>\n <ng-container *ngSwitchCase=\"'mask'\">\n <input class=\"form-control\"\n type=\"text\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [textMask]=\"{mask: data.mask, showMask: true, placeholderChar: data.placeholder}\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onMaskChange($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\"/>\n </ng-container>\n <ng-container *ngSwitchCase=\"'checkbox'\">\n <input class=\"form-control\"\n type=\"checkbox\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"value\"\n (ngModelChange)=\"control.setValue($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\"/>\n </ng-container>\n <ng-container *ngSwitchCase=\"'text'\">\n <input class=\"form-control\"\n type=\"text\"\n [attr.autocomplete]=\"data.autocomplete\"\n [minlength]=\"data.min\"\n [maxlength]=\"data.max\"\n [placeholder]=\"data.placeholder | translate\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"data.useLanguage ? (value | translate) : value\"\n (ngModelChange)=\"onTextChange($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\"/>\n </ng-container>\n <ng-container *ngSwitchDefault>\n <input class=\"form-control\"\n [attr.autocomplete]=\"data.autocomplete\"\n [minlength]=\"data.min\"\n [maxlength]=\"data.max\"\n [placeholder]=\"data.placeholder | translate\"\n [type]=\"data.type\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"value\"\n (ngModelChange)=\"control.setValue($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\"/>\n </ng-container>\n</ng-container>\n"
2053
- },] }
2054
- ];
2055
- DynamicFormInputComponent.ctorParameters = function () { return [
2056
- { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.LANGUAGE_SERVICE,] }] }
2057
- ]; };
2058
- DynamicFormInputComponent.propDecorators = {
2059
- isChecked: [{ type: core.HostBinding, args: ["class.checked",] }]
1984
+ var DynamicFormInputComponent = /** @class */ (function (_super) {
1985
+ __extends(DynamicFormInputComponent, _super);
1986
+ function DynamicFormInputComponent(language) {
1987
+ var _this = _super.call(this) || this;
1988
+ _this.language = language;
1989
+ return _this;
1990
+ }
1991
+ // Acceptor for provider
1992
+ DynamicFormInputComponent.acceptor = function (control) {
1993
+ return control.type == "input";
1994
+ };
1995
+ // Loader for provider
1996
+ DynamicFormInputComponent.loader = function () {
1997
+ return Promise.resolve();
1998
+ };
1999
+ Object.defineProperty(DynamicFormInputComponent.prototype, "isChecked", {
2000
+ get: function () {
2001
+ return this.data.type == "checkbox" && this.value;
2002
+ },
2003
+ enumerable: false,
2004
+ configurable: true
2005
+ });
2006
+ DynamicFormInputComponent.prototype.onDateChange = function (value) {
2007
+ var date = new Date(value);
2008
+ var dateValue = date.valueOf();
2009
+ if (isNaN(dateValue) || dateValue < -30610224000000)
2010
+ return;
2011
+ this.control.setValue(date);
2012
+ };
2013
+ DynamicFormInputComponent.prototype.onMaskChange = function (value) {
2014
+ value = ngxUtils.ObjectUtils.isFunction(this.data.unmask) ? this.data.unmask(value) : value;
2015
+ this.control.setValue(value);
2016
+ };
2017
+ DynamicFormInputComponent.prototype.onTextChange = function (value) {
2018
+ var _this = this;
2019
+ if (!this.data.useLanguage) {
2020
+ this.control.setValue(value);
2021
+ return;
2022
+ }
2023
+ var translations = ngxUtils.ObjectUtils.isArray(this.value) ? Array.from(this.value) : [];
2024
+ var translation = translations.find(function (t) { return t.lang == _this.language.editLanguage; });
2025
+ if (translation) {
2026
+ translation.translation = value;
2027
+ }
2028
+ else {
2029
+ translations.push({
2030
+ lang: this.language.editLanguage,
2031
+ translation: value
2032
+ });
2033
+ }
2034
+ this.control.setValue(translations);
2035
+ };
2036
+ DynamicFormInputComponent.prototype.onNumberBlur = function () {
2037
+ var value = this.value;
2038
+ if (ngxUtils.ObjectUtils.isNumber(this.data.max) && this.data.max < value) {
2039
+ this.control.setValue(this.data.max);
2040
+ }
2041
+ else if (ngxUtils.ObjectUtils.isNumber(this.data.min) && this.data.min > value) {
2042
+ this.control.setValue(this.data.min);
2043
+ }
2044
+ this.control.onBlur();
2045
+ };
2046
+ return DynamicFormInputComponent;
2047
+ }(FormControlComponent));
2048
+ DynamicFormInputComponent.decorators = [
2049
+ { type: core.Component, args: [{
2050
+ moduleId: module.id,
2051
+ selector: "dynamic-form-input",
2052
+ template: "<ng-container [ngSwitch]=\"data.type\">\r\n <ng-container *ngSwitchCase=\"'textarea'\">\r\n <textarea class=\"form-control\"\r\n rows=\"5\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">{{ data.placeholder | translate }}</textarea>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'date'\">\r\n <input class=\"form-control\"\r\n type=\"date\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value | date: 'y-MM-dd'\"\r\n (ngModelChange)=\"onDateChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'number'\">\r\n <input class=\"form-control\"\r\n type=\"number\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [min]=\"data.min\"\r\n [max]=\"data.max\"\r\n [step]=\"data.step\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"onNumberBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'mask'\">\r\n <input class=\"form-control\"\r\n type=\"text\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [textMask]=\"{mask: data.mask, showMask: true, placeholderChar: data.placeholder}\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"onMaskChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <input class=\"form-control\"\r\n type=\"checkbox\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'text'\">\r\n <input class=\"form-control\"\r\n type=\"text\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [minlength]=\"data.min\"\r\n [maxlength]=\"data.max\"\r\n [placeholder]=\"data.placeholder | translate\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"data.useLanguage ? (value | translate) : value\"\r\n (ngModelChange)=\"onTextChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchDefault>\r\n <input class=\"form-control\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [minlength]=\"data.min\"\r\n [maxlength]=\"data.max\"\r\n [placeholder]=\"data.placeholder | translate\"\r\n [type]=\"data.type\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n</ng-container>\r\n"
2053
+ },] }
2054
+ ];
2055
+ DynamicFormInputComponent.ctorParameters = function () { return [
2056
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.LANGUAGE_SERVICE,] }] }
2057
+ ]; };
2058
+ DynamicFormInputComponent.propDecorators = {
2059
+ isChecked: [{ type: core.HostBinding, args: ["class.checked",] }]
2060
2060
  };
2061
2061
 
2062
- var DynamicFormSelectComponent = /** @class */ (function (_super) {
2063
- __extends(DynamicFormSelectComponent, _super);
2064
- function DynamicFormSelectComponent() {
2065
- return _super !== null && _super.apply(this, arguments) || this;
2066
- }
2067
- // Acceptor for provider
2068
- DynamicFormSelectComponent.acceptor = function (control) {
2069
- return control.type == "select";
2070
- };
2071
- // Loader for provider
2072
- DynamicFormSelectComponent.loader = function (control) {
2073
- var data = control.getData();
2074
- if (data.type == "radio" && data.multi) {
2075
- return Promise.reject("Radio group doesn't support multi select!");
2076
- }
2077
- return new Promise(function (resolve) {
2078
- var getOptions = ngxUtils.ReflectUtils.resolve(data.options, control.form.injector);
2079
- getOptions(control).then(function (options) {
2080
- if (data.emptyOption)
2081
- options.unshift({ id: null, label: "" });
2082
- control.meta.options = options;
2083
- DynamicFormSelectComponent.fillOptions(control, options);
2084
- resolve(options);
2085
- });
2086
- });
2087
- };
2088
- DynamicFormSelectComponent.fillOptions = function (control, options) {
2089
- var data = control.getData();
2090
- var selected = control.value;
2091
- if (data.multi || options.length == 0 || options.findIndex(function (t) { return t.id == selected; }) >= 0)
2092
- return;
2093
- control.setValue(options[0].id);
2094
- };
2095
- DynamicFormSelectComponent.prototype.onSelectChange = function (value) {
2096
- var isArray = ngxUtils.ObjectUtils.isArray(value);
2097
- var current = this.value;
2098
- if (this.data.multi) {
2099
- if (isArray) {
2100
- this.control.setValue(value);
2101
- return;
2102
- }
2103
- if (ngxUtils.ObjectUtils.isArray(current)) {
2104
- this.control.setValue(current.indexOf(value) < 0
2105
- ? current.concat([value])
2106
- : current.filter(function (c) { return c !== value; }));
2107
- return;
2108
- }
2109
- this.control.setValue([value]);
2110
- return;
2111
- }
2112
- if (isArray)
2113
- value = value[0];
2114
- if (current == value) {
2115
- var option = this.meta.options.find(function (o) { return o.id !== value; });
2116
- value = option ? option.id : null;
2117
- }
2118
- this.control.setValue(value);
2119
- };
2120
- DynamicFormSelectComponent.prototype.checkValue = function (option) {
2121
- var value = this.value;
2122
- return ngxUtils.ObjectUtils.isArray(value) ? value.indexOf(option.id) >= 0 : option.id == value;
2123
- };
2124
- DynamicFormSelectComponent.prototype.findOption = function (option, index, id) {
2125
- return option.id == id;
2126
- };
2127
- return DynamicFormSelectComponent;
2128
- }(FormControlComponent));
2129
- DynamicFormSelectComponent.decorators = [
2130
- { type: core.Component, args: [{
2131
- moduleId: module.id,
2132
- selector: "dynamic-form-select",
2133
- template: "<ng-template #selectTemplate let-selected=\"selected\">\n <select class=\"form-control\"\n [multiple]=\"data.multi\"\n [id]=\"control.formId\"\n [name]=\"control.formId\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled\"\n [ngModel]=\"data.multi ? value : [value]\"\n (ngModelChange)=\"onSelectChange($event)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\">\n <option *ngFor=\"let option of meta.options\" [value]=\"option.id\" [disabled]=\"option.selectable == false\">\n {{ option.label | translate }}\n </option>\n </select>\n <label class=\"form-control-description\" [attr.for]=\"control.formId\" *ngIf=\"!data.multi && selected?.description\">\n {{ selected?.description | translate }}\n </label>\n</ng-template>\n<ng-container [ngSwitch]=\"data.type\">\n <ng-container *ngSwitchCase=\"'radio'\">\n <ul class=\"radio-group\">\n <li *ngFor=\"let option of meta.options\" class=\"radio\">\n <label [ngClass]=\"{checked: value == option.id}\">\n <input type=\"radio\"\n [id]=\"control.formId + '-' + option.id\"\n [name]=\"control.formId + '-' + option.id\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled || option.selectable == false\"\n [value]=\"option.id\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onSelectChange(option.id)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\">\n {{ option.label | translate }}\n </label>\n </li>\n </ul>\n </ng-container>\n <ng-container *ngSwitchCase=\"'checkbox'\">\n <ul class=\"checkbox-group\">\n <li *ngFor=\"let option of meta.options\" class=\"checkbox\">\n <label [ngClass]=\"{checked: checkValue(option)}\">\n <input type=\"checkbox\"\n [id]=\"control.formId + '-' + option.id\"\n [name]=\"control.formId + '-' + option.id\"\n [ngClass]=\"{disabled: control.disabled}\"\n [disabled]=\"control.disabled || option.selectable == false\"\n [ngModel]=\"checkValue(option)\"\n (ngModelChange)=\"onSelectChange(option.id)\"\n (blur)=\"control.onBlur()\"\n (focus)=\"control.onFocus()\">\n {{ option.label | translate }}\n </label>\n </li>\n </ul>\n </ng-container>\n <ng-container *ngSwitchDefault [ngTemplateOutlet]=\"selectTemplate\" [ngTemplateOutletContext]=\"{selected: meta?.options | find:findOption:value}\">\n\n </ng-container>\n</ng-container>\n"
2134
- },] }
2062
+ var DynamicFormSelectComponent = /** @class */ (function (_super) {
2063
+ __extends(DynamicFormSelectComponent, _super);
2064
+ function DynamicFormSelectComponent() {
2065
+ return _super !== null && _super.apply(this, arguments) || this;
2066
+ }
2067
+ // Acceptor for provider
2068
+ DynamicFormSelectComponent.acceptor = function (control) {
2069
+ return control.type == "select";
2070
+ };
2071
+ // Loader for provider
2072
+ DynamicFormSelectComponent.loader = function (control) {
2073
+ var data = control.getData();
2074
+ if (data.type == "radio" && data.multi) {
2075
+ return Promise.reject("Radio group doesn't support multi select!");
2076
+ }
2077
+ return new Promise(function (resolve) {
2078
+ var getOptions = ngxUtils.ReflectUtils.resolve(data.options, control.form.injector);
2079
+ getOptions(control).then(function (options) {
2080
+ if (data.emptyOption)
2081
+ options.unshift({ id: null, label: "" });
2082
+ control.meta.options = options;
2083
+ DynamicFormSelectComponent.fillOptions(control, options);
2084
+ resolve(options);
2085
+ });
2086
+ });
2087
+ };
2088
+ DynamicFormSelectComponent.fillOptions = function (control, options) {
2089
+ var data = control.getData();
2090
+ var selected = control.value;
2091
+ if (data.multi || options.length == 0 || options.findIndex(function (t) { return t.id == selected; }) >= 0)
2092
+ return;
2093
+ control.setValue(options[0].id);
2094
+ };
2095
+ DynamicFormSelectComponent.prototype.onSelectChange = function (value) {
2096
+ var isArray = ngxUtils.ObjectUtils.isArray(value);
2097
+ var current = this.value;
2098
+ if (this.data.multi) {
2099
+ if (isArray) {
2100
+ this.control.setValue(value);
2101
+ return;
2102
+ }
2103
+ if (ngxUtils.ObjectUtils.isArray(current)) {
2104
+ this.control.setValue(current.indexOf(value) < 0
2105
+ ? current.concat([value])
2106
+ : current.filter(function (c) { return c !== value; }));
2107
+ return;
2108
+ }
2109
+ this.control.setValue([value]);
2110
+ return;
2111
+ }
2112
+ if (isArray)
2113
+ value = value[0];
2114
+ if (current == value) {
2115
+ var option = this.meta.options.find(function (o) { return o.id !== value; });
2116
+ value = option ? option.id : null;
2117
+ }
2118
+ this.control.setValue(value);
2119
+ };
2120
+ DynamicFormSelectComponent.prototype.checkValue = function (option) {
2121
+ var value = this.value;
2122
+ return ngxUtils.ObjectUtils.isArray(value) ? value.indexOf(option.id) >= 0 : option.id == value;
2123
+ };
2124
+ DynamicFormSelectComponent.prototype.findOption = function (option, index, id) {
2125
+ return option.id == id;
2126
+ };
2127
+ return DynamicFormSelectComponent;
2128
+ }(FormControlComponent));
2129
+ DynamicFormSelectComponent.decorators = [
2130
+ { type: core.Component, args: [{
2131
+ moduleId: module.id,
2132
+ selector: "dynamic-form-select",
2133
+ template: "<ng-template #selectTemplate let-selected=\"selected\">\r\n <select class=\"form-control\"\r\n [multiple]=\"data.multi\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"data.multi ? value : [value]\"\r\n (ngModelChange)=\"onSelectChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n <option *ngFor=\"let option of meta.options\" [value]=\"option.id\" [disabled]=\"option.selectable == false\">\r\n {{ option.label | translate }}\r\n </option>\r\n </select>\r\n <label class=\"form-control-description\" [attr.for]=\"control.formId\" *ngIf=\"!data.multi && selected?.description\">\r\n {{ selected?.description | translate }}\r\n </label>\r\n</ng-template>\r\n<ng-container [ngSwitch]=\"data.type\">\r\n <ng-container *ngSwitchCase=\"'radio'\">\r\n <ul class=\"radio-group\">\r\n <li *ngFor=\"let option of meta.options\" class=\"radio\">\r\n <label [ngClass]=\"{checked: value == option.id}\">\r\n <input type=\"radio\"\r\n [id]=\"control.formId + '-' + option.id\"\r\n [name]=\"control.formId + '-' + option.id\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled || option.selectable == false\"\r\n [value]=\"option.id\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"onSelectChange(option.id)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n {{ option.label | translate }}\r\n </label>\r\n </li>\r\n </ul>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <ul class=\"checkbox-group\">\r\n <li *ngFor=\"let option of meta.options\" class=\"checkbox\">\r\n <label [ngClass]=\"{checked: checkValue(option)}\">\r\n <input type=\"checkbox\"\r\n [id]=\"control.formId + '-' + option.id\"\r\n [name]=\"control.formId + '-' + option.id\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled || option.selectable == false\"\r\n [ngModel]=\"checkValue(option)\"\r\n (ngModelChange)=\"onSelectChange(option.id)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n {{ option.label | translate }}\r\n </label>\r\n </li>\r\n </ul>\r\n </ng-container>\r\n <ng-container *ngSwitchDefault [ngTemplateOutlet]=\"selectTemplate\" [ngTemplateOutletContext]=\"{selected: meta?.options | find:findOption:value}\">\r\n\r\n </ng-container>\r\n</ng-container>\r\n"
2134
+ },] }
2135
2135
  ];
2136
2136
 
2137
- var DynamicFormStaticComponent = /** @class */ (function (_super) {
2138
- __extends(DynamicFormStaticComponent, _super);
2139
- function DynamicFormStaticComponent() {
2140
- return _super !== null && _super.apply(this, arguments) || this;
2141
- }
2142
- // Acceptor for provider
2143
- DynamicFormStaticComponent.acceptor = function (control) {
2144
- return control.type == "static";
2145
- };
2146
- // Loader for provider
2147
- DynamicFormStaticComponent.loader = function () {
2148
- return Promise.resolve();
2149
- };
2150
- return DynamicFormStaticComponent;
2151
- }(FormControlComponent));
2152
- DynamicFormStaticComponent.decorators = [
2153
- { type: core.Component, args: [{
2154
- moduleId: module.id,
2155
- selector: "dynamic-form-static",
2156
- template: "<unordered-list [listStyle]=\"data.style\" [ngClass]=\"{disabled: control.disabled}\"\n [data]=\"!data.properties ? {value: value} : data.properties | remap: value\">\n <ng-template [type]=\"!data.properties ? 'key' : null\" selector=\"level == 0\" let-item=\"item\"></ng-template>\n <ng-template type=\"value\" selector=\"valueType == 'date'\" let-item=\"item\">\n {{ item.value | date }}\n </ng-template>\n</unordered-list>\n"
2157
- },] }
2137
+ var DynamicFormStaticComponent = /** @class */ (function (_super) {
2138
+ __extends(DynamicFormStaticComponent, _super);
2139
+ function DynamicFormStaticComponent() {
2140
+ return _super !== null && _super.apply(this, arguments) || this;
2141
+ }
2142
+ // Acceptor for provider
2143
+ DynamicFormStaticComponent.acceptor = function (control) {
2144
+ return control.type == "static";
2145
+ };
2146
+ // Loader for provider
2147
+ DynamicFormStaticComponent.loader = function () {
2148
+ return Promise.resolve();
2149
+ };
2150
+ return DynamicFormStaticComponent;
2151
+ }(FormControlComponent));
2152
+ DynamicFormStaticComponent.decorators = [
2153
+ { type: core.Component, args: [{
2154
+ moduleId: module.id,
2155
+ selector: "dynamic-form-static",
2156
+ template: "<unordered-list [listStyle]=\"data.style\" [ngClass]=\"{disabled: control.disabled}\"\r\n [data]=\"!data.properties ? {value: value} : data.properties | remap: value\">\r\n <ng-template [type]=\"!data.properties ? 'key' : null\" selector=\"level == 0\" let-item=\"item\"></ng-template>\r\n <ng-template type=\"value\" selector=\"valueType == 'date'\" let-item=\"item\">\r\n {{ item.value | date }}\r\n </ng-template>\r\n</unordered-list>\r\n"
2157
+ },] }
2158
2158
  ];
2159
2159
 
2160
- var DynamicFormModelComponent = /** @class */ (function (_super) {
2161
- __extends(DynamicFormModelComponent, _super);
2162
- function DynamicFormModelComponent() {
2163
- return _super !== null && _super.apply(this, arguments) || this;
2164
- }
2165
- // Acceptor for provider
2166
- DynamicFormModelComponent.acceptor = function (control) {
2167
- return control.type == "model";
2168
- };
2169
- // Loader for provider
2170
- DynamicFormModelComponent.loader = function () {
2171
- return Promise.resolve();
2172
- };
2173
- return DynamicFormModelComponent;
2174
- }(FormControlComponent));
2175
- DynamicFormModelComponent.decorators = [
2176
- { type: core.Component, args: [{
2177
- moduleId: module.id,
2178
- selector: "dynamic-form-model",
2179
- template: "<dynamic-form [name]=\"data.name || form.name\"\n [group]=\"control\"\n [data]=\"value\"\n [updateOn]=\"control.updateOn\"\n [parent]=\"form\"\n\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\n [controlTemplates]=\"form.controlTemplates\"\n\n [controlTemplate]=\"form.controlTemplate\"\n [labelTemplates]=\"form.labelTemplates\"\n [inputTemplates]=\"form.inputTemplates\"\n [prefixTemplates]=\"form.prefixTemplates\"\n [suffixTemplates]=\"form.suffixTemplates\"\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\n\n #subForm>\n <ng-template #wrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\n </ng-template>\n</dynamic-form>\n"
2180
- },] }
2181
- ];
2182
- DynamicFormModelComponent.propDecorators = {
2183
- subForm: [{ type: core.ViewChild, args: ["subForm",] }]
2160
+ var DynamicFormModelComponent = /** @class */ (function (_super) {
2161
+ __extends(DynamicFormModelComponent, _super);
2162
+ function DynamicFormModelComponent() {
2163
+ return _super !== null && _super.apply(this, arguments) || this;
2164
+ }
2165
+ // Acceptor for provider
2166
+ DynamicFormModelComponent.acceptor = function (control) {
2167
+ return control.type == "model";
2168
+ };
2169
+ // Loader for provider
2170
+ DynamicFormModelComponent.loader = function () {
2171
+ return Promise.resolve();
2172
+ };
2173
+ return DynamicFormModelComponent;
2174
+ }(FormControlComponent));
2175
+ DynamicFormModelComponent.decorators = [
2176
+ { type: core.Component, args: [{
2177
+ moduleId: module.id,
2178
+ selector: "dynamic-form-model",
2179
+ template: "<dynamic-form [name]=\"data.name || form.name\"\r\n [group]=\"control\"\r\n [data]=\"value\"\r\n [updateOn]=\"control.updateOn\"\r\n [parent]=\"form\"\r\n\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n #subForm>\r\n <ng-template #wrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\r\n </ng-template>\r\n</dynamic-form>\r\n"
2180
+ },] }
2181
+ ];
2182
+ DynamicFormModelComponent.propDecorators = {
2183
+ subForm: [{ type: core.ViewChild, args: ["subForm",] }]
2184
2184
  };
2185
2185
 
2186
- var DynamicFormGroupDirective = /** @class */ (function () {
2187
- function DynamicFormGroupDirective(vcr, forms) {
2188
- this.vcr = vcr;
2189
- this.forms = forms;
2190
- }
2191
- Object.defineProperty(DynamicFormGroupDirective.prototype, "component", {
2192
- get: function () {
2193
- return this.comp;
2194
- },
2195
- enumerable: false,
2196
- configurable: true
2197
- });
2198
- DynamicFormGroupDirective.prototype.ngOnChanges = function (changes) {
2199
- if (changes.control || changes.form || changes.visible) {
2200
- if (!this.visible) {
2201
- this.vcr.clear();
2202
- this.comp = null;
2203
- return;
2204
- }
2205
- this.comp = this.forms.createGroup(this.vcr);
2206
- }
2207
- if (!this.comp)
2208
- return;
2209
- this.comp.form = this.form;
2210
- this.comp.control = this.control;
2211
- };
2212
- return DynamicFormGroupDirective;
2213
- }());
2214
- DynamicFormGroupDirective.decorators = [
2215
- { type: core.Directive, args: [{
2216
- selector: "[form-group]",
2217
- },] }
2218
- ];
2219
- DynamicFormGroupDirective.ctorParameters = function () { return [
2220
- { type: core.ViewContainerRef },
2221
- { type: DynamicFormService }
2222
- ]; };
2223
- DynamicFormGroupDirective.propDecorators = {
2224
- control: [{ type: core.Input, args: ["form-group",] }],
2225
- form: [{ type: core.Input }],
2226
- visible: [{ type: core.Input }]
2186
+ var DynamicFormGroupDirective = /** @class */ (function () {
2187
+ function DynamicFormGroupDirective(vcr, forms) {
2188
+ this.vcr = vcr;
2189
+ this.forms = forms;
2190
+ }
2191
+ Object.defineProperty(DynamicFormGroupDirective.prototype, "component", {
2192
+ get: function () {
2193
+ return this.comp;
2194
+ },
2195
+ enumerable: false,
2196
+ configurable: true
2197
+ });
2198
+ DynamicFormGroupDirective.prototype.ngOnChanges = function (changes) {
2199
+ if (changes.control || changes.form || changes.visible) {
2200
+ if (!this.visible) {
2201
+ this.vcr.clear();
2202
+ this.comp = null;
2203
+ return;
2204
+ }
2205
+ this.comp = this.forms.createGroup(this.vcr);
2206
+ }
2207
+ if (!this.comp)
2208
+ return;
2209
+ this.comp.form = this.form;
2210
+ this.comp.control = this.control;
2211
+ };
2212
+ return DynamicFormGroupDirective;
2213
+ }());
2214
+ DynamicFormGroupDirective.decorators = [
2215
+ { type: core.Directive, args: [{
2216
+ selector: "[form-group]",
2217
+ },] }
2218
+ ];
2219
+ DynamicFormGroupDirective.ctorParameters = function () { return [
2220
+ { type: core.ViewContainerRef },
2221
+ { type: DynamicFormService }
2222
+ ]; };
2223
+ DynamicFormGroupDirective.propDecorators = {
2224
+ control: [{ type: core.Input, args: ["form-group",] }],
2225
+ form: [{ type: core.Input }],
2226
+ visible: [{ type: core.Input }]
2227
2227
  };
2228
2228
 
2229
- // --- Components ---
2230
- var components = [
2231
- DynamicFormsComponent,
2232
- DynamicFormComponent,
2233
- DynamicFormGroupComponent,
2234
- DynamicFormFileComponent,
2235
- DynamicFormInputComponent,
2236
- DynamicFormSelectComponent,
2237
- DynamicFormStaticComponent,
2238
- DynamicFormModelComponent
2239
- ];
2240
- // --- Directives ---
2241
- var directives = [
2242
- AsyncSubmitDirective,
2243
- DynamicFormControlDirective,
2244
- DynamicFormGroupDirective,
2245
- DynamicFormTemplateDirective
2246
- ];
2247
- // --- Pipes ---
2248
- var pipes = [];
2249
- var NgxDynamicFormModule = /** @class */ (function () {
2250
- function NgxDynamicFormModule() {
2251
- }
2252
- NgxDynamicFormModule.forRoot = function (controlProviders, groupProvider) {
2253
- return {
2254
- ngModule: NgxDynamicFormModule,
2255
- providers: __spread([
2256
- DynamicFormService,
2257
- OpenApiService,
2258
- provideFormControl(DynamicFormFileComponent, DynamicFormFileComponent.acceptor, DynamicFormFileComponent.loader),
2259
- provideFormControl(DynamicFormInputComponent, DynamicFormInputComponent.acceptor, DynamicFormInputComponent.loader),
2260
- provideFormControl(DynamicFormSelectComponent, DynamicFormSelectComponent.acceptor, DynamicFormSelectComponent.loader),
2261
- provideFormControl(DynamicFormStaticComponent, DynamicFormStaticComponent.acceptor, DynamicFormStaticComponent.loader),
2262
- provideFormControl(DynamicFormModelComponent, DynamicFormModelComponent.acceptor, DynamicFormModelComponent.loader)
2263
- ], (controlProviders || []), [
2264
- groupProvider || provideFormGroup(DynamicFormGroupComponent)
2265
- ])
2266
- };
2267
- };
2268
- return NgxDynamicFormModule;
2269
- }());
2270
- NgxDynamicFormModule.decorators = [
2271
- { type: core.NgModule, args: [{
2272
- declarations: __spread(components, directives, pipes),
2273
- imports: [
2274
- common.CommonModule,
2275
- forms.FormsModule,
2276
- forms.ReactiveFormsModule,
2277
- angular2TextMask.TextMaskModule,
2278
- ngxUtils.NgxUtilsModule
2279
- ],
2280
- exports: __spread(components, directives, pipes, [
2281
- forms.FormsModule,
2282
- forms.ReactiveFormsModule,
2283
- ngxUtils.NgxUtilsModule
2284
- ]),
2285
- entryComponents: components,
2286
- providers: pipes
2287
- },] }
2229
+ // --- Components ---
2230
+ var components = [
2231
+ DynamicFormsComponent,
2232
+ DynamicFormComponent,
2233
+ DynamicFormGroupComponent,
2234
+ DynamicFormFileComponent,
2235
+ DynamicFormInputComponent,
2236
+ DynamicFormSelectComponent,
2237
+ DynamicFormStaticComponent,
2238
+ DynamicFormModelComponent
2239
+ ];
2240
+ // --- Directives ---
2241
+ var directives = [
2242
+ AsyncSubmitDirective,
2243
+ DynamicFormControlDirective,
2244
+ DynamicFormGroupDirective,
2245
+ DynamicFormTemplateDirective
2246
+ ];
2247
+ // --- Pipes ---
2248
+ var pipes = [];
2249
+ var NgxDynamicFormModule = /** @class */ (function () {
2250
+ function NgxDynamicFormModule() {
2251
+ }
2252
+ NgxDynamicFormModule.forRoot = function (controlProviders, groupProvider) {
2253
+ return {
2254
+ ngModule: NgxDynamicFormModule,
2255
+ providers: __spread([
2256
+ DynamicFormService,
2257
+ OpenApiService,
2258
+ provideFormControl(DynamicFormFileComponent, DynamicFormFileComponent.acceptor, DynamicFormFileComponent.loader),
2259
+ provideFormControl(DynamicFormInputComponent, DynamicFormInputComponent.acceptor, DynamicFormInputComponent.loader),
2260
+ provideFormControl(DynamicFormSelectComponent, DynamicFormSelectComponent.acceptor, DynamicFormSelectComponent.loader),
2261
+ provideFormControl(DynamicFormStaticComponent, DynamicFormStaticComponent.acceptor, DynamicFormStaticComponent.loader),
2262
+ provideFormControl(DynamicFormModelComponent, DynamicFormModelComponent.acceptor, DynamicFormModelComponent.loader)
2263
+ ], (controlProviders || []), [
2264
+ groupProvider || provideFormGroup(DynamicFormGroupComponent)
2265
+ ])
2266
+ };
2267
+ };
2268
+ return NgxDynamicFormModule;
2269
+ }());
2270
+ NgxDynamicFormModule.decorators = [
2271
+ { type: core.NgModule, args: [{
2272
+ declarations: __spread(components, directives, pipes),
2273
+ imports: [
2274
+ common.CommonModule,
2275
+ forms.FormsModule,
2276
+ forms.ReactiveFormsModule,
2277
+ angular2TextMask.TextMaskModule,
2278
+ ngxUtils.NgxUtilsModule
2279
+ ],
2280
+ exports: __spread(components, directives, pipes, [
2281
+ forms.FormsModule,
2282
+ forms.ReactiveFormsModule,
2283
+ ngxUtils.NgxUtilsModule
2284
+ ]),
2285
+ entryComponents: components,
2286
+ providers: pipes
2287
+ },] }
2288
2288
  ];
2289
2289
 
2290
- /**
2291
- * Generated bundle index. Do not edit.
2290
+ /**
2291
+ * Generated bundle index. Do not edit.
2292
2292
  */
2293
2293
 
2294
2294
  exports.AsyncSubmitDirective = AsyncSubmitDirective;