From fd16bc8b48766098637a9dd8b5180921ca5d8718 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Wed, 27 Nov 2019 14:49:24 +0100
Subject: [PATCH] FEAT #11691 TIME 0:10 add confirm if remove attachment

---
 .../attachment-create.component.ts            | 25 +++++++++++++++----
 src/frontend/lang/lang-fr.ts                  |  2 +-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/frontend/app/attachments/attachment-create/attachment-create.component.ts b/src/frontend/app/attachments/attachment-create/attachment-create.component.ts
index 1ad365c164f..a17a101e883 100644
--- a/src/frontend/app/attachments/attachment-create/attachment-create.component.ts
+++ b/src/frontend/app/attachments/attachment-create/attachment-create.component.ts
@@ -1,7 +1,7 @@
 import { Component, OnInit, Input, EventEmitter, Output, Inject, ViewChildren, QueryList, ViewChild } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 import { LANG } from '../../translate.component';
-import { catchError, tap, finalize, exhaustMap } from 'rxjs/operators';
+import { catchError, tap, finalize, exhaustMap, filter } from 'rxjs/operators';
 import { of, forkJoin } from 'rxjs';
 import { NotificationService } from '../../notification.service';
 import { MatDialog, MAT_DIALOG_DATA, MatDialogRef, MatTabGroup } from '@angular/material';
@@ -9,6 +9,7 @@ import { AppService } from '../../../service/app.service';
 import { DocumentViewerComponent } from '../../viewer/document-viewer.component';
 import { SortPipe } from '../../../plugins/sorting.pipe';
 import { FormControl, FormGroup, Validators } from '@angular/forms';
+import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
 
 @Component({
     templateUrl: "attachment-create.component.html",
@@ -50,7 +51,8 @@ export class AttachmentCreateComponent implements OnInit {
         public dialogRef: MatDialogRef<AttachmentCreateComponent>,
         public appService: AppService,
         private notify: NotificationService,
-        private sortPipe: SortPipe) {
+        private sortPipe: SortPipe,
+        public dialog: MatDialog) {
     }
 
     ngOnInit(): void {
@@ -184,12 +186,25 @@ export class AttachmentCreateComponent implements OnInit {
         });
 
         this.attachFormGroup.push(new FormGroup(this.attachments[this.attachments.length - 1]));
+        this.indexTab = this.attachments.length - 1;
     }
 
     removePj(i: number) {
-        this.indexTab = 0;
-        this.attachments.splice(i, 1);
-        this.attachFormGroup.splice(i, 1);
+        const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.delete+ ' : PJ n°'+ (i+1), msg: this.lang.confirmAction } });
+
+        dialogRef.afterClosed().pipe(
+            filter((data: string) => data === 'ok'),
+            tap(() => {
+                this.indexTab = 0;
+                this.attachments.splice(i, 1);
+                this.attachFormGroup.splice(i, 1);
+            }),
+            catchError((err: any) => {
+                this.notify.handleErrors(err);
+                return of(false);
+            })
+        ).subscribe();
+
     }
 
     getAttachType(attachType: any, i: number) {
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index 83016c7952a..b9f71e1f0bf 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1345,7 +1345,7 @@ export const LANG_FR = {
     "addAttachment": "Ajouter une pièce jointe",
     "dateAgo": "Il y a",
     "dateTo": "Le",
-    "attachmentCreation": "Creation d'une pièce jointe",
+    "attachmentCreation": "Création d'une pièce jointe",
     "newAttachment": "Nouvelle pièce jointe",
     "delAttachment": "Enlever la pièce jointe",
     "mustCompleteAllAttachments": "Veuillez compléter l'ensemble des pièces jointes",
-- 
GitLab