vue-laravel-crud 1.3.15 → 1.3.17

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.
@@ -100,6 +100,10 @@ export default /*#__PURE__*/ {
100
100
  type: String,
101
101
  default: "",
102
102
  },
103
+ hideModalAfterSave: {
104
+ type: Boolean,
105
+ default: true,
106
+ },
103
107
  refreshAfterSave: {
104
108
  type: Boolean,
105
109
  default: true,
@@ -448,6 +452,7 @@ export default /*#__PURE__*/ {
448
452
  },
449
453
 
450
454
  refresh() {
455
+ this.$emit("refresh", {});
451
456
  this.fetchItems();
452
457
  },
453
458
  isColumnHasFilter(column) {
@@ -462,7 +467,7 @@ export default /*#__PURE__*/ {
462
467
  }, 1);
463
468
  },
464
469
  fetchItems(page = 1) {
465
- let _this = this;
470
+
466
471
  this.loading = true;
467
472
  axios
468
473
  .get(this.apiUrl + "/" + this.modelName, {
@@ -508,6 +513,7 @@ export default /*#__PURE__*/ {
508
513
  }
509
514
 
510
515
  this.loading = false;
516
+ this.$emit("afterFetch", {});
511
517
  })
512
518
  .catch((error) => {
513
519
  //console.debug(error);
@@ -517,64 +523,59 @@ export default /*#__PURE__*/ {
517
523
  },
518
524
 
519
525
  removeItem: function (id, index) {
520
- let _this = this;
521
-
522
526
  this.$bvModal
523
- .msgBoxConfirm(_this.messageRemoveConfirm, {
527
+ .msgBoxConfirm(this.messageRemoveConfirm, {
524
528
  size: "sm",
525
529
  buttonSize: "sm",
526
530
  okVariant: "danger",
527
- okTitle: _this.messageRemove,
531
+ okTitle: this.messageRemove,
528
532
  cancelTitle: "NO",
529
533
  centered: true,
530
534
  })
531
535
  .then((value) => {
532
536
  if (value) {
533
- _this.loading = true;
537
+ this.loading = true;
534
538
  axios
535
- .delete(_this.apiUrl + "/" + _this.modelName + "/" + id)
536
- .then(function (response) {
537
- _this.items.splice(index, 1);
538
- _this.toastSuccess("Elemento eliminado.");
539
- _this.loading = false;
539
+ .delete(this.apiUrl + "/" + this.modelName + "/" + id)
540
+ .then( (response) => {
541
+ this.items.splice(index, 1);
542
+ this.toastSuccess("Elemento eliminado.");
543
+ this.loading = false;
540
544
  })
541
- .catch(function (error) {
542
- _this.toastError(error);
543
- _this.loading = false;
545
+ .catch( (error) => {
546
+ this.toastError(error);
547
+ this.loading = false;
544
548
  });
545
549
  }
546
550
  })
547
551
  .catch((error) => {
548
- _this.toastError(error);
549
- _this.loading = false;
552
+ this.toastError(error);
553
+ this.loading = false;
550
554
  });
551
555
  },
552
556
 
553
557
  saveSort() {
554
558
  if (this.orderable) {
555
- let _this = this;
556
- _this.loading = true;
557
-
559
+ this.loading = true;
558
560
  let order = [];
559
-
560
561
  this.items.forEach((v, k) => {
561
562
  order.push({ id: v.id, order: v[this.orderProp] });
562
563
  });
563
564
 
564
565
  axios
565
- .post(this.apiUrl + "/" + _this.modelName + "/sort", {
566
+ .post(this.apiUrl + "/" + this.modelName + "/sort", {
566
567
  order: order,
567
568
  })
568
- .then(function (response) {
569
+ .then( (response) => {
569
570
  let data = response.data;
570
- _this.toastSuccess("Orden Actualizado");
571
- if (_this.refreshAfterSave) _this.refresh();
572
- _this.loading = false;
571
+ this.toastSuccess("Orden Actualizado");
572
+ if (this.refreshAfterSave) this.refresh();
573
+ this.loading = false;
573
574
  })
574
- .catch(function (error) {
575
+ .catch( (error) => {
575
576
  //console.debug(error);
576
- _this.toastError(error);
577
- _this.loading = false;
577
+ this.toastError(error);
578
+ this.loading = false;
578
579
  });
579
580
  }
580
581
  },
@@ -616,8 +617,7 @@ export default /*#__PURE__*/ {
616
617
  return ops.join(", ");
617
618
  },
618
619
  async saveItem(event = null) {
619
- let _this = this;
620
- _this.loading = true;
620
+ this.loading = true;
621
621
 
622
622
  if (this.validate) {
623
623
  let validation_result = true;
@@ -634,90 +634,95 @@ export default /*#__PURE__*/ {
634
634
  if (this.item.id) {
635
635
  axios
636
636
  .put(
637
- this.apiUrl + "/" + _this.modelName + "/" + _this.item.id,
638
- _this.item
637
+ this.apiUrl + "/" + this.modelName + "/" + this.item.id,
638
+ this.item
639
639
  )
640
- .then(function (response) {
641
- _this.$bvModal.hide("modal-form-item-" + _this.modelName);
640
+ .then((response) => {
641
+ if(this.hideModalAfterSave){
642
+ this.$bvModal.hide("modal-form-item-" + this.modelName);
643
+ }
644
+
642
645
  let itemSv = response.data;
643
- let itemIndex = _this.items.findIndex(
644
- (item) => item.id == _this.item.id
646
+ let itemIndex = this.items.findIndex(
647
+ (item) => item.id == this.item.id
645
648
  );
646
- _this.items[itemIndex] = itemSv;
647
- _this.item = itemSv;
648
- _this.loading = false;
649
- if (_this.refreshAfterSave) _this.refresh();
650
- _this.toastSuccess("Elemento Modificado");
649
+ this.items[itemIndex] = itemSv;
650
+ this.item = itemSv;
651
+ this.loading = false;
652
+ if (this.refreshAfterSave) this.refresh();
653
+ this.toastSuccess("Elemento Modificado");
651
654
  })
652
- .catch(function (error) {
653
- _this.toastError(error);
654
- _this.loading = false;
655
+ .catch((error) => {
656
+ this.toastError(error);
657
+ this.loading = false;
655
658
  });
656
659
  } else {
657
660
  if (this.createMultipart) {
658
661
  const formData = new FormData();
659
662
 
660
- Object.keys(_this.item).forEach((key) => {
661
- if (_this.item[key][0] && _this.item[key][0].name) {
662
- console.log(_this.item[key]);
663
-
664
- let files = _this.item[key];
663
+ Object.keys(this.item).forEach((key) => {
664
+ if (this.item[key][0] && this.item[key][0].name) {
665
+ let files = this.item[key];
665
666
  for (var x = 0; x < files.length; x++) {
666
667
  formData.append(
667
668
  key + "[]",
668
- _this.item[key][x],
669
- _this.item[key][x].name
669
+ this.item[key][x],
670
+ this.item[key][x].name
670
671
  );
671
672
  }
672
- } else formData.append(key, _this.item[key]);
673
+ } else formData.append(key, this.item[key]);
673
674
  });
674
675
 
675
676
  axios
676
- .post(this.apiUrl + "/" + _this.modelName, formData)
677
- .then(function (response) {
678
- _this.loading = false;
679
- _this.$bvModal.hide("modal-form-item-" + _this.modelName);
677
+ .post(this.apiUrl + "/" + this.modelName, formData)
678
+ .then( (response) => {
679
+ this.loading = false;
680
+ if(this.hideModalAfterSave){
681
+ this.$bvModal.hide("modal-form-item-" + this.modelName);
682
+ }
680
683
  if (response.data.success) {
681
684
  if (response.data.message) {
682
- _this.toastSuccess(response.data.message);
685
+ this.toastSuccess(response.data.message);
683
686
  }
684
687
  return;
685
688
  }
686
689
 
687
690
  let itemSv = response.data;
688
691
 
689
- _this.items.push(itemSv);
690
- _this.item = itemSv;
691
- if (_this.refreshAfterSave) _this.refresh();
692
- _this.toastSuccess("Elemento Creado");
692
+ this.items.push(itemSv);
693
+ this.item = itemSv;
694
+ if (this.refreshAfterSave) this.refresh();
695
+ this.toastSuccess("Elemento Creado");
693
696
  })
694
- .catch(function (error) {
695
- _this.toastError(error);
696
- _this.loading = false;
697
+ .catch( (error) => {
698
+ this.toastError(error);
699
+ this.loading = false;
697
700
  });
698
701
  } else {
699
702
  axios
700
- .post(this.apiUrl + "/" + _this.modelName, _this.item)
701
- .then(function (response) {
702
- _this.loading = false;
703
- _this.$bvModal.hide("modal-form-item-" + _this.modelName);
703
+ .post(this.apiUrl + "/" + this.modelName, this.item)
704
+ .then( (response) => {
705
+ this.loading = false;
706
+ if(this.hideModalAfterSave){
707
+ this.$bvModal.hide("modal-form-item-" + this.modelName);
708
+ }
704
709
  if (response.data.success) {
705
710
  if (response.data.message) {
706
- _this.toastSuccess(response.data.message);
711
+ this.toastSuccess(response.data.message);
707
712
  }
708
713
  return;
709
714
  }
710
715
 
711
716
  let itemSv = response.data;
712
717
 
713
- _this.items.push(itemSv);
714
- _this.item = itemSv;
715
- if (_this.refreshAfterSave) _this.refresh();
716
- _this.toastSuccess("Elemento Creado");
718
+ this.items.push(itemSv);
719
+ this.item = itemSv;
720
+ if (this.refreshAfterSave) this.refresh();
721
+ this.toastSuccess("Elemento Creado");
717
722
  })
718
- .catch(function (error) {
719
- _this.toastError(error);
720
- _this.loading = false;
723
+ .catch( (error) => {
724
+ this.toastError(error);
725
+ this.loading = false;
721
726
  });
722
727
  }
723
728
  }