vgapp 0.3.0 → 0.3.2
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/app/modules/vgformsender/js/vgformsender.js +31 -13
- package/build/vgapp.css +5107 -13
- package/build/vgapp.js +5172 -3
- package/build/vgapp.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,15 @@ import BaseModule from "../../base-module";
|
|
|
2
2
|
import {Manipulator} from "../../../utils/js/dom/manipulator";
|
|
3
3
|
import EventHandler from "../../../utils/js/dom/event";
|
|
4
4
|
import VGModal from "../../vgmodal/js/vgmodal";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
execute,
|
|
7
|
+
isObject,
|
|
8
|
+
isVisible,
|
|
9
|
+
makeRandomString,
|
|
10
|
+
mergeDeepObject,
|
|
11
|
+
noop,
|
|
12
|
+
normalizeData
|
|
13
|
+
} from "../../../utils/js/functions";
|
|
6
14
|
import Selectors from "../../../utils/js/dom/selectors";
|
|
7
15
|
import VGCollapse from "../../vgcollapse/js/vgcollapse";
|
|
8
16
|
import {getSVG} from "../../module-fn";
|
|
@@ -28,7 +36,10 @@ class VGFormSender extends BaseModule {
|
|
|
28
36
|
super(element, params);
|
|
29
37
|
|
|
30
38
|
this._params = this._getParams(element, mergeDeepObject({
|
|
31
|
-
redirect:
|
|
39
|
+
redirect: {
|
|
40
|
+
error: '',
|
|
41
|
+
success: ''
|
|
42
|
+
},
|
|
32
43
|
validate: false,
|
|
33
44
|
submit: false,
|
|
34
45
|
fields: [],
|
|
@@ -41,7 +52,8 @@ class VGFormSender extends BaseModule {
|
|
|
41
52
|
},
|
|
42
53
|
alert: {
|
|
43
54
|
enabled: true,
|
|
44
|
-
type: 'modal'
|
|
55
|
+
type: 'modal',
|
|
56
|
+
errors: true,
|
|
45
57
|
},
|
|
46
58
|
ajax: {
|
|
47
59
|
route: '',
|
|
@@ -82,7 +94,9 @@ class VGFormSender extends BaseModule {
|
|
|
82
94
|
this._element.classList.add(this._params.classes.general);
|
|
83
95
|
|
|
84
96
|
[... Selectors.findAll('input, textarea, select', this._element)].forEach((el) => {
|
|
85
|
-
el
|
|
97
|
+
if (isVisible(el)) {
|
|
98
|
+
el.parentElement.classList.add(this._params.classes.content)
|
|
99
|
+
}
|
|
86
100
|
});
|
|
87
101
|
|
|
88
102
|
if (this._params.validate) {
|
|
@@ -113,15 +127,19 @@ class VGFormSender extends BaseModule {
|
|
|
113
127
|
|
|
114
128
|
if (_this._params.alert.enabled) {
|
|
115
129
|
if (typeof status === 'string' && status === 'error') {
|
|
116
|
-
_this.
|
|
130
|
+
if (_this._params.redirect.error) {
|
|
131
|
+
window.location.href = _this._params.redirect.error;
|
|
132
|
+
} else {
|
|
133
|
+
_this._alertError(event, data);
|
|
134
|
+
}
|
|
117
135
|
} else if (typeof status === 'string' && status === 'success') {
|
|
118
|
-
_this.
|
|
136
|
+
if (_this._params.redirect.success) {
|
|
137
|
+
window.location.href = _this._params.redirect.success;
|
|
138
|
+
} else {
|
|
139
|
+
_this._alertSuccess(event, data);
|
|
140
|
+
}
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
|
-
|
|
122
|
-
if (_this._params.redirect) {
|
|
123
|
-
window.location.href = _this._params.redirect;
|
|
124
|
-
}
|
|
125
143
|
});
|
|
126
144
|
}
|
|
127
145
|
|
|
@@ -367,17 +385,17 @@ class VGFormSender extends BaseModule {
|
|
|
367
385
|
if (typeof response !== 'string') {
|
|
368
386
|
if (!('view' in response)) {
|
|
369
387
|
if ('title' in response) title = response.title;
|
|
370
|
-
if (status === 'error' && data.code !== 200) {
|
|
388
|
+
if (status === 'error' && data.code !== 200 && this._params.alert.errors) {
|
|
371
389
|
code = ' ' + data.text + ' (' + data.code + ')';
|
|
372
390
|
}
|
|
373
391
|
|
|
374
|
-
txt += '<h4 class="vg-alert-content--title">' + title + code + '</h4>';
|
|
392
|
+
if (title) txt += '<h4 class="vg-alert-content--title">' + title + code + '</h4>';
|
|
375
393
|
|
|
376
394
|
if ('message' in response) {
|
|
377
395
|
txt += '<div class="vg-alert-content--message">' + response.message + '</div>'
|
|
378
396
|
}
|
|
379
397
|
|
|
380
|
-
if ('errors' in response) {
|
|
398
|
+
if ('errors' in response && this._params.alert.errors) {
|
|
381
399
|
let errors = normalizeData(response.errors) || null;
|
|
382
400
|
if (isObject(errors)) {
|
|
383
401
|
for (const error in errors) {
|