not-bulma 1.0.32 → 1.0.35
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.
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export let align = 'left';
|
|
10
10
|
|
|
11
11
|
let size2;
|
|
12
|
-
$: size2 = subsize?subsize:(size<6?size+1:size);
|
|
12
|
+
$: size2 = subsize?subsize:(parseInt(size)<6?parseInt(size)+1:size);
|
|
13
13
|
$: spacedStyle = (spaced?'is-spaced':'');
|
|
14
14
|
|
|
15
15
|
$: resultTitle = `<h${size} style="text-align: ${align};" class="title ${spacedStyle} is-${size}">${$LOCALE[title]}</h${size}>`;
|
|
@@ -1,225 +1,226 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Runner
|
|
3
|
-
} from 'not-validation';
|
|
1
|
+
import { Runner } from "not-validation";
|
|
4
2
|
|
|
5
|
-
import {VARIANTS} from
|
|
6
|
-
import Lib from
|
|
7
|
-
import notCommon from
|
|
8
|
-
import notBase from
|
|
3
|
+
import { VARIANTS } from "../../LIB.js";
|
|
4
|
+
import Lib from "../../lib.js";
|
|
5
|
+
import notCommon from "../../common";
|
|
6
|
+
import notBase from "../../base";
|
|
9
7
|
|
|
10
|
-
import UICommon from
|
|
11
|
-
import FormHelpers from
|
|
12
|
-
import UIFormComponent from
|
|
8
|
+
import UICommon from "../../../elements/common.js";
|
|
9
|
+
import FormHelpers from "./form.helpers.js";
|
|
10
|
+
import UIFormComponent from "./form.svelte";
|
|
13
11
|
|
|
14
|
-
import {
|
|
15
|
-
DEFAULT_STATUS_SUCCESS,
|
|
16
|
-
DEFAULT_STATUS_ERROR
|
|
17
|
-
} from '../../const';
|
|
12
|
+
import { DEFAULT_STATUS_SUCCESS, DEFAULT_STATUS_ERROR } from "../../const";
|
|
18
13
|
|
|
19
|
-
const DEFAULT_CONTAINER_SELECTOR =
|
|
20
|
-
const DEFAULT_ACTION_NAME =
|
|
21
|
-
const DEFAULT_VARIANT_NAME =
|
|
14
|
+
const DEFAULT_CONTAINER_SELECTOR = ".form";
|
|
15
|
+
const DEFAULT_ACTION_NAME = "default";
|
|
16
|
+
const DEFAULT_VARIANT_NAME = "noname";
|
|
22
17
|
|
|
23
18
|
class notForm extends notBase {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this
|
|
142
|
-
this
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
19
|
+
//UI renderer component class constructor
|
|
20
|
+
#uiComponent = null;
|
|
21
|
+
//form validation
|
|
22
|
+
#validationRunner = null;
|
|
23
|
+
//ui component
|
|
24
|
+
#form = null;
|
|
25
|
+
//model.action
|
|
26
|
+
#action = DEFAULT_ACTION_NAME;
|
|
27
|
+
//fields schemas
|
|
28
|
+
#fields = new Lib(); //fields of UI
|
|
29
|
+
//variants sets for select menus and so on
|
|
30
|
+
#variants = null; //variants for UI
|
|
31
|
+
|
|
32
|
+
constructor({
|
|
33
|
+
target = null,
|
|
34
|
+
name = "Default",
|
|
35
|
+
options = {},
|
|
36
|
+
working = {},
|
|
37
|
+
data = {},
|
|
38
|
+
ui = UIFormComponent, //default UI
|
|
39
|
+
}) {
|
|
40
|
+
super({
|
|
41
|
+
working: {
|
|
42
|
+
name: `${name}Form`,
|
|
43
|
+
...working,
|
|
44
|
+
},
|
|
45
|
+
options,
|
|
46
|
+
data,
|
|
47
|
+
});
|
|
48
|
+
this.#variants = new Lib(VARIANTS.getContent());
|
|
49
|
+
if (target) {
|
|
50
|
+
this.setOptions("target", target);
|
|
51
|
+
}
|
|
52
|
+
this.#uiComponent = ui;
|
|
53
|
+
if (notCommon.objHas(options, "action")) {
|
|
54
|
+
this.#action = options.action;
|
|
55
|
+
}
|
|
56
|
+
this.initForm();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
initForm() {
|
|
60
|
+
if (this.getOptions("autoInit", true)) {
|
|
61
|
+
this.initLibs();
|
|
62
|
+
}
|
|
63
|
+
if (this.getOptions("autoRender", true)) {
|
|
64
|
+
this.initUI();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
initLibs() {
|
|
69
|
+
this.initFields();
|
|
70
|
+
this.initVariants();
|
|
71
|
+
this.initValidator();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
reInit() {
|
|
75
|
+
this.initLibs();
|
|
76
|
+
this.updateUI();
|
|
77
|
+
this.resetLoading();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
initFields() {
|
|
81
|
+
const manifest = this.getFormManifest();
|
|
82
|
+
if (notCommon.objHas(manifest, "fields") && this.#fields.isEmpty()) {
|
|
83
|
+
this.#fields.import(manifest.fields); //all fields available in model manifest
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
initVariants() {
|
|
88
|
+
if (this.getOptions("variants")) {
|
|
89
|
+
this.#variants.import(this.getOptions("variants"));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//creating validators runner for this specific form
|
|
94
|
+
initValidator() {
|
|
95
|
+
this.#validationRunner = Runner(this.getFormValidators());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
initUI() {
|
|
99
|
+
try {
|
|
100
|
+
const props = this.#getFormProps({
|
|
101
|
+
manifest: this.getFormManifest(),
|
|
102
|
+
formOptions: this.getFormOptions(),
|
|
103
|
+
data: this.getFormData(),
|
|
104
|
+
injectedProps: this.getFormInjectedProps(),
|
|
105
|
+
});
|
|
106
|
+
const target = this.getFormTargetEl();
|
|
107
|
+
while (target.children.length)
|
|
108
|
+
target.removeChild(target.firstChild);
|
|
109
|
+
this.#form = new this.#uiComponent({
|
|
110
|
+
target,
|
|
111
|
+
props,
|
|
112
|
+
});
|
|
113
|
+
this.#bindUIEvents();
|
|
114
|
+
this.validateForm();
|
|
115
|
+
} catch (e) {
|
|
116
|
+
this.error(e);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updateUI() {
|
|
121
|
+
try {
|
|
122
|
+
const props = this.#getFormProps({
|
|
123
|
+
manifest: this.getFormManifest(),
|
|
124
|
+
formOptions: this.getFormOptions(),
|
|
125
|
+
data: this.getFormData(),
|
|
126
|
+
injectedProps: this.getFormInjectedProps(),
|
|
127
|
+
});
|
|
128
|
+
this.#form.$set(props);
|
|
129
|
+
this.validateForm();
|
|
130
|
+
} catch (e) {
|
|
131
|
+
this.error(e);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#bindUIEvents() {
|
|
136
|
+
this.#form.$on("change", () => this.validateForm());
|
|
137
|
+
this.#form.$on("change", (ev) => {
|
|
138
|
+
this.emit("change", ev.detail);
|
|
139
|
+
this.emit(`change.${ev.detail.field}`, ev.detail.value);
|
|
140
|
+
});
|
|
141
|
+
this.#form.$on("submit", (ev) => this.submit(ev.detail));
|
|
142
|
+
this.#form.$on("reject", () => this.reject());
|
|
143
|
+
this.#form.$on("error", ({ detail }) => this.emit("error", detail));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async validateForm() {
|
|
147
|
+
if (this.getOptions("readonly", false)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const validationResult = await this.#validationRunner(
|
|
152
|
+
this.#form.collectData(),
|
|
153
|
+
this.getFormAction()
|
|
154
|
+
);
|
|
155
|
+
this.#form.updateFormValidationStatus(validationResult.getReport());
|
|
156
|
+
if (!validationResult.clean) {
|
|
157
|
+
this.emit("error", validationResult.getReport());
|
|
158
|
+
}
|
|
159
|
+
} catch (e) {
|
|
160
|
+
const report = {
|
|
161
|
+
form: [UICommon.ERROR_DEFAULT, e.message],
|
|
162
|
+
};
|
|
163
|
+
this.#form && this.#form.updateFormValidationStatus(report);
|
|
164
|
+
this.emit("error", report);
|
|
165
|
+
notCommon.report(e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
submit(data) {
|
|
170
|
+
this.emit("submit", data);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
reject() {
|
|
174
|
+
this.emit("reject");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
setLoading() {
|
|
178
|
+
this.emit("loading");
|
|
179
|
+
this.#form.setLoading();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
resetLoading() {
|
|
183
|
+
this.emit("loaded");
|
|
184
|
+
this.#form.resetLoading();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
destroy() {
|
|
188
|
+
this.emit("destroy");
|
|
189
|
+
if (this.#form) {
|
|
190
|
+
this.#form.$destroy && this.#form.$destroy();
|
|
191
|
+
this.#form.destroy && this.#form.destroy();
|
|
192
|
+
this.#form = null;
|
|
193
|
+
}
|
|
194
|
+
this.#validationRunner = null;
|
|
195
|
+
this.#action = null;
|
|
196
|
+
this.#fields = null;
|
|
197
|
+
this.#variants = null;
|
|
198
|
+
this.setOptions(null);
|
|
199
|
+
this.setWorking(null);
|
|
200
|
+
this.setData(null);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
#getFormProps({
|
|
204
|
+
manifest, //model manifest
|
|
205
|
+
formOptions = {
|
|
206
|
+
ui: {},
|
|
207
|
+
fields: {},
|
|
208
|
+
}, //some options
|
|
209
|
+
data = null, //initial data for form
|
|
210
|
+
injectedProps = {},
|
|
211
|
+
}) {
|
|
212
|
+
const action = this.#action;
|
|
213
|
+
if (typeof formOptions === "undefined" || formOptions === null) {
|
|
214
|
+
formOptions = {
|
|
215
|
+
ui: {},
|
|
216
|
+
fields: {},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const form = FormHelpers.initFormByField(
|
|
221
|
+
//form seed object
|
|
222
|
+
{},
|
|
223
|
+
/*
|
|
223
224
|
Form structure
|
|
224
225
|
[
|
|
225
226
|
//each item is line of form
|
|
@@ -230,195 +231,205 @@ class notForm extends notBase {
|
|
|
230
231
|
[email, telephone]
|
|
231
232
|
]
|
|
232
233
|
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
getFormAction() {
|
|
257
|
-
return this.#action;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
setFormAction(val) {
|
|
261
|
-
if (val && val !== this.#action) {
|
|
262
|
-
this.#action = val;
|
|
263
|
-
this.#form && this.#form.$destroy();
|
|
264
|
-
this.initForm();
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
processResult(result) {
|
|
269
|
-
if (result.status === DEFAULT_STATUS_SUCCESS) {
|
|
270
|
-
this.setFormSuccess();
|
|
271
|
-
return true;
|
|
272
|
-
} else {
|
|
273
|
-
this.setFormErrors(result);
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Form validation result
|
|
280
|
-
**/
|
|
281
|
-
setFormSuccess() {
|
|
282
|
-
this.#form.showSuccess();
|
|
283
|
-
this.emit('success');
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
setFormErrors(result) {
|
|
287
|
-
const status = {
|
|
288
|
-
form: [],
|
|
289
|
-
fields: {}
|
|
290
|
-
};
|
|
291
|
-
if (result.message) {
|
|
292
|
-
status.form.push(result.message);
|
|
293
|
-
}
|
|
294
|
-
if (result.errors && Object.keys(result.errors).length > 0) {
|
|
295
|
-
status.fields = { ...result.errors
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
this.#form.updateFormValidationStatus(status);
|
|
299
|
-
this.emit('error', status);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Returns variant by collection name and item id
|
|
304
|
-
* @param {string} name name of the variants collection
|
|
305
|
-
* @param {string|number} id item identificator
|
|
306
|
-
* @returns {object} item
|
|
307
|
-
**/
|
|
308
|
-
getVariant(name, id) {
|
|
309
|
-
let lib = this.#variants.get(name);
|
|
310
|
-
let result = lib.find(item => item.id === id);
|
|
311
|
-
if (result) {
|
|
312
|
-
return result;
|
|
313
|
-
}
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/***
|
|
318
|
-
* Redefinable getters
|
|
319
|
-
**/
|
|
320
|
-
|
|
321
|
-
getFormTargetEl() {
|
|
322
|
-
const targetEl = this.getOptions(
|
|
323
|
-
'target',
|
|
324
|
-
DEFAULT_CONTAINER_SELECTOR
|
|
325
|
-
);
|
|
326
|
-
if (targetEl instanceof HTMLElement) {
|
|
327
|
-
return targetEl;
|
|
328
|
-
} else if (typeof targetEl === 'string') {
|
|
329
|
-
return document.querySelector(targetEl);
|
|
330
|
-
} else {
|
|
331
|
-
throw new Error('Form parent element is not defined');
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
getFormValidators() {
|
|
336
|
-
if (this.getOptions('validators')) {
|
|
337
|
-
return this.getOptions('validators', {});
|
|
338
|
-
} else {
|
|
339
|
-
this.#missingOverrideWarning('validators');
|
|
340
|
-
return {};
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
getFormManifest() {
|
|
345
|
-
const modelName = this.getModelName();
|
|
346
|
-
if (modelName && notCommon.getApp()) {
|
|
347
|
-
return notCommon.getApp().getInterfaceManifest(modelName);
|
|
348
|
-
}
|
|
349
|
-
if (this.getOptions('manifest', undefined)) {
|
|
350
|
-
return this.getOptions('manifest', {});
|
|
351
|
-
} else {
|
|
352
|
-
this.#missingOverrideWarning('manifest');
|
|
353
|
-
return {};
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
getFormData() {
|
|
358
|
-
if (this.getData()) {
|
|
359
|
-
return this.getData();
|
|
360
|
-
} else {
|
|
361
|
-
this.#missingOverrideWarning('data');
|
|
362
|
-
return {};
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
getFormOptions() {
|
|
367
|
-
if (this.getOptions('ui', undefined) || this.getOptions('fields', undefined)) {
|
|
368
|
-
return {
|
|
369
|
-
ui: this.getOptions('ui', {}),
|
|
370
|
-
fields: this.getOptions('fields', {}),
|
|
371
|
-
};
|
|
372
|
-
} else {
|
|
373
|
-
this.#missingOverrideWarning('options');
|
|
374
|
-
return {
|
|
375
|
-
ui: {},
|
|
376
|
-
fields: {},
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Override empty message
|
|
383
|
-
**/
|
|
384
|
-
#missingOverrideWarning(missing) {
|
|
385
|
-
this.error(`${missing} for ${this.getWorking('name')} form is not defined`);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Form operations
|
|
390
|
-
**/
|
|
391
|
-
collectData() {
|
|
392
|
-
const data = this.#form.collectData();
|
|
393
|
-
this.setData({ ...data
|
|
394
|
-
}); //update in inner store
|
|
395
|
-
return data;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
updateField(fieldName, props){
|
|
399
|
-
this.#form.updateField(fieldName, props);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
getModel(name, data){
|
|
403
|
-
if(typeof name === 'string'){
|
|
404
|
-
return this.getInterface(name)(data || {});
|
|
405
|
-
}else{
|
|
406
|
-
return this.getInterface()(name || {});
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
getInterface(name = false){
|
|
411
|
-
return notCommon.getApp().getInterface(name || this.getModelName());
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Returns current model name
|
|
416
|
-
* @return {string}
|
|
417
|
-
*/
|
|
418
|
-
getModelName() {
|
|
419
|
-
return this.getOptions('model');
|
|
420
|
-
}
|
|
234
|
+
manifest.actions[action].fields, //form fields structure
|
|
235
|
+
this.#variants, //variants library
|
|
236
|
+
this.#fields, //fields library
|
|
237
|
+
formOptions.fields, //form wide fields options
|
|
238
|
+
data
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
//if no auto init of form structure, set to loading state
|
|
243
|
+
loading: !this.getOptions("autoInit", true),
|
|
244
|
+
title: manifest.actions[action].title,
|
|
245
|
+
description: manifest.actions[action].description,
|
|
246
|
+
fields: manifest.actions[action].fields,
|
|
247
|
+
form,
|
|
248
|
+
//injecting options to UI from top level input
|
|
249
|
+
...formOptions.ui, //form UI options
|
|
250
|
+
...injectedProps,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
getName() {
|
|
255
|
+
return this.getWorking("name");
|
|
256
|
+
}
|
|
421
257
|
|
|
258
|
+
getFormAction() {
|
|
259
|
+
return this.#action;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
setFormAction(val) {
|
|
263
|
+
if (val && val !== this.#action) {
|
|
264
|
+
this.#action = val;
|
|
265
|
+
this.#form && this.#form.$destroy();
|
|
266
|
+
this.initForm();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
processResult(result) {
|
|
271
|
+
if (result.status === DEFAULT_STATUS_SUCCESS) {
|
|
272
|
+
this.setFormSuccess();
|
|
273
|
+
return true;
|
|
274
|
+
} else {
|
|
275
|
+
this.setFormErrors(result);
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Form validation result
|
|
282
|
+
**/
|
|
283
|
+
setFormSuccess() {
|
|
284
|
+
this.#form.showSuccess();
|
|
285
|
+
this.emit("success");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
setFormErrors(result) {
|
|
289
|
+
if (this.getOptions("readonly", false)) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const status = {
|
|
293
|
+
form: [],
|
|
294
|
+
fields: {},
|
|
295
|
+
};
|
|
296
|
+
if (result.message) {
|
|
297
|
+
status.form.push(result.message);
|
|
298
|
+
}
|
|
299
|
+
if (result.errors && Object.keys(result.errors).length > 0) {
|
|
300
|
+
status.fields = { ...result.errors };
|
|
301
|
+
}
|
|
302
|
+
this.#form.updateFormValidationStatus(status);
|
|
303
|
+
this.emit("error", status);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Returns variant by collection name and item id
|
|
308
|
+
* @param {string} name name of the variants collection
|
|
309
|
+
* @param {string|number} id item identificator
|
|
310
|
+
* @returns {object} item
|
|
311
|
+
**/
|
|
312
|
+
getVariant(name, id) {
|
|
313
|
+
let lib = this.#variants.get(name);
|
|
314
|
+
let result = lib.find((item) => item.id === id);
|
|
315
|
+
if (result) {
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/***
|
|
322
|
+
* Redefinable getters
|
|
323
|
+
**/
|
|
324
|
+
|
|
325
|
+
getFormTargetEl() {
|
|
326
|
+
const targetEl = this.getOptions("target", DEFAULT_CONTAINER_SELECTOR);
|
|
327
|
+
if (targetEl instanceof HTMLElement) {
|
|
328
|
+
return targetEl;
|
|
329
|
+
} else if (typeof targetEl === "string") {
|
|
330
|
+
return document.querySelector(targetEl);
|
|
331
|
+
} else {
|
|
332
|
+
throw new Error("Form parent element is not defined");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
getFormValidators() {
|
|
337
|
+
if (this.getOptions("validators")) {
|
|
338
|
+
return this.getOptions("validators", {});
|
|
339
|
+
} else {
|
|
340
|
+
this.#missingOverrideWarning("validators");
|
|
341
|
+
return {};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
getFormManifest() {
|
|
346
|
+
const modelName = this.getModelName();
|
|
347
|
+
if (modelName && notCommon.getApp()) {
|
|
348
|
+
return notCommon.getApp().getInterfaceManifest(modelName);
|
|
349
|
+
}
|
|
350
|
+
if (this.getOptions("manifest", undefined)) {
|
|
351
|
+
return this.getOptions("manifest", {});
|
|
352
|
+
} else {
|
|
353
|
+
this.#missingOverrideWarning("manifest");
|
|
354
|
+
return {};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
getFormData() {
|
|
359
|
+
if (this.getData()) {
|
|
360
|
+
return this.getData();
|
|
361
|
+
} else {
|
|
362
|
+
this.#missingOverrideWarning("data");
|
|
363
|
+
return {};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
getFormOptions() {
|
|
368
|
+
if (
|
|
369
|
+
this.getOptions("ui", undefined) ||
|
|
370
|
+
this.getOptions("fields", undefined)
|
|
371
|
+
) {
|
|
372
|
+
return {
|
|
373
|
+
ui: this.getOptions("ui", {}),
|
|
374
|
+
fields: this.getOptions("fields", {}),
|
|
375
|
+
};
|
|
376
|
+
} else {
|
|
377
|
+
this.#missingOverrideWarning("options");
|
|
378
|
+
return {
|
|
379
|
+
ui: {},
|
|
380
|
+
fields: {},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
getFormInjectedProps() {
|
|
386
|
+
return this.getOptions("injected", {});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Override empty message
|
|
391
|
+
**/
|
|
392
|
+
#missingOverrideWarning(missing) {
|
|
393
|
+
this.error(
|
|
394
|
+
`${missing} for ${this.getWorking("name")} form is not defined`
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Form operations
|
|
400
|
+
**/
|
|
401
|
+
collectData() {
|
|
402
|
+
if (this.getOptions("readonly", false)) {
|
|
403
|
+
return this.getData();
|
|
404
|
+
}
|
|
405
|
+
const data = this.#form.collectData();
|
|
406
|
+
this.setData({ ...data }); //update in inner store
|
|
407
|
+
return data;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
updateField(fieldName, props) {
|
|
411
|
+
this.#form.updateField(fieldName, props);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
getModel(name, data) {
|
|
415
|
+
if (typeof name === "string") {
|
|
416
|
+
return this.getInterface(name)(data || {});
|
|
417
|
+
} else {
|
|
418
|
+
return this.getInterface()(name || {});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
getInterface(name = false) {
|
|
423
|
+
return notCommon.getApp().getInterface(name || this.getModelName());
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Returns current model name
|
|
428
|
+
* @return {string}
|
|
429
|
+
*/
|
|
430
|
+
getModelName() {
|
|
431
|
+
return this.getOptions("model");
|
|
432
|
+
}
|
|
422
433
|
}
|
|
423
434
|
|
|
424
435
|
export default notForm;
|