vgapp 0.7.0 → 0.7.1
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.
|
@@ -16,6 +16,12 @@ import VGCollapse from "../../vgcollapse/js/vgcollapse";
|
|
|
16
16
|
import {getSVG} from "../../module-fn";
|
|
17
17
|
import VGHideShowPass from "./hideshowpass";
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* TODO
|
|
21
|
+
* доделай динамическое добавление полей в форму,
|
|
22
|
+
* но не меняй место их получения (их нужно получить прямо перед отправкой, после того как выполнился промис beforeSend)
|
|
23
|
+
*/
|
|
24
|
+
|
|
19
25
|
/**
|
|
20
26
|
* Constants
|
|
21
27
|
*/
|
|
@@ -82,6 +88,7 @@ class VGFormSender extends BaseModule {
|
|
|
82
88
|
afterError: noop,
|
|
83
89
|
},
|
|
84
90
|
interceptors: {
|
|
91
|
+
beforeSend: () => new Promise((resolve, reject) => resolve()),
|
|
85
92
|
success: false,
|
|
86
93
|
error: false
|
|
87
94
|
},
|
|
@@ -143,42 +150,49 @@ class VGFormSender extends BaseModule {
|
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
request(data, event) {
|
|
146
|
-
this
|
|
153
|
+
const _this = this;
|
|
147
154
|
|
|
148
|
-
|
|
155
|
+
_this._alertBefore();
|
|
149
156
|
|
|
150
|
-
|
|
151
|
-
|
|
157
|
+
const submit = () => {
|
|
158
|
+
_this._params.ajax.data = new FormData(_this._element);
|
|
159
|
+
_this._route(function (status, data) {
|
|
160
|
+
_this._element.classList.remove('was-validated');
|
|
152
161
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
162
|
+
if (_this._params.response.enabled) {
|
|
163
|
+
data.response = _this._params.response;
|
|
164
|
+
}
|
|
156
165
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} else {
|
|
162
|
-
if (!this._params.interceptors.error) {
|
|
163
|
-
this._alertError(event, data);
|
|
164
|
-
execute(this._params.callback.afterError, [this._element, this, event, data]);
|
|
166
|
+
if (_this._params.alert.enabled) {
|
|
167
|
+
if (typeof status === 'string' && status === 'error') {
|
|
168
|
+
if (_this._params.redirect.error) {
|
|
169
|
+
window.location.href = _this._params.redirect.error;
|
|
165
170
|
} else {
|
|
166
|
-
|
|
171
|
+
if (!_this._params.interceptors.error) {
|
|
172
|
+
_this._alertError(event, data);
|
|
173
|
+
execute(_this._params.callback.afterError, [_this._element, _this, event, data]);
|
|
174
|
+
} else {
|
|
175
|
+
execute(_this._params.callback.afterError, [_this._element, _this, event, data]);
|
|
176
|
+
}
|
|
167
177
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
window.location.href = this._params.redirect.success;
|
|
172
|
-
} else {
|
|
173
|
-
if (!this._params.interceptors.success) {
|
|
174
|
-
this._alertSuccess(event, data);
|
|
175
|
-
execute(this._params.callback.afterSuccess, [this._element, this, event, data]);
|
|
178
|
+
} else if (typeof status === 'string' && status === 'success') {
|
|
179
|
+
if (_this._params.redirect.success) {
|
|
180
|
+
window.location.href = _this._params.redirect.success;
|
|
176
181
|
} else {
|
|
177
|
-
|
|
182
|
+
if (!_this._params.interceptors.success) {
|
|
183
|
+
_this._alertSuccess(event, data);
|
|
184
|
+
execute(_this._params.callback.afterSuccess, [_this._element, _this, event, data]);
|
|
185
|
+
} else {
|
|
186
|
+
execute(_this._params.callback.afterSuccess, [_this._element, _this, event, data]);
|
|
187
|
+
}
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
|
-
}
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
_this._params.interceptors.beforeSend().then(() => {
|
|
195
|
+
submit();
|
|
182
196
|
});
|
|
183
197
|
}
|
|
184
198
|
|
|
@@ -515,7 +529,7 @@ EventHandler.on(document, EVENT_SUBMIT_DATA_API, function (event) {
|
|
|
515
529
|
}
|
|
516
530
|
}
|
|
517
531
|
|
|
518
|
-
const collectData = function(data, fields) {
|
|
532
|
+
/*const collectData = function(data, fields) {
|
|
519
533
|
for (let name in fields) {
|
|
520
534
|
if (typeof fields[name] === 'object') {
|
|
521
535
|
for (let key in fields[name]) {
|
|
@@ -530,19 +544,19 @@ EventHandler.on(document, EVENT_SUBMIT_DATA_API, function (event) {
|
|
|
530
544
|
}
|
|
531
545
|
|
|
532
546
|
return data;
|
|
533
|
-
}
|
|
547
|
+
}*/
|
|
534
548
|
|
|
535
549
|
if (!instance._params.submit) {
|
|
536
550
|
event.preventDefault();
|
|
537
551
|
|
|
538
|
-
let data = new FormData(instance._element);
|
|
552
|
+
//let data = new FormData(instance._element);
|
|
539
553
|
|
|
540
554
|
// TODO доделать
|
|
541
555
|
/*if (Array.isArray(instance._params.ajax.fields) && instance._params.ajax.fields.length) {
|
|
542
556
|
data = collectData(data, instance._params.ajax.fields);
|
|
543
557
|
}*/
|
|
544
558
|
|
|
545
|
-
return instance.request(
|
|
559
|
+
return instance.request(event);
|
|
546
560
|
}
|
|
547
561
|
})
|
|
548
562
|
|