From 136745d2334936ab5fb96573a01b826a1c72d442 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Wed, 4 Dec 2019 11:34:15 +0100
Subject: [PATCH] FEAT #11691 TIME 0:20 add alert modal if toggle new version

---
 .../attachments-page/attachment-page.component.html       | 2 +-
 .../attachments-page/attachment-page.component.ts         | 8 ++++++++
 src/frontend/lang/lang-en.ts                              | 3 +++
 src/frontend/lang/lang-fr.ts                              | 3 +++
 src/frontend/lang/lang-nl.ts                              | 3 +++
 src/frontend/plugins/modal/alert.component.html           | 2 +-
 src/frontend/plugins/modal/alert.component.scss           | 5 +++++
 src/frontend/plugins/modal/confirm.component.scss         | 5 +++++
 8 files changed, 29 insertions(+), 2 deletions(-)

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 e33e62e51cc..88ba0e8c4b8 100644
--- a/src/frontend/app/attachments/attachments-page/attachment-page.component.html
+++ b/src/frontend/app/attachments/attachments-page/attachment-page.component.html
@@ -22,7 +22,7 @@
                     <div class="attachment-form">
                         <div class="attachment-form-item">
                             <mat-slide-toggle [checked]="newVersion" color="primary"
-                                (change)="newVersion = !newVersion">Nouvelle version</mat-slide-toggle>
+                                (change)="toggleNewVersion()">{{lang.newVersion}}</mat-slide-toggle>
                         </div>
                         <div class="attachment-form-item">
                             <mat-form-field class="input-form">
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 0cdcabaa14e..6bfaf3077da 100644
--- a/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
+++ b/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
@@ -12,6 +12,7 @@ import { DocumentViewerComponent } from '../../viewer/document-viewer.component'
 import { PrivilegeService } from '../../../service/privileges.service';
 import { HeaderService } from '../../../service/header.service';
 import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
+import { AlertComponent } from '../../../plugins/modal/alert.component';
 
 @Component({
     selector: 'app-attachment-page',
@@ -242,4 +243,11 @@ export class AttachmentPageComponent implements OnInit {
             })
         ).subscribe();
     }
+
+    toggleNewVersion() {
+        if(!this.newVersion) {
+            this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.information, msg: this.lang.mustEditDocument } });
+        }
+        this.newVersion = !this.newVersion;
+    }
 }
\ No newline at end of file
diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts
index ec54f1c92db..f12632f9dc7 100755
--- a/src/frontend/lang/lang-en.ts
+++ b/src/frontend/lang/lang-en.ts
@@ -1321,4 +1321,7 @@ export const LANG_EN = {
     "saveModifiedData": "Do you want to save modified data ?",
     "dataUpdated": "Data updated",
     "canUpdateData": "Can update resource data",
+    "newVersion": "New version",
+    "information": "Information",
+    "mustEditDocument": "You must <b>edit</b> document in order to <b>validate</b> modifications.",
 };
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index ae1919328a7..b0787000726 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1359,4 +1359,7 @@ export const LANG_FR = {
     "saveModifiedData": "Voulez-vous sauvegarder les modifications ?",
     "dataUpdated": "Données modifiées",
     "canUpdateData": "Pouvoir modifier les métadonnées du courrier",
+    "newVersion": "Nouvelle version",
+    "information": "Information",
+    "mustEditDocument": "Vous devez <b>éditer</b> votre document afin de pouvoir <b>valider</b> vos modifications.",
 };
diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts
index 4469262e452..782183d71f7 100755
--- a/src/frontend/lang/lang-nl.ts
+++ b/src/frontend/lang/lang-nl.ts
@@ -1346,4 +1346,7 @@ export const LANG_NL = {
     "saveModifiedData": "Do you want to save modified data ?", //_TO_TRANSLATE
     "dataUpdated": "Data updated", //_TO_TRANSLATE
     "canUpdateData": "Can update resource data", //_TO_TRANSLATE
+    "newVersion": "New version", //_TO_TRANSLATE
+    "information": "Information", //_TO_TRANSLATE
+    "mustEditDocument": "You must <b>edit</b> document in order to <b>validate</b> modifications.", //_TO_TRANSLATE
 };
diff --git a/src/frontend/plugins/modal/alert.component.html b/src/frontend/plugins/modal/alert.component.html
index 4f29c15a947..2b50daa8a31 100644
--- a/src/frontend/plugins/modal/alert.component.html
+++ b/src/frontend/plugins/modal/alert.component.html
@@ -1,5 +1,5 @@
 <div class="modalContent">
-  <h1 mat-dialog-title>{{data.title}}</h1>
+  <h1 *ngIf="data.title !== ''" mat-dialog-title>{{data.title}}</h1>
   <div *ngIf="data.msg !== ''" mat-dialog-content>
     <div class="alert-message alert-message-info" [innerHTML]="data.msg"></div>
   </div>
diff --git a/src/frontend/plugins/modal/alert.component.scss b/src/frontend/plugins/modal/alert.component.scss
index 2f3fb890a9e..68fead1106a 100644
--- a/src/frontend/plugins/modal/alert.component.scss
+++ b/src/frontend/plugins/modal/alert.component.scss
@@ -28,4 +28,9 @@
     height: 40px;
     font-size: 20px;
     color: #666;
+}
+
+.alert-message-info {
+    margin: 0;
+    font-size: 16px;
 }
\ No newline at end of file
diff --git a/src/frontend/plugins/modal/confirm.component.scss b/src/frontend/plugins/modal/confirm.component.scss
index e73e3726d5a..5cf6cc4ccf3 100644
--- a/src/frontend/plugins/modal/confirm.component.scss
+++ b/src/frontend/plugins/modal/confirm.component.scss
@@ -29,4 +29,9 @@
     height: 40px;
     font-size: 20px;
     color: #666;
+}
+
+.alert-message-info {
+    margin: 0;
+    font-size: 16px;
 }
\ No newline at end of file
-- 
GitLab