From fd20d01d24a0bbbb5b25bd95b3fcb394e50a1066 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 27 Nov 2020 16:23:08 +0100
Subject: [PATCH] FEAT #10118 TIME 0:30 add version enabled option + use in
 attachment page

---
 .../attachment-type-administration.component.html      |  2 +-
 .../attachment-type-administration.component.ts        | 10 ++++++++++
 .../attachments-page/attachment-page.component.html    |  2 +-
 .../attachments-page/attachment-page.component.ts      |  6 ++++++
 src/lang/lang-fr.json                                  |  6 ++++--
 5 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/frontend/app/administration/attachment/attachment-type-administration.component.html b/src/frontend/app/administration/attachment/attachment-type-administration.component.html
index bf710cb64ea..b7096dedcf5 100644
--- a/src/frontend/app/administration/attachment/attachment-type-administration.component.html
+++ b/src/frontend/app/administration/attachment/attachment-type-administration.component.html
@@ -38,7 +38,7 @@
                                 <mat-list-item>
                                     <div mat-line style="display: flex;">
                                         <mat-slide-toggle [formControlName]="idOpt" [name]="idOpt"
-                                            color="primary" [checked]="attachmentType[idOpt].value">
+                                            color="primary" [checked]="attachmentType[idOpt].value" [disabled]="!isValidToggle(idOpt)">
                                             {{'lang.' + idOpt + '_attachment' | translate}}</mat-slide-toggle>
                                         &nbsp;
                                         <i class="fa fa-question-circle" color="primary" style="cursor: help;"
diff --git a/src/frontend/app/administration/attachment/attachment-type-administration.component.ts b/src/frontend/app/administration/attachment/attachment-type-administration.component.ts
index 4cb49c7763d..5294123895c 100644
--- a/src/frontend/app/administration/attachment/attachment-type-administration.component.ts
+++ b/src/frontend/app/administration/attachment/attachment-type-administration.component.ts
@@ -28,6 +28,7 @@ export class AttachmentTypeAdministrationComponent implements OnInit {
         emailLink: new FormControl({ value: false, disabled: false }),
         signable: new FormControl({ value: false, disabled: false }),
         icon: new FormControl({ value: '', disabled: false }),
+        versionEnabled: new FormControl({ value: false, disabled: false }),
         newVersionDefault: new FormControl({ value: false, disabled: false }),
     };
 
@@ -125,4 +126,13 @@ export class AttachmentTypeAdministrationComponent implements OnInit {
             })
         ).subscribe();
     }
+
+    isValidToggle(id: string) {
+        if (id === 'newVersionDefault' && !this.attachmentType['versionEnabled'].value) {
+            this.attachmentType['newVersionDefault'].setValue(false);
+            return false;
+        } else {
+            return true;
+        }
+    }
 }
diff --git a/src/frontend/app/attachments/attachments-page/attachment-page.component.html b/src/frontend/app/attachments/attachments-page/attachment-page.component.html
index 1639fb0ca36..fa6559f70db 100755
--- a/src/frontend/app/attachments/attachments-page/attachment-page.component.html
+++ b/src/frontend/app/attachments/attachments-page/attachment-page.component.html
@@ -15,7 +15,7 @@
     <mat-dialog-content class="attach-content">
             <ng-container *ngIf="!loading">
                     <div class="attachment-form col-md-3 col-sm-12">
-                        <div *ngIf="editMode" class="attachment-form-item">
+                        <div *ngIf="editMode && isVersionEnabled()" class="attachment-form-item">
                             <mat-slide-toggle [checked]="newVersion" color="primary"
                                 (change)="newVersion = !newVersion;">{{'lang.newVersion' | translate}}</mat-slide-toggle>
                         </div>
diff --git a/src/frontend/app/attachments/attachments-page/attachment-page.component.ts b/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
index 95c7d4c356e..33310ec108e 100644
--- a/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
+++ b/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
@@ -141,6 +141,8 @@ export class AttachmentPageComponent implements OnInit {
 
                     this.versions = data.versions;
 
+                    this.newVersion = this.attachmentsTypes.filter((item: any) => item.typeId === data.type)[0].newVersionDefault;
+
                     this.attachFormGroup = new FormGroup(this.attachment);
                     resolve(true);
                 }),
@@ -153,6 +155,10 @@ export class AttachmentPageComponent implements OnInit {
         });
     }
 
+    isVersionEnabled() {
+        return this.attachmentsTypes.filter((item: any) => item.typeId === this.attachment.type.value)[0].versionEnabled;
+    }
+
     createNewVersion(mode: string = 'default') {
         this.sendingData = true;
         this.appAttachmentViewer.getFile().pipe(
diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json
index b61b9c0ec97..b2868d85cff 100644
--- a/src/lang/lang-fr.json
+++ b/src/lang/lang-fr.json
@@ -2172,8 +2172,10 @@
     "emailLink_attachmentDesc": "Les pièces jointes de ce type seront sélectionnées par défaut lors de l'envoi d'un courriel",
     "signable_attachment": "Autoriser la signature",
     "signable_attachmentDesc": "Possibilité d'apposer une griffe sur les pièces jointes de ce type dans le parapheur",
-    "newVersionDefault_attachment": "'Nouvelle version' activé par défaut",
-    "newVersionDefault_attachmentDesc": "Lors de la modification d'une pièce jointe, 'Nouvelle version' sera activé par défaut",
+    "newVersionDefault_attachment": "«Nouvelle version» activé par défaut",
+    "newVersionDefault_attachmentDesc": "Lors de la modification d'une pièce jointe, «Nouvelle version» sera activé par défaut",
+    "versionEnabled_attachment": "Création de nouvelles versions",
+    "versionEnabled_attachmentDesc": "Lors de la modification d'une pièce jointe, «Nouvelle version» pourra être choisi",
     "attachmentTypeCreation": "Création d'un type de pièce jointe",
     "attachmentTypeAdded": "Type de pièce jointe ajouté",
     "attachmentTypeUpdated": "Type de pièce jointe modifié",
-- 
GitLab