@esfaenza/extensions 15.2.26 → 15.2.28

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.
@@ -626,19 +626,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
626
626
  * Service che fornisce funzionalità di alert nei tipi fondamentali: success, info, warning e danger
627
627
  */
628
628
  class MessageService {
629
- /**
630
- * Costruttore
631
- *
632
- * @ignore
633
- */
634
- constructor(injector, locProvider, emb, hash) {
629
+ /** Costruttore @ignore */
630
+ constructor(injector, locProvider, hash) {
635
631
  this.injector = injector;
636
632
  this.locProvider = locProvider;
637
- this.emb = emb;
638
633
  this.hash = hash;
639
- /**
640
- * Oggetto statico in supporto alla localizzazione
641
- */
634
+ /** Oggetto statico in supporto alla localizzazione */
642
635
  this.loc = {
643
636
  'Confirm': { 'en-US': "Confirm", 'it-IT': "Conferma", },
644
637
  'Cancel': { 'en-US': "Cancel", 'it-IT': "Annulla", },
@@ -648,12 +641,22 @@ class MessageService {
648
641
  'Success': { 'en-US': "Success", 'it-IT': "Successo", },
649
642
  'Warning': { 'en-US': "Warning", 'it-IT': "Attenzione", }
650
643
  };
644
+ /** Supporto all'Embedding */
645
+ this.Embedded = false;
646
+ this.MainWindow = null;
647
+ this.MessageObserver = null;
651
648
  this.GuidRepsonseFunctionsMap = {};
652
649
  this.init();
653
650
  }
651
+ /** Getter per il servizio dei toast. ngx-toastr è fatta talmente male che la service dev'essere recuperata in questo modo */
654
652
  get toastr() {
655
653
  return this.injector.get(ToastrService);
656
654
  }
655
+ configureEmbeddability(mainWindow, messageObserver) {
656
+ this.Embedded = true;
657
+ this.MainWindow = mainWindow;
658
+ this.MessageObserver = messageObserver;
659
+ }
657
660
  async init() {
658
661
  let LOCALE = this.locProvider ? await this.locProvider.Locale.pipe(first()).toPromise() : 'it-IT';
659
662
  this.expiredSessionSwal = swal.mixin({
@@ -755,8 +758,8 @@ class MessageService {
755
758
  * @param {"toastr" | "swal" | null} secondaryNotificationType Qualora sia una notifica secondaria, ne indica il tipo
756
759
  */
757
760
  simpleSuccess(text, secondaryNotificationType = null, secondaryNotificationTimeout = null) {
758
- if (this.emb.Embedded) {
759
- this.emb.MainWindow.postMessage({ type: "alert", level: 'success', msg: text }, "*");
761
+ if (this.Embedded) {
762
+ this.MainWindow.postMessage({ type: "alert", level: 'success', msg: text }, "*");
760
763
  return;
761
764
  }
762
765
  let tos = this.toastrOrSwal(secondaryNotificationType);
@@ -775,8 +778,8 @@ class MessageService {
775
778
  * @param {"toastr" | "swal" | null} secondaryNotificationType Qualora sia una notifica secondaria, ne indica il tipo
776
779
  */
777
780
  simpleInfo(text, secondaryNotificationType = null, secondaryNotificationTimeout = null) {
778
- if (this.emb.Embedded) {
779
- this.emb.MainWindow.postMessage({ type: "alert", level: 'info', msg: text }, "*");
781
+ if (this.Embedded) {
782
+ this.MainWindow.postMessage({ type: "alert", level: 'info', msg: text }, "*");
780
783
  return;
781
784
  }
782
785
  let tos = this.toastrOrSwal(secondaryNotificationType);
@@ -795,8 +798,8 @@ class MessageService {
795
798
  * @param {"toastr" | "swal" | null} secondaryNotificationType Qualora sia una notifica secondaria, ne indica il tipo
796
799
  */
797
800
  simpleError(text, secondaryNotificationType = null, secondaryNotificationTimeout = null) {
798
- if (this.emb.Embedded) {
799
- this.emb.MainWindow.postMessage({ type: "alert", level: 'error', msg: text }, "*");
801
+ if (this.Embedded) {
802
+ this.MainWindow.postMessage({ type: "alert", level: 'error', msg: text }, "*");
800
803
  return;
801
804
  }
802
805
  let tos = this.toastrOrSwal(secondaryNotificationType);
@@ -815,8 +818,8 @@ class MessageService {
815
818
  * @param {"toastr" | "swal" | null} secondaryNotificationType Qualora sia una notifica secondaria, ne indica il tipo
816
819
  */
817
820
  simpleWarning(text, secondaryNotificationType = null, secondaryNotificationTimeout = null) {
818
- if (this.emb.Embedded) {
819
- this.emb.MainWindow.postMessage({ type: "alert", level: 'warning', msg: text }, "*");
821
+ if (this.Embedded) {
822
+ this.MainWindow.postMessage({ type: "alert", level: 'warning', msg: text }, "*");
820
823
  return;
821
824
  }
822
825
  let tos = this.toastrOrSwal(secondaryNotificationType);
@@ -878,13 +881,13 @@ class MessageService {
878
881
  this.withChoiceBase("success", title, text, onsuccess, onerror);
879
882
  }
880
883
  withChoiceBase(level, title, text, onsuccess, onerror) {
881
- if (this.emb.Embedded) {
884
+ if (this.Embedded) {
882
885
  let guid = this.hash.getGUID();
883
886
  this.GuidRepsonseFunctionsMap[guid] = { onsuccess, onerror };
884
- this.emb.MainWindow.postMessage({ type: "confirm", level, title, text, guid }, "*");
887
+ this.MainWindow.postMessage({ type: "confirm", level, title, text, guid }, "*");
885
888
  // Observe sulla risposta
886
889
  console.log("Inviata confirm request alla pagina principale, in attesa di risposta...");
887
- this.emb.MessageObserver.pipe(filter(event => event?.data?.type == "confirm-response" && event?.data?.guid == guid), take(1)).subscribe(event => {
890
+ this.MessageObserver.pipe(filter(event => event?.data?.type == "confirm-response" && event?.data?.guid == guid), take(1)).subscribe(event => {
888
891
  console.log("Event listener su window-message. Risposta pergiunta");
889
892
  if (event?.data?.result === true)
890
893
  this.GuidRepsonseFunctionsMap[guid].onsuccess();
@@ -893,7 +896,7 @@ class MessageService {
893
896
  });
894
897
  }
895
898
  else
896
- (level == "warning" ? this._simpleWarningWithChoice : this._simpleSuccessWithChoice)(title, text, onsuccess, onerror);
899
+ (level == "warning" ? this._simpleWarningWithChoice.bind(this) : this._simpleSuccessWithChoice.bind(this))(title, text, onsuccess, onerror);
897
900
  }
898
901
  /**
899
902
  * Mostra un messaggio di success con richiesta di conferma e gestisce il risultato chiamato i callback **onconfirm** o **onabort**
@@ -1019,7 +1022,7 @@ class MessageService {
1019
1022
  }
1020
1023
  }
1021
1024
  }
1022
- MessageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MessageService, deps: [{ token: Injector }, { token: i1.BaseLocalization, optional: true }, { token: AppEmbeddingExtensions }, { token: HashingService }], target: i0.ɵɵFactoryTarget.Injectable });
1025
+ MessageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MessageService, deps: [{ token: Injector }, { token: i1.BaseLocalization, optional: true }, { token: HashingService }], target: i0.ɵɵFactoryTarget.Injectable });
1023
1026
  MessageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MessageService, providedIn: "root" });
1024
1027
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: MessageService, decorators: [{
1025
1028
  type: Injectable,
@@ -1029,7 +1032,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1029
1032
  args: [Injector]
1030
1033
  }] }, { type: i1.BaseLocalization, decorators: [{
1031
1034
  type: Optional
1032
- }] }, { type: AppEmbeddingExtensions }, { type: HashingService }]; } });
1035
+ }] }, { type: HashingService }]; } });
1033
1036
 
1034
1037
  // Angular
1035
1038
  /* Classe che contiene tutte le informazioni sull'embedding in un unico contenitore per semplicità */
@@ -1040,15 +1043,17 @@ class AppEmbeddingExtensions {
1040
1043
  this.Embedded = false;
1041
1044
  this.EmbeddingLevel = 0;
1042
1045
  this.MessageObserver = new Subject();
1043
- this.setupEmbeddability();
1044
1046
  this.MainWindow = window;
1045
1047
  while (this.MainWindow.parent != this.MainWindow) {
1046
1048
  this.MainWindow = this.MainWindow.parent;
1047
1049
  this.EmbeddingLevel++;
1048
1050
  this.Embedded = true;
1049
1051
  }
1052
+ this.configureEmbeddability();
1053
+ if (this.Embedded)
1054
+ this.msgService.configureEmbeddability(this.MainWindow, this.MessageObserver);
1050
1055
  }
1051
- setupEmbeddability() {
1056
+ configureEmbeddability() {
1052
1057
  window.onmessage = (event) => {
1053
1058
  // Ignoro i miei messaggi dato che mi interessano solo quelli degli altri iframe
1054
1059
  if (event.source == window && event?.data?.type != "modal-open")