vgapp 1.0.5 → 1.0.6

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.
@@ -52,10 +52,10 @@ class VGFiles extends VGFilesBase {
52
52
  retryAttempts: 1,
53
53
  retryDelay: 1000,
54
54
  },
55
- removes: {
56
- all: { route: '', alert: true, toast: true, confirm: null },
57
- single: { route: '', alert: true, toast: true, confirm: null }
58
- },
55
+ removes: {
56
+ all: { route: '', alert: true, toast: true, confirm: null },
57
+ single: { route: '', alert: true, toast: true, confirm: null }
58
+ },
59
59
  sortable: {
60
60
  enabled: false,
61
61
  route: '',
@@ -525,8 +525,8 @@ class VGFiles extends VGFilesBase {
525
525
  });
526
526
  }
527
527
 
528
- reload(button) {
529
- if (!this._params.ajax || !this._params.uploads.route) return;
528
+ reload(button) {
529
+ if (!this._params.ajax || !this._params.uploads.route) return;
530
530
 
531
531
  const dataButton = Manipulator.get(button, 'data');
532
532
  const fileData = {
@@ -556,85 +556,85 @@ class VGFiles extends VGFilesBase {
556
556
  this._triggerCallback('onReload', payload);
557
557
  this._triggerEvent('reload', payload);
558
558
 
559
- this.upload(fileToRetry);
560
- }
561
-
562
- _runAjaxRequest(paramsAjax, callback) {
563
- const previousAjax = this._params.ajax;
564
- this._params.ajax = paramsAjax;
565
-
566
- this._route((status, data) => {
567
- this._params.ajax = previousAjax;
568
- callback(status, data);
569
- });
570
- }
571
-
572
- _normalizeConfirmResult(result) {
573
- if (result === true) return { accepted: true, data: null };
574
- if (result === false || result == null) return { accepted: false, data: null };
575
-
576
- if (typeof result === 'object') {
577
- if (typeof result.accepted === 'boolean') {
578
- return { accepted: result.accepted, data: result.data ?? null };
579
- }
580
- if (Object.prototype.hasOwnProperty.call(result, 'data')) {
581
- return { accepted: true, data: result.data ?? null };
582
- }
583
- }
584
-
585
- return { accepted: Boolean(result), data: null };
586
- }
587
-
588
- _runDefaultRemoveConfirm(trigger, params) {
589
- return new Promise((resolve) => {
590
- VGAlert.confirm(trigger, {
591
- lang: params.lang,
592
- ajax: params.ajax,
593
- buttons: params.buttons,
594
- message: params.message
595
- });
596
-
597
- EventHandler.one(trigger, 'vg.alert.accept', (event) => {
598
- resolve({ accepted: true, data: event?.vgalert?.data ?? null });
599
- });
600
-
601
- EventHandler.one(trigger, 'vg.alert.reject', () => {
602
- resolve({ accepted: false, data: null });
603
- });
604
- });
605
- }
606
-
607
- _confirmRemove(type, trigger, ajax, message) {
608
- const buttons = {
609
- agree: {
610
- text: lang_buttons(this._params.lang, NAME)['agree'],
611
- class: ["btn-danger"],
612
- },
613
- cancel: {
614
- text: lang_buttons(this._params.lang, NAME)['cancel'],
615
- class: ["btn-outline-danger"],
616
- },
617
- };
618
-
619
- const confirmParams = {
620
- type,
621
- trigger,
622
- lang: this._params.lang,
623
- ajax,
624
- buttons,
625
- message
626
- };
627
-
628
- const customConfirm = this._params?.removes?.[type]?.confirm;
629
- if (typeof customConfirm === 'function') {
630
- return Promise.resolve(customConfirm(confirmParams, this))
631
- .then((result) => this._normalizeConfirmResult(result));
632
- }
633
-
634
- return this._runDefaultRemoveConfirm(trigger, confirmParams);
635
- }
636
-
637
- removeFile(button) {
559
+ this.upload(fileToRetry);
560
+ }
561
+
562
+ _runAjaxRequest(paramsAjax, callback) {
563
+ const previousAjax = this._params.ajax;
564
+ this._params.ajax = paramsAjax;
565
+
566
+ this._route((status, data) => {
567
+ this._params.ajax = previousAjax;
568
+ callback(status, data);
569
+ });
570
+ }
571
+
572
+ _normalizeConfirmResult(result) {
573
+ if (result === true) return { accepted: true, data: null };
574
+ if (result === false || result == null) return { accepted: false, data: null };
575
+
576
+ if (typeof result === 'object') {
577
+ if (typeof result.accepted === 'boolean') {
578
+ return { accepted: result.accepted, data: result.data ?? null };
579
+ }
580
+ if (Object.prototype.hasOwnProperty.call(result, 'data')) {
581
+ return { accepted: true, data: result.data ?? null };
582
+ }
583
+ }
584
+
585
+ return { accepted: Boolean(result), data: null };
586
+ }
587
+
588
+ _runDefaultRemoveConfirm(trigger, params) {
589
+ return new Promise((resolve) => {
590
+ VGAlert.confirm(trigger, {
591
+ lang: params.lang,
592
+ ajax: params.ajax,
593
+ buttons: params.buttons,
594
+ message: params.message
595
+ });
596
+
597
+ EventHandler.one(trigger, 'vg.alert.accept', (event) => {
598
+ resolve({ accepted: true, data: event?.vgalert?.data ?? null });
599
+ });
600
+
601
+ EventHandler.one(trigger, 'vg.alert.reject', () => {
602
+ resolve({ accepted: false, data: null });
603
+ });
604
+ });
605
+ }
606
+
607
+ _confirmRemove(type, trigger, ajax, message) {
608
+ const buttons = {
609
+ agree: {
610
+ text: lang_buttons(this._params.lang, NAME)['agree'],
611
+ class: ["btn-danger"],
612
+ },
613
+ cancel: {
614
+ text: lang_buttons(this._params.lang, NAME)['cancel'],
615
+ class: ["btn-outline-danger"],
616
+ },
617
+ };
618
+
619
+ const confirmParams = {
620
+ type,
621
+ trigger,
622
+ lang: this._params.lang,
623
+ ajax,
624
+ buttons,
625
+ message
626
+ };
627
+
628
+ const customConfirm = this._params?.removes?.[type]?.confirm;
629
+ if (typeof customConfirm === 'function') {
630
+ return Promise.resolve(customConfirm(confirmParams, this))
631
+ .then((result) => this._normalizeConfirmResult(result));
632
+ }
633
+
634
+ return this._runDefaultRemoveConfirm(trigger, confirmParams);
635
+ }
636
+
637
+ removeFile(button) {
638
638
  const name = normalizeData(Manipulator.get(button, 'data-name'));
639
639
  const size = normalizeData(Manipulator.get(button, 'data-size'));
640
640
  const id = normalizeData(Manipulator.get(button, 'data-id'));
@@ -668,9 +668,9 @@ class VGFiles extends VGFilesBase {
668
668
  if (this._params.ajax && this._params.removes.single.route) {
669
669
  if (!id) return;
670
670
 
671
- const routeBase = this._params.removes.single.route;
672
- const routeSeparator = routeBase.includes('?') ? '&' : '?';
673
- const route = `${routeBase}${routeSeparator}id=${encodeURIComponent(id)}`;
671
+ const routeBase = this._params.removes.single.route;
672
+ const routeSeparator = routeBase.includes('?') ? '&' : '?';
673
+ const route = `${routeBase}${routeSeparator}id=${encodeURIComponent(id)}`;
674
674
  const paramsAjax = {
675
675
  route: route,
676
676
  method: 'delete'
@@ -691,31 +691,31 @@ class VGFiles extends VGFilesBase {
691
691
  }
692
692
  };
693
693
 
694
- if (this._params.removes.single.alert) {
695
- const message = {
696
- title: lang_messages(this._params.lang, NAME)['title'],
697
- description: lang_messages(this._params.lang, NAME)['description']
698
- };
699
-
700
- this._confirmRemove('single', button, paramsAjax, message)
701
- .then((result) => {
702
- if (!result.accepted) return;
703
-
704
- if (result.data) {
705
- _completeRemoveFile(result.data);
706
- return;
707
- }
708
-
709
- this._runAjaxRequest(paramsAjax, (status, data) => {
710
- _completeRemoveFile(data);
711
- });
712
- })
713
- .catch(() => {});
714
- } else {
715
- this._runAjaxRequest(paramsAjax, (status, data) => {
716
- _completeRemoveFile(data);
717
- });
718
- }
694
+ if (this._params.removes.single.alert) {
695
+ const message = {
696
+ title: lang_messages(this._params.lang, NAME)['title'],
697
+ description: lang_messages(this._params.lang, NAME)['description']
698
+ };
699
+
700
+ this._confirmRemove('single', button, paramsAjax, message)
701
+ .then((result) => {
702
+ if (!result.accepted) return;
703
+
704
+ if (result.data) {
705
+ _completeRemoveFile(result.data);
706
+ return;
707
+ }
708
+
709
+ this._runAjaxRequest(paramsAjax, (status, data) => {
710
+ _completeRemoveFile(data);
711
+ });
712
+ })
713
+ .catch(() => {});
714
+ } else {
715
+ this._runAjaxRequest(paramsAjax, (status, data) => {
716
+ _completeRemoveFile(data);
717
+ });
718
+ }
719
719
  } else {
720
720
  this._files = this._files.filter(f => !(f.name === name && f.size === size));
721
721
  this._updateStatsAfterRemove();
@@ -885,7 +885,14 @@ class VGFiles extends VGFilesBase {
885
885
  this._sortable = null;
886
886
 
887
887
  this.clear();
888
- if (this._uploader) this._uploader.destroy();
888
+ if (this._uploader) {
889
+ if (typeof this._uploader.destroy === 'function') {
890
+ this._uploader.destroy();
891
+ } else {
892
+ if (typeof this._uploader.clear === 'function') this._uploader.clear();
893
+ if (typeof this._uploader.offAll === 'function') this._uploader.offAll();
894
+ }
895
+ }
889
896
  super.dispose();
890
897
  }
891
898
  }
@@ -932,37 +939,37 @@ EventHandler.on(document, `click.${NAME_KEY}.data.api`, SELECTOR_DATA_DISMISS_AL
932
939
  instance.clear(true, true);
933
940
  };
934
941
 
935
- if (instance._params.removes.all.alert) {
936
- const message = {
937
- title: lang_messages(instance._params.lang, NAME)['title'],
938
- description: lang_messages(instance._params.lang, NAME)['descriptions']
939
- };
940
-
941
- instance._confirmRemove('all', e.target, paramsAjax, message)
942
- .then((result) => {
943
- if (!result.accepted) return;
944
-
945
- if (result.data) {
946
- if (instance._params.removes.all.toast) {
947
- VGToast.run(result.data?.response?.message);
948
- }
949
- _completeClearAll();
950
- return;
951
- }
952
-
953
- instance._runAjaxRequest(paramsAjax, (status, data) => {
954
- if (instance._params.removes.all.toast && data?.response?.message) {
955
- VGToast.run(data.response.message);
956
- }
957
- _completeClearAll();
958
- });
959
- })
960
- .catch(() => {});
961
- } else {
962
- instance._runAjaxRequest(paramsAjax, (status, data) => {
963
- if (instance._params.removes.all.toast && data?.response?.message) {
964
- VGToast.run(data.response.message);
965
- }
942
+ if (instance._params.removes.all.alert) {
943
+ const message = {
944
+ title: lang_messages(instance._params.lang, NAME)['title'],
945
+ description: lang_messages(instance._params.lang, NAME)['descriptions']
946
+ };
947
+
948
+ instance._confirmRemove('all', e.target, paramsAjax, message)
949
+ .then((result) => {
950
+ if (!result.accepted) return;
951
+
952
+ if (result.data) {
953
+ if (instance._params.removes.all.toast) {
954
+ VGToast.run(result.data?.response?.message);
955
+ }
956
+ _completeClearAll();
957
+ return;
958
+ }
959
+
960
+ instance._runAjaxRequest(paramsAjax, (status, data) => {
961
+ if (instance._params.removes.all.toast && data?.response?.message) {
962
+ VGToast.run(data.response.message);
963
+ }
964
+ _completeClearAll();
965
+ });
966
+ })
967
+ .catch(() => {});
968
+ } else {
969
+ instance._runAjaxRequest(paramsAjax, (status, data) => {
970
+ if (instance._params.removes.all.toast && data?.response?.message) {
971
+ VGToast.run(data.response.message);
972
+ }
966
973
  _completeClearAll();
967
974
  });
968
975
  }
@@ -351,6 +351,7 @@ class VGModal extends BaseModule {
351
351
  for (const elm of elements) {
352
352
  switch (elm.tagName) {
353
353
  case 'INPUT': elm.value = item.value; break;
354
+ case 'FORM': elm.action = item.value; break;
354
355
  case 'IMG': Manipulator.set(elm, 'src', item.value); break;
355
356
  default: elm.innerHTML = item.value;
356
357
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vgapp",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "author": {
6
6
  "name": "Vegas Studio",