From cc666d882004b7b2f0894e899b5a16b1099f09eb Mon Sep 17 00:00:00 2001
From: Jean-Laurent <jean-laurent.duzant@xelians.fr>
Date: Tue, 2 Aug 2022 11:30:43 +0200
Subject: [PATCH] FIX #20391 TIME 0:15 fix DLT enable false in admin && true
 when not in admin

---
 .../indexing-form/indexing-form.component.html   |  2 +-
 .../indexing-form/indexing-form.component.ts     | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.html b/src/frontend/app/indexation/indexing-form/indexing-form.component.html
index 4481cfc8bdc..90991b1994d 100644
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.html
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.html
@@ -113,7 +113,7 @@
                                         <mat-icon color="primary" class="fas fa-database">
                                         </mat-icon>
                                     </button>
-                                    <button mat-button color="primary" *ngIf="adminMode && !field.SQLMode && field.enabled" matPrefix
+                                    <button mat-button color="primary" *ngIf="adminMode && !field.SQLMode && !arrFormControl[field.identifier].disabled" matPrefix
                                         mat-icon-button (click)="$event.stopPropagation();toggleTodayDate(field);"
                                         [matTooltip]="'lang.todayDate' | translate"
                                         style="position: absolute;left: -40px;">
diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
index 66a33eab2b3..aa68419b94c 100755
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
@@ -15,6 +15,7 @@ import { FunctionsService } from '@service/functions.service';
 import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
 import { IssuingSiteInputComponent } from '../../administration/registered-mail/issuing-site/indexing/issuing-site-input.component';
 import { RegisteredMailRecipientInputComponent } from '../../administration/registered-mail/indexing/recipient-input.component';
+import { ConstantPool } from '@angular/compiler';
 
 @Component({
     selector: 'app-indexing-form',
@@ -462,6 +463,9 @@ export class IndexingFormComponent implements OnInit {
                 this.mustFixErrors = false;
                 const formatdatas = this.formatDatas(this.getDatas());
 
+                console.log('JL saveDatas - ', formatdatas);
+                return;
+
                 this.http.put(`../rest/resources/${this.resId}`, formatdatas).pipe(
                     tap(() => {
                         if (this.currentCategory === 'registeredMail') {
@@ -1040,8 +1044,12 @@ export class IndexingFormComponent implements OnInit {
                 }
 
                 await this.initElemForm(saveResourceState).then(() => {
-                    if (!this.adminMode && !this.functions.empty(this.arrFormControl['processLimitDate']) && this.arrFormControl['processLimitDate'].disabled) {
+                    if (!this.adminMode && !this.functions.empty(this.arrFormControl['processLimitDate'])) {
                         this.arrFormControl['processLimitDate'].enable();
+                        this.indexingModelClone.fields.find((field: any) => field.identifier === 'processLimitDate').enabled = true;
+                    } else if (this.adminMode && !this.functions.empty(this.arrFormControl['processLimitDate'])) {
+                        this.arrFormControl['processLimitDate'].disable();
+                        this.indexingModelClone.fields.find((field: any) => field.identifier === 'processLimitDate').enabled = false;
                     }
                 });
                 this.createForm();
@@ -1081,7 +1089,7 @@ export class IndexingFormComponent implements OnInit {
         const valArr: ValidatorFn[] = [];
 
         const disabledState = !field.enabled || this.isAlwaysDisabledField(field);
-        if (!disabledState) {
+        if (!disabledState && field.identifier !== 'processLimitDate') {
             field.enabled = true;
         }
 
@@ -1241,7 +1249,7 @@ export class IndexingFormComponent implements OnInit {
         if (this.functions.empty(this.arrFormControl['priority']?.value)) {
             delete objToSend.priority;
         }
-        if (this.arrFormControl['processLimitDate'] !== undefined) {
+        if (!this.adminMode && this.arrFormControl['processLimitDate'] !== undefined) {
             this.http.get('../rest/indexing/processLimitDate', { params: objToSend }).pipe(
                 tap((data: any) => {
                     limitDate = data.processLimitDate !== null ? new Date(data.processLimitDate) : '';
@@ -1276,7 +1284,7 @@ export class IndexingFormComponent implements OnInit {
         if (this.functions.empty(this.arrFormControl['doctype']?.value)) {
             delete objToSend.doctype;
         }
-        if (this.arrFormControl['processLimitDate'] !== undefined) {
+        if (!this.adminMode && this.arrFormControl['processLimitDate'] !== undefined) {
             this.http.get('../rest/indexing/processLimitDate', { params: objToSend }).pipe(
                 tap((data: any) => {
                     limitDate = data.processLimitDate !== null ? new Date(data.processLimitDate) : '';
-- 
GitLab