From 5bf8ceb1c9da467d0272df4c6666e505897e702d Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Wed, 13 Jun 2018 16:23:06 +0000
Subject: [PATCH] FEAT #7737 front admin templates

---
 .../Views/template-administration.component.html      | 11 ++++++-----
 .../template-administration.component.ts              |  8 +++++++-
 apps/maarch_entreprise/js/angular/lang/lang-en.ts     |  5 +++--
 apps/maarch_entreprise/js/angular/lang/lang-fr.ts     |  5 +++--
 4 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/apps/maarch_entreprise/Views/template-administration.component.html b/apps/maarch_entreprise/Views/template-administration.component.html
index 762527d1502..8e815488d63 100755
--- a/apps/maarch_entreprise/Views/template-administration.component.html
+++ b/apps/maarch_entreprise/Views/template-administration.component.html
@@ -37,7 +37,7 @@
                             <div class="col-sm-12">
                                 <mat-form-field>
                                     <textarea matInput [(ngModel)]="template.template_comment" required name="template_comment" id="template_comment" placeholder="{{lang.description}}"
-                                        title="{{lang.description}}" matTextareaAutosize matAutosizeMinRows="3"
+                                        title="{{lang.description}}" matTextareaAutosize matAutosizeMinRows="2"
                                         matAutosizeMaxRows="5">
                                     </textarea>
                                 </mat-form-field>
@@ -46,7 +46,7 @@
                         <div class="form-group">
                             <div class="col-sm-12">
                                 <mat-form-field>
-                                    <mat-select id="template_target" name="template_target" title="{{lang.templateTarget}}" placeholder="{{lang.templateTarget}}" [(ngModel)]="template.template_target" (ngModelChange)="updateTemplateType()">
+                                    <mat-select [disabled]="!creationMode" id="template_target" name="template_target" title="{{lang.templateTarget}}" placeholder="{{lang.templateTarget}}" [(ngModel)]="template.template_target" (ngModelChange)="updateTemplateType()">
                                         <mat-option value="">{{lang.noTarget}}</mat-option>
                                         <mat-option value="attachments">{{lang.attachments}}</mat-option>
                                         <mat-option value="notifications">{{lang.notifications}}</mat-option>
@@ -71,7 +71,7 @@
                         </div>
                         <div class="form-group" [hidden]="template.template_target=='attachments' || template.template_target=='notifications' || template.template_target=='doctypes' || template.template_target=='notes'">
                             <div class="col-sm-12">
-                                <mat-radio-group required name="template_type" [(ngModel)]="template.template_type">
+                                <mat-radio-group [disabled]="!creationMode" required name="template_type" [(ngModel)]="template.template_type">
                                     <mat-radio-button style="margin-left:10px" color="primary" name="template_type" value="OFFICE" [checked]="template.template_type=='OFFICE'" *ngIf="template.template_target=='attachments' || template.template_target==''">{{lang.office}}</mat-radio-button>
                                     <mat-radio-button style="margin-left:10px" color="primary" name="template_type" value="HTML" [checked]="template.template_type=='HTML'" *ngIf="template.template_target=='sendmail' || template.template_target=='doctypes' || template.template_target == 'notifications' || template.template_target == ''" (click)="initMce()">{{lang.html}}</mat-radio-button>
                                     <mat-radio-button style="margin-left:10px" color="primary" name="template_type" value="TXT" [checked]="template.template_type=='TXT'" *ngIf="template.template_target=='sendmail' || template.template_target=='notes' || template.template_target == ''">{{lang.txt}}</mat-radio-button>
@@ -82,7 +82,8 @@
                             <div class="col-sm-5" style="overflow:hidden">
                                 <div class="form-group">
                                     <div class="col-sm-12" style="text-align:center;">
-                                        <button mat-raised-button color="primary" type="button" (click)="clickOnUploader('uploadSignFile')"><i class="fa fa-paperclip fa-2x"></i> {{lang.chooseFile}}</button>
+                                        <button mat-raised-button color="primary" type="button" (click)="clickOnUploader('uploadSignFile')"><i class="fa fa-paperclip fa-2x"></i> {{lang.importFile}}</button>
+                                        <div *ngIf="template.uploadedFile"><h5>Fichier importé</h5></div>
                                     </div>
                                 </div>
                                 <div class="col-md-12">
@@ -127,7 +128,7 @@
                                 </div>
                             </div>
                         </div>
-                        <div class="form-group">
+                        <div class="form-group" *ngIf="template.template_target=='notifications'">
                             <div class="col-sm-12">
                                 <mat-form-field>
                                     <mat-select id="template_datasource" name="template_datasource" title="{{lang.templateDatasource}}" placeholder="{{lang.templateDatasource}}" [(ngModel)]="template.template_datasource">
diff --git a/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts b/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts
index fa84eb566a1..6848943ef9e 100755
--- a/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts
+++ b/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts
@@ -170,7 +170,6 @@ export class TemplateAdministrationComponent implements OnInit {
 
     resfreshUpload(b64Content: any) {
         this.template.uploadedFile.base64 = b64Content.replace(/^data:.*?;base64,/, "");
-        this.template.uploadedFile.base64ForJs = b64Content;
         this.template.template_style = null;
     }
 
@@ -217,6 +216,13 @@ export class TemplateAdministrationComponent implements OnInit {
 
     onSubmit() {
         this.template.entities = $j('#jstree').jstree(true).get_checked();
+        if(this.template.template_target!='notifications'){
+            this.template.template_datasource=='letterbox_attachment';
+        }
+        if(this.creationMode && this.template.template_style && !this.template.userUniqueId){
+            alert(this.lang.editModelFirst);
+            return;
+        }
         if (this.creationMode) {
             this.http.post(this.coreUrl + 'rest/templates', this.template)
                 .subscribe(() => {
diff --git a/apps/maarch_entreprise/js/angular/lang/lang-en.ts b/apps/maarch_entreprise/js/angular/lang/lang-en.ts
index e265da30770..17b5f1c0d21 100755
--- a/apps/maarch_entreprise/js/angular/lang/lang-en.ts
+++ b/apps/maarch_entreprise/js/angular/lang/lang-en.ts
@@ -544,7 +544,8 @@ export const LANG_EN = {
     "confirmDuplicate"                  : "Do you really want to duplicate this template ?",
     "noDatasource"                      : "No datasources",
     "templateDuplicated"                : "Template duplicated",
-    "chooseFile"                        : "Choose a file",
-    "allAttachments"                    : "All attachments"
+    "importFile"                        : "Import a file",
+    "allAttachments"                    : "All attachments",
+    "editModelFirst"                    : "Please edit model first"
 
 };
diff --git a/apps/maarch_entreprise/js/angular/lang/lang-fr.ts b/apps/maarch_entreprise/js/angular/lang/lang-fr.ts
index b54beede8d9..d34fbd96833 100755
--- a/apps/maarch_entreprise/js/angular/lang/lang-fr.ts
+++ b/apps/maarch_entreprise/js/angular/lang/lang-fr.ts
@@ -566,7 +566,8 @@ export const LANG_FR = {
     "confirmDuplicate"                  : "Voulez-vous vraiment dupliquer ce template ?",
     "noDatasource"                      : "Aucune source de données",
     "templateDuplicated"                : "Modèle dupliqué",
-    "chooseFile"                        : "Choisissez un fichier",
-    "allAttachments"                    : "Tous les attachements"
+    "importFile"                        : "Importer un fichier",
+    "allAttachments"                    : "Tous les attachements",
+    "editModelFirst"                    : "Veuillez éditer le modèle avant de valider"
     
 };
-- 
GitLab