From faa02525dffc57f7e688d293dc4dd9df780bde2c Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Tue, 10 Nov 2020 15:55:20 +0100
Subject: [PATCH] FEAT #15341 TIME 0:15 hide modal option

---
 .../list/import/contact-import.component.ts   |   3 +-
 .../user/import/users-import.component.ts     |   3 +-
 .../registered-mail-import.component.ts       |   3 +-
 .../app/viewer/document-viewer.component.ts   | 104 ++++++++++--------
 .../plugins/modal/confirm.component.html      |   1 +
 .../plugins/modal/confirm.component.ts        |  24 +++-
 src/lang/lang-en.json                         |   3 +-
 src/lang/lang-fr.json                         |   3 +-
 src/lang/lang-nl.json                         |   3 +-
 9 files changed, 94 insertions(+), 53 deletions(-)

diff --git a/src/frontend/app/administration/contact/list/import/contact-import.component.ts b/src/frontend/app/administration/contact/list/import/contact-import.component.ts
index 074fcaeae58..608cc9a335d 100644
--- a/src/frontend/app/administration/contact/list/import/contact-import.component.ts
+++ b/src/frontend/app/administration/contact/list/import/contact-import.component.ts
@@ -286,13 +286,14 @@ export class ContactImportComponent implements OnInit {
     }
 
     onSubmit() {
+        let dialogRef: any = null;
         const dataToSend: any[] = [];
         let confirmText = '';
         this.translate.get('lang.confirmImportContacts', { 0: this.countAll }).subscribe((res: string) => {
             confirmText = `${res} ?<br/><br/>`;
             confirmText += `<ul><li><b>${this.countAdd}</b> ${this.translate.instant('lang.additions')}</li><li><b>${this.countUp}</b> ${this.translate.instant('lang.modifications')}</li></ul>`;
         });
-        let dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.import'), msg: confirmText } });
+        dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.import'), msg: confirmText } });
         dialogRef.afterClosed().pipe(
             filter((data: string) => data === 'ok'),
             tap(() => {
diff --git a/src/frontend/app/administration/user/import/users-import.component.ts b/src/frontend/app/administration/user/import/users-import.component.ts
index 61cfeb49cb3..4f9c53287c2 100644
--- a/src/frontend/app/administration/user/import/users-import.component.ts
+++ b/src/frontend/app/administration/user/import/users-import.component.ts
@@ -186,13 +186,14 @@ export class UsersImportComponent implements OnInit {
     }
 
     onSubmit() {
+        let dialogRef: any = null;
         const dataToSend: any[] = [];
         let confirmText = '';
         this.translate.get('lang.confirmImportUsers', { 0: this.countAll }).subscribe((res: string) => {
             confirmText = `${res} ?<br/><br/>`;
             confirmText += `<ul><li><b>${this.countAdd}</b> ${this.translate.instant('lang.additions')}</li><li><b>${this.countUp}</b> ${this.translate.instant('lang.modifications')}</li></ul>`;
         });
-        let dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.import'), msg: confirmText } });
+        dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.import'), msg: confirmText } });
         dialogRef.afterClosed().pipe(
             filter((data: string) => data === 'ok'),
             tap(() => {
diff --git a/src/frontend/app/registeredMail/import/registered-mail-import.component.ts b/src/frontend/app/registeredMail/import/registered-mail-import.component.ts
index 2483113993a..e4d3be86dd4 100644
--- a/src/frontend/app/registeredMail/import/registered-mail-import.component.ts
+++ b/src/frontend/app/registeredMail/import/registered-mail-import.component.ts
@@ -404,12 +404,13 @@ export class RegisteredMailImportComponent implements OnInit {
     }
 
     onSubmit() {
+        let dialogRef: any = null;
         const dataToSend: any[] = [];
         let confirmText = '';
         this.translate.get('lang.confirmImportRegisteredMails', { 0: this.countAll }).subscribe((res: string) => {
             confirmText = `${res} ?<br/><br/>`;
         });
-        let dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.import'), msg: confirmText } });
+        dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.import'), msg: confirmText } });
         dialogRef.afterClosed().pipe(
             filter((data: string) => data === 'ok'),
             tap(() => {
diff --git a/src/frontend/app/viewer/document-viewer.component.ts b/src/frontend/app/viewer/document-viewer.component.ts
index 17d254ab886..a2a213dac5f 100755
--- a/src/frontend/app/viewer/document-viewer.component.ts
+++ b/src/frontend/app/viewer/document-viewer.component.ts
@@ -19,6 +19,7 @@ import { VisaWorkflowModalComponent } from '../visa/modal/visa-workflow-modal.co
 import { of } from 'rxjs';
 import { CollaboraOnlineViewerComponent } from '../../plugins/collabora-online/collabora-online-viewer.component';
 import { AuthService } from '@service/auth.service';
+import { LocalStorageService } from '@service/local-storage.service';
 
 @Component({
     selector: 'app-document-viewer',
@@ -151,7 +152,8 @@ export class DocumentViewerComponent implements OnInit, OnDestroy {
         private sortPipe: SortPipe,
         public functions: FunctionsService,
         public privilegeService: PrivilegeService,
-        private authService: AuthService
+        private authService: AuthService,
+        private localStorage: LocalStorageService
     ) {
         (<any>window).pdfWorkerSrc = '../node_modules/pdfjs-dist/build/pdf.worker.min.js';
     }
@@ -709,13 +711,21 @@ export class DocumentViewerComponent implements OnInit, OnDestroy {
     }
 
     editTemplate(templateId: number) {
+        if (this.localStorage.get(`modal_confirmEditTemplate_${this.headerService.user.id}`) !== null) {
+            this.launchEditTemplate(templateId);
+        } else {
+            this.confirmEditTemplate(templateId);
+        }
+    }
+
+    confirmEditTemplate(templateId: number) {
         let confirmMsg = '';
         if (this.mode === 'attachment') {
             confirmMsg = this.translate.instant('lang.editionAttachmentConfirmFirst') + '<br><br>' + this.translate.instant('lang.editionAttachmentConfirmThird');
         } else {
             confirmMsg = this.translate.instant('lang.editionAttachmentConfirmFirst') + '<br><br>' + this.translate.instant('lang.editionAttachmentConfirmSecond');
         }
-        this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.templateEdition'), msg: confirmMsg } });
+        this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { idModal: 'confirmEditTemplate', title: this.translate.instant('lang.templateEdition'), msg: confirmMsg } });
 
         this.dialogRef.afterClosed().pipe(
             tap((data: string) => {
@@ -725,50 +735,7 @@ export class DocumentViewerComponent implements OnInit, OnDestroy {
             }),
             filter((data: string) => data === 'ok'),
             tap(() => {
-
-                this.triggerEvent.emit();
-                const template = this.listTemplates.filter(templateItem => templateItem.id === templateId)[0];
-
-                this.file.format = template.extension;
-
-                if (this.editor.mode === 'onlyoffice') {
-
-                    this.editor.async = false;
-                    this.editor.options = {
-                        objectType: 'attachmentCreation',
-                        objectId: template.id,
-                        docUrl: `rest/onlyOffice/mergedFile`,
-                        dataToMerge: this.resourceDatas
-                    };
-                    this.editInProgress = true;
-
-                } else if (this.editor.mode === 'collaboraOnline') {
-                    this.editor.async = false;
-                    this.editInProgress = true;
-                    this.editor.options = {
-                        objectType: this.mode === 'attachment' ? 'attachmentCreation' : 'resourceCreation',
-                        objectId: template.id,
-                        dataToMerge: this.resourceDatas
-                    };
-                } else {
-                    this.editor.async = true;
-                    this.editor.options = {
-                        objectType: 'attachmentCreation',
-                        objectId: template.id,
-                        cookie: document.cookie,
-                        authToken : this.authService.getToken(),
-                        data: this.resourceDatas,
-                    };
-                    this.editInProgress = true;
-
-                    this.http.post('../rest/jnlp', this.editor.options).pipe(
-                        tap((data: any) => {
-                            window.location.href = '../rest/jnlp/' + data.generatedJnlp;
-                            this.checkLockFile(data.jnlpUniqueId, template.extension);
-                        })
-                    ).subscribe();
-                }
-
+                this.launchEditTemplate(templateId);
             }),
             catchError((err: any) => {
                 this.notify.handleErrors(err);
@@ -777,6 +744,51 @@ export class DocumentViewerComponent implements OnInit, OnDestroy {
         ).subscribe();
     }
 
+    launchEditTemplate(templateId: number) {
+        this.triggerEvent.emit();
+        const template = this.listTemplates.filter(templateItem => templateItem.id === templateId)[0];
+
+        this.file.format = template.extension;
+
+        if (this.editor.mode === 'onlyoffice') {
+
+            this.editor.async = false;
+            this.editor.options = {
+                objectType: 'attachmentCreation',
+                objectId: template.id,
+                docUrl: `rest/onlyOffice/mergedFile`,
+                dataToMerge: this.resourceDatas
+            };
+            this.editInProgress = true;
+
+        } else if (this.editor.mode === 'collaboraOnline') {
+            this.editor.async = false;
+            this.editInProgress = true;
+            this.editor.options = {
+                objectType: this.mode === 'attachment' ? 'attachmentCreation' : 'resourceCreation',
+                objectId: template.id,
+                dataToMerge: this.resourceDatas
+            };
+        } else {
+            this.editor.async = true;
+            this.editor.options = {
+                objectType: 'attachmentCreation',
+                objectId: template.id,
+                cookie: document.cookie,
+                authToken : this.authService.getToken(),
+                data: this.resourceDatas,
+            };
+            this.editInProgress = true;
+
+            this.http.post('../rest/jnlp', this.editor.options).pipe(
+                tap((data: any) => {
+                    window.location.href = '../rest/jnlp/' + data.generatedJnlp;
+                    this.checkLockFile(data.jnlpUniqueId, template.extension);
+                })
+            ).subscribe();
+        }
+    }
+
     editResource() {
         if (this.mode === 'attachment') {
             this.editAttachment();
diff --git a/src/frontend/plugins/modal/confirm.component.html b/src/frontend/plugins/modal/confirm.component.html
index 0be2d5ae211..b0fb9d585e6 100644
--- a/src/frontend/plugins/modal/confirm.component.html
+++ b/src/frontend/plugins/modal/confirm.component.html
@@ -2,6 +2,7 @@
   <h1 mat-dialog-title>{{data.title}}</h1>
   <div *ngIf="data.msg !== ''" mat-dialog-content>
     <div class="alert-message alert-message-info" [innerHTML]="data.msg"></div>
+    <mat-checkbox color="primary" *ngIf="idModal !== null" (change)="hideModal()">{{'lang.hideModal' | translate}}</mat-checkbox>
   </div>
   <span class="divider-modal"></span>
   <div mat-dialog-actions>
diff --git a/src/frontend/plugins/modal/confirm.component.ts b/src/frontend/plugins/modal/confirm.component.ts
index c811582ba7a..bd7c4d301e5 100755
--- a/src/frontend/plugins/modal/confirm.component.ts
+++ b/src/frontend/plugins/modal/confirm.component.ts
@@ -1,6 +1,8 @@
 import { Component, Inject } from '@angular/core';
 import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
 import { TranslateService } from '@ngx-translate/core';
+import { HeaderService } from '@service/header.service';
+import { LocalStorageService } from '@service/local-storage.service';
 
 @Component({
     templateUrl: 'confirm.component.html',
@@ -8,7 +10,19 @@ import { TranslateService } from '@ngx-translate/core';
 })
 export class ConfirmComponent {
 
-    constructor(public translate: TranslateService, @Inject(MAT_DIALOG_DATA) public data: any, public dialogRef: MatDialogRef<ConfirmComponent>) {
+    idModal: string = null;
+
+    constructor(
+       public translate: TranslateService,
+        @Inject(MAT_DIALOG_DATA) public data: any,
+        public dialogRef: MatDialogRef<ConfirmComponent>,
+        public headerService: HeaderService,
+        private localStorage: LocalStorageService
+    ) {
+        if (this.data.idModal !== undefined) {
+            this.idModal = this.data.idModal;
+        }
+
         if (this.data.msg === null) {
             this.data.msg = '';
         }
@@ -21,4 +35,12 @@ export class ConfirmComponent {
             this.data.buttonValidate = this.translate.instant('lang.ok');
         }
     }
+
+    hideModal() {
+        if (this.idModal !== '') {
+            this.localStorage.save(`modal_${this.idModal}_${this.headerService.user.id}`, true);
+        } else {
+            alert('No idModal provided!');
+        }
+    }
 }
diff --git a/src/lang/lang-en.json b/src/lang/lang-en.json
index 07deaddd1a4..25d24a220c7 100644
--- a/src/lang/lang-en.json
+++ b/src/lang/lang-en.json
@@ -2165,5 +2165,6 @@
     "noBindingMailDesc": "A non-binding document involves a specific final action defined in the settings administration and is no longer linked to the document type.",
     "registeredMailMsgActivate": "Activating this range will close the current range used for that type of recommended.",
     "redirectUserVisaWorkflow": "Change of approver / signatory for mails in the process of visa / signature",
-    "chooseNewVisaUser": "is in <b>visa / signature</b> of some mails, please choose a <b>user replacement</b>"
+    "chooseNewVisaUser": "is in <b>visa / signature</b> of some mails, please choose a <b>user replacement</b>",
+    "hideModal": "Hide this modal"
 }
\ No newline at end of file
diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json
index 63a3551b428..ddb2e3ca93a 100644
--- a/src/lang/lang-fr.json
+++ b/src/lang/lang-fr.json
@@ -2157,5 +2157,6 @@
     "infoImportNoIdToCreate": "La colonne <b>id</b> doit être vide pour la création",
     "almostThere": "Vous y êtes presque !",
     "redirectUserVisaWorkflow": "Changement de viseur / signataire pour les courriers en cours de visa / signature",
-    "chooseNewVisaUser": "est en <b>visa / signature</b> de certains courriers, veuillez choisir un utilisateur de <b>remplacement</b>"
+    "chooseNewVisaUser": "est en <b>visa / signature</b> de certains courriers, veuillez choisir un utilisateur de <b>remplacement</b>",
+    "hideModal": "Ne plus afficher cette fenêtre"
 }
diff --git a/src/lang/lang-nl.json b/src/lang/lang-nl.json
index 3a7bce4b45c..dd9ed11f085 100644
--- a/src/lang/lang-nl.json
+++ b/src/lang/lang-nl.json
@@ -2176,5 +2176,6 @@
     "bindingMailAlt": "Document <b>engageant</b>__TO_TRANSLATE",
     "noBindingMailAlt": "Document <b>non engageant</b>__TO_TRANSLATE",
     "redirectUserVisaWorkflow": "Changement de viseur / signataire pour les courriers en cours de visa / signature__TO_TRANSLATE",
-    "chooseNewVisaUser": "est en <b>visa / signature</b> de certains courriers, veuillez choisir un utilisateur de <b>remplacement</b>__TO_TRANSLATE"
+    "chooseNewVisaUser": "est en <b>visa / signature</b> de certains courriers, veuillez choisir un utilisateur de <b>remplacement</b>__TO_TRANSLATE",
+    "hideModal": "Ne plus afficher cette fenêtre__TO_TRANSLATE"
 }
\ No newline at end of file
-- 
GitLab