vgapp 1.0.5 → 1.0.7

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,88 +556,100 @@ 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'));
641
+ const emitRemove = () => {
642
+ const payload = {
643
+ button: button,
644
+ name: name,
645
+ size: size,
646
+ id: id,
647
+ remaining: this._files.length
648
+ };
649
+
650
+ this._triggerCallback('onRemoveFile', payload);
651
+ this._triggerEvent('remove', payload);
652
+ };
641
653
 
642
654
  const fileToRemove = this._files.find(f => f.name === name && f.size === size);
643
655
  if (fileToRemove) {
@@ -668,9 +680,9 @@ class VGFiles extends VGFilesBase {
668
680
  if (this._params.ajax && this._params.removes.single.route) {
669
681
  if (!id) return;
670
682
 
671
- const routeBase = this._params.removes.single.route;
672
- const routeSeparator = routeBase.includes('?') ? '&' : '?';
673
- const route = `${routeBase}${routeSeparator}id=${encodeURIComponent(id)}`;
683
+ const routeBase = this._params.removes.single.route;
684
+ const routeSeparator = routeBase.includes('?') ? '&' : '?';
685
+ const route = `${routeBase}${routeSeparator}id=${encodeURIComponent(id)}`;
674
686
  const paramsAjax = {
675
687
  route: route,
676
688
  method: 'delete'
@@ -689,51 +701,43 @@ class VGFiles extends VGFilesBase {
689
701
  if (this._params.removes.single.toast) {
690
702
  VGToast.run(data?.response?.message);
691
703
  }
704
+
705
+ emitRemove();
692
706
  };
693
707
 
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
- }
708
+ if (this._params.removes.single.alert) {
709
+ const message = {
710
+ title: lang_messages(this._params.lang, NAME)['title'],
711
+ description: lang_messages(this._params.lang, NAME)['description']
712
+ };
713
+
714
+ this._confirmRemove('single', button, paramsAjax, message)
715
+ .then((result) => {
716
+ if (!result.accepted) return;
717
+
718
+ if (result.data) {
719
+ _completeRemoveFile(result.data);
720
+ return;
721
+ }
722
+
723
+ this._runAjaxRequest(paramsAjax, (status, data) => {
724
+ _completeRemoveFile(data);
725
+ });
726
+ })
727
+ .catch(() => {});
728
+ } else {
729
+ this._runAjaxRequest(paramsAjax, (status, data) => {
730
+ _completeRemoveFile(data);
731
+ });
732
+ }
719
733
  } else {
720
734
  this._files = this._files.filter(f => !(f.name === name && f.size === size));
721
735
  this._updateStatsAfterRemove();
722
736
  this._files.length ? this.build() : this.clear(true);
737
+ emitRemove();
723
738
  }
724
739
 
725
740
  this._resetFileInput();
726
-
727
- const payload = {
728
- button: button,
729
- name: name,
730
- size: size,
731
- id: id,
732
- remaining: this._files.length
733
- };
734
-
735
- this._triggerCallback('onRemoveFile', payload);
736
- this._triggerEvent('remove', payload);
737
741
  }
738
742
 
739
743
  _updateStatsAfterRemove() {
@@ -885,7 +889,14 @@ class VGFiles extends VGFilesBase {
885
889
  this._sortable = null;
886
890
 
887
891
  this.clear();
888
- if (this._uploader) this._uploader.destroy();
892
+ if (this._uploader) {
893
+ if (typeof this._uploader.destroy === 'function') {
894
+ this._uploader.destroy();
895
+ } else {
896
+ if (typeof this._uploader.clear === 'function') this._uploader.clear();
897
+ if (typeof this._uploader.offAll === 'function') this._uploader.offAll();
898
+ }
899
+ }
889
900
  super.dispose();
890
901
  }
891
902
  }
@@ -932,37 +943,37 @@ EventHandler.on(document, `click.${NAME_KEY}.data.api`, SELECTOR_DATA_DISMISS_AL
932
943
  instance.clear(true, true);
933
944
  };
934
945
 
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
- }
946
+ if (instance._params.removes.all.alert) {
947
+ const message = {
948
+ title: lang_messages(instance._params.lang, NAME)['title'],
949
+ description: lang_messages(instance._params.lang, NAME)['descriptions']
950
+ };
951
+
952
+ instance._confirmRemove('all', e.target, paramsAjax, message)
953
+ .then((result) => {
954
+ if (!result.accepted) return;
955
+
956
+ if (result.data) {
957
+ if (instance._params.removes.all.toast) {
958
+ VGToast.run(result.data?.response?.message);
959
+ }
960
+ _completeClearAll();
961
+ return;
962
+ }
963
+
964
+ instance._runAjaxRequest(paramsAjax, (status, data) => {
965
+ if (instance._params.removes.all.toast && data?.response?.message) {
966
+ VGToast.run(data.response.message);
967
+ }
968
+ _completeClearAll();
969
+ });
970
+ })
971
+ .catch(() => {});
972
+ } else {
973
+ instance._runAjaxRequest(paramsAjax, (status, data) => {
974
+ if (instance._params.removes.all.toast && data?.response?.message) {
975
+ VGToast.run(data.response.message);
976
+ }
966
977
  _completeClearAll();
967
978
  });
968
979
  }
@@ -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.7",
4
4
  "description": "",
5
5
  "author": {
6
6
  "name": "Vegas Studio",