From 3748d87335f2543484c2563b61d95423912233e3 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 4 Oct 2019 09:55:53 +0200
Subject: [PATCH] FEAT #11274 TIME 8 begin front diff list indexing

---
 src/frontend/app/app-common.module.ts         |   8 +-
 src/frontend/app/app.module.ts                |   2 -
 .../diffusions/diffusions-list.component.html |  57 +++-
 .../diffusions/diffusions-list.component.scss |  57 ++++
 .../diffusions/diffusions-list.component.ts   | 266 +++++++++++++++++-
 .../indexing-form.component.html              |  26 +-
 .../indexing-form/indexing-form.component.ts  |  35 ++-
 .../autocomplete/autocomplete.component.html  |   2 +-
 8 files changed, 435 insertions(+), 18 deletions(-)

diff --git a/src/frontend/app/app-common.module.ts b/src/frontend/app/app-common.module.ts
index e00d2a7cd24..c1972da8002 100755
--- a/src/frontend/app/app-common.module.ts
+++ b/src/frontend/app/app-common.module.ts
@@ -57,6 +57,8 @@ import { PluginSelectSearchComponent }                        from '../plugins/s
 import { FolderInputComponent }                        from '../app/folder/indexing/folder-input.component';
 import { TagInputComponent }                        from '../app/tag/indexing/tag-input.component';
 
+import { DiffusionsListComponent }             from './diffusions/diffusions-list.component';
+
 
 
 export class MyHammerConfig extends HammerGestureConfig {
@@ -104,7 +106,8 @@ export class MyHammerConfig extends HammerGestureConfig {
         FieldListComponent,
         PluginSelectSearchComponent,
         FolderInputComponent,
-        TagInputComponent
+        TagInputComponent,
+        DiffusionsListComponent
     ],
     exports: [
         CommonModule,
@@ -139,7 +142,8 @@ export class MyHammerConfig extends HammerGestureConfig {
         FieldListComponent,
         PluginSelectSearchComponent,
         FolderInputComponent,
-        TagInputComponent
+        TagInputComponent,
+        DiffusionsListComponent
     ],
     providers: [
         LatinisePipe,
diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts
index 0d2a578d2a5..e9c26438ac0 100755
--- a/src/frontend/app/app.module.ts
+++ b/src/frontend/app/app.module.ts
@@ -59,7 +59,6 @@ import { ExportComponent }                      from './list/export/export.compo
 import { NoteEditorComponent }                  from './notes/note-editor.component';
 import { NotesListComponent }                   from './notes/notes.component';
 import { AttachmentsListComponent }             from './attachments/attachments-list.component';
-import { DiffusionsListComponent }             from './diffusions/diffusions-list.component';
 import { VisaWorkflowComponent }             from './visa/visa-workflow.component';
 import { AvisWorkflowComponent }             from './avis/avis-workflow.component';
 
@@ -92,7 +91,6 @@ import { IndexationComponent }                        from './indexation/indexat
         NotesListComponent,
         NoteEditorComponent,
         AttachmentsListComponent,
-        DiffusionsListComponent,
         VisaWorkflowComponent,
         AvisWorkflowComponent,
         FiltersListComponent,
diff --git a/src/frontend/app/diffusions/diffusions-list.component.html b/src/frontend/app/diffusions/diffusions-list.component.html
index 89da05c2234..c9318aba1b0 100644
--- a/src/frontend/app/diffusions/diffusions-list.component.html
+++ b/src/frontend/app/diffusions/diffusions-list.component.html
@@ -1,12 +1,58 @@
+<ng-container *ngIf="!loading">
+    <plugin-autocomplete *ngIf="adminMode" [labelPlaceholder]="lang.addUserOrEntity"
+        [routeDatas]="['/rest/autocomplete/users','/rest/autocomplete/entities']" [targetSearchKey]="'idToDisplay'"
+        [subInfoKey]="'descriptionToDisplay'" (triggerEvent)="addElem($event)"></plugin-autocomplete>
+    <div *ngIf="isEmptyList() && !loading" style="text-align:center;font-size:24px;font-weight:bold;opacity:0.3;">
+        {{lang.noDiffusionList}}
+    </div>
+    <ng-container *ngFor="let role of availableRoles">
+        <mat-expansion-panel *ngIf="diffList[role.id].items.length > 0" class="diffusionList"
+            [expanded]="role.id === 'dest' || this.adminMode">
+            <mat-expansion-panel-header>
+                <mat-panel-title>
+                    {{role.label}} <ng-container *ngIf="role.id !== 'dest'">({{diffList[role.id].items.length}})
+                    </ng-container>
+                </mat-panel-title>
+            </mat-expansion-panel-header>
+            <mat-list>
+                <mat-list-item class="item-diffusion-list"
+                    *ngFor="let diffusion of diffList[role.id].items;let i=index">
+                    <mat-icon mat-list-icon color="primary" class="fa"
+                        [class.fa-user]="diffusion.item_type === 'user_id'"
+                        [class.fa-sitemap]="diffusion.item_type === 'entity_id'"></mat-icon>
+                    <div class="item-diffusion">
+                        <p mat-line>{{diffusion.labelToDisplay}}</p>
+                        <p mat-line class="subInfo">{{diffusion.descriptionToDisplay}}</p>
+                    </div>
+                    <div *ngIf="role.id !== 'dest' && adminMode && diffusion.item_type === 'user_id'">
+                        <button mat-button [matMenuTriggerFor]="menu">{{role.label}} <i
+                                class="fa fa-chevron-down"></i></button>
+                        <mat-menu #menu="matMenu" [class]="'roleListMenu'">
+                            <button mat-menu-item *ngFor="let selectRole of availableRoles"
+                                (click)="changeRole(diffusion,role,selectRole)"
+                                style="font-size:13px;">{{selectRole.label}}</button>
+                        </mat-menu>
+                    </div>
+                    <div *ngIf="role.id !== 'dest' && adminMode">
+                        <button mat-icon-button color="warn" (click)="deleteItem(role.id,i)">
+                            <mat-icon class="fa fa-times" style="height:auto;"></mat-icon>
+                        </button>
+                    </div>
+                </mat-list-item>
+            </mat-list>
+        </mat-expansion-panel>
+    </ng-container>
+</ng-container>
 <div *ngIf="loading" style="display:flex;height:100%;">
     <mat-spinner style="margin:auto;"></mat-spinner>
 </div>
-
-<mat-list *ngIf="!loading">
+<!--<mat-list *ngIf="!loading">
     <div *ngIf="diffList.length == 0" style="text-align:center;font-size:24px;font-weight:bold;opacity:0.3;">
         {{lang.noDiffusionList}}
     </div>
-    <plugin-autocomplete *ngIf="injectDatas.editable" [labelPlaceholder]="lang.addUserOrEntity" [routeDatas]="['/rest/autocomplete/users','/rest/autocomplete/entities']" [targetSearchKey]="'idToDisplay'" [subInfoKey]="'descriptionToDisplay'" (triggerEvent)="addElem($event)"></plugin-autocomplete>
+    <plugin-autocomplete *ngIf="injectDatas.editable" [labelPlaceholder]="lang.addUserOrEntity"
+        [routeDatas]="['/rest/autocomplete/users','/rest/autocomplete/entities']" [targetSearchKey]="'idToDisplay'"
+        [subInfoKey]="'descriptionToDisplay'" (triggerEvent)="addElem($event)"></plugin-autocomplete>
     <div cdkDropListGroup class="roleList">
         <ng-container *ngFor="let role of availableRoles">
             <h3 mat-subheader>{{role.label}}</h3>
@@ -16,7 +62,8 @@
                 [cdkDropListEnterPredicate]="role.id == 'dest' ? noReturnPredicate : allPredicate"
                 [cdkDropListDisabled]="role.id == 'dest' || !injectDatas.editable">
                 <div *ngIf="diffList[role.id].items.length === 0" style="text-align:center;">
-                    <span style="opacity: 0.5;text-align: center;font-size: 10px;padding: 10px;">{{lang.noPerson}}</span>
+                    <span
+                        style="opacity: 0.5;text-align: center;font-size: 10px;padding: 10px;">{{lang.noPerson}}</span>
                     <button mat-icon-button *ngIf="role.id == 'dest' && injectDatas.editable"
                         (click)="loadDestUserList()" [matMenuTriggerFor]="menuDestUserList"
                         title="{{lang.chooseAnotherEntityUser}}">
@@ -55,4 +102,4 @@
             </div>
         </ng-container>
     </div>
-</mat-list>
\ No newline at end of file
+</mat-list>-->
\ No newline at end of file
diff --git a/src/frontend/app/diffusions/diffusions-list.component.scss b/src/frontend/app/diffusions/diffusions-list.component.scss
index 24e6fea83c6..4121018417c 100644
--- a/src/frontend/app/diffusions/diffusions-list.component.scss
+++ b/src/frontend/app/diffusions/diffusions-list.component.scss
@@ -41,4 +41,61 @@
 
 .roleList {
     padding-bottom: 40px;
+}
+
+.diffusionList {
+    box-shadow : none;
+
+    .mat-expansion-panel-header-title {
+        color: #4A4A4A;
+        font-weight: bold;
+        font-size: 13px;
+    }
+
+    .item-diffusion-list {
+        height: 55px;
+        margin-bottom: 10px;
+        background-color: rgba(216,216,216,0.1);
+        border-radius: 10px;
+        font-size: 13px;
+
+        .mat-icon {
+            font-size: 13px;
+            height: 13px;
+            width: 13px;
+            padding-right: 10px;
+        }
+
+        .item-diffusion {
+            flex: 1;
+            display: flex;
+            flex-direction: column;
+            justify-content: center;
+            .mat-line {
+                margin: 0px;
+            }
+        }
+
+        .subInfo {
+            font-size: 13px;
+            opacity: 0.5;
+        }
+
+        .mat-button {
+            background: white;
+            font-size: 13px;
+            border: 0.5px solid rgba(74,74,74,0.32);
+            border-radius: 29.5px;
+            color: #4A4A4A;
+        }
+    }
+}
+
+::ng-deep.roleListMenu {
+    .mat-menu-content {
+        padding-top: 0;
+        padding-bottom: 0;
+        font-size: 13px;
+        color: #4A4A4A;
+    }
 }
\ No newline at end of file
diff --git a/src/frontend/app/diffusions/diffusions-list.component.ts b/src/frontend/app/diffusions/diffusions-list.component.ts
index 8f4e1aac5c1..2f11cbd9b93 100644
--- a/src/frontend/app/diffusions/diffusions-list.component.ts
+++ b/src/frontend/app/diffusions/diffusions-list.component.ts
@@ -3,6 +3,10 @@ import { HttpClient } from '@angular/common/http';
 import { LANG } from '../translate.component';
 import { NotificationService } from '../notification.service';
 import { CdkDragDrop, transferArrayItem } from '@angular/cdk/drag-drop';
+import { FormControl } from '@angular/forms';
+import { tap, exhaustMap, finalize, map, catchError } from 'rxjs/operators';
+import { of, forkJoin } from 'rxjs';
+import { filter } from 'minimatch';
 
 declare function $j(selector: any): any;
 
@@ -23,14 +27,71 @@ export class DiffusionsListComponent implements OnInit {
     currentEntityId: number = 0;
     userDestList: any[] = [];
 
-    diffList: any = {};
+    diffList: any = null;
 
 
     @Input('injectDatas') injectDatas: any;
 
+    /**
+     * Ressource identifier to load listinstance (Incompatible with templateId)
+     */
+    @Input('resId') resId: number;
+
+    /**
+     * Add previous dest in copy (Only compatible with resId)
+     */
+    @Input('keepDestForRedirection') keepDestForRedirection: boolean;
+
+    /**
+     * Entity identifier to load listModel of entity (Incompatible with resId)
+     */
+    @Input('entityId') entityId: any;
+
+    /**
+     * For manage current loaded list
+     */
+    @Input('adminMode') adminMode: boolean;
+
+    /**
+     * Ids of related allowed entities perimeters
+     */
+    @Input('allowedEntities') allowedEntities: number[];
+
+    /**
+     * To load privilege of current list management
+     * @param indexing
+     * @param process
+     */
+    @Input('target') target: string;
+
+    /**
+     * FormControl to use this component in form
+     */
+    @Input('diffFormControl') diffFormControl: FormControl;
+
     constructor(public http: HttpClient, private notify: NotificationService) { }
 
-    ngOnInit(): void { }
+    ngOnInit(): void {
+        this.adminMode = this.adminMode !== undefined ? this.adminMode : false;
+        this.keepDestForRedirection = this.keepDestForRedirection !== undefined ? this.keepDestForRedirection : false;
+
+        if (this.resId !== undefined) {
+
+            this.loadListinstance(this.resId);
+
+        } else if (this.entityId !== undefined && this.entityId !== '') {
+            this.loadListModel(this.entityId);
+        } else {
+            this.initRoles();
+        }
+
+        /*if (this.injectDatas === undefined) {
+            this.injectDatas = {};
+            this.injectDatas['editable'] = false;
+            this.loading = false;
+            this.loadListModel(6); 
+        }*/
+    }
 
     drop(event: CdkDragDrop<string[]>) {
         if (event.previousContainer === event.container) {
@@ -52,10 +113,98 @@ export class DiffusionsListComponent implements OnInit {
     }
 
     loadListModel(entityId: number) {
+        this.diffList = {};
         this.loading = true;
         this.currentEntityId = entityId;
         this.userDestList = [];
+
+        let arrayRoutes: any = [];
+        let mergedRoutesDatas: any = {};
+
         if (this.availableRoles.length === 0) {
+            arrayRoutes.push(this.http.get('../../rest/listTemplates/types/entity_id/roles'));
+        }
+
+        arrayRoutes.push(this.http.get('../../rest/listTemplates/entities/' + entityId));
+
+        if (this.resId !== undefined) {
+            arrayRoutes.push(this.http.get('../../rest/resources/' + this.resId + '/listInstance'));
+        }
+
+        forkJoin(arrayRoutes).pipe(
+            map(data => {
+                let objectId = '';
+                let index = '';
+                for (var key in data) {
+                    index = key;
+                    objectId = Object.keys(data[key])[0];
+                    mergedRoutesDatas[Object.keys(data[key])[0]] = data[index][objectId]
+                }
+                return mergedRoutesDatas;
+            }),
+            tap((data) => {
+                if (data.roles !== undefined) {
+                    data['roles'].forEach((element: any) => {
+                        if (element.id == 'cc') {
+                            element.id = 'copy';
+                        }
+                        if (element.available) {
+                            this.availableRoles.push(element);
+                            this.diffList[element.id] = {
+                                'label': element.label,
+                                'items': []
+                            };
+                        }
+                        if (element.keepInListInstance) {
+                            this.keepRoles.push(element.id);
+                        }
+                    });
+                } else {
+                    this.availableRoles.forEach(element => {
+                        this.diffList[element.id] = {
+                            'label': element.label,
+                            'items': []
+                        };
+                    });
+                }
+            }),
+            tap((data: any) => {
+                data.listTemplate.forEach((element: any) => {
+                    if (element.item_mode == 'cc') {
+                        this.diffList['copy'].items.push(element);
+                    } else if (element.object_type != 'VISA_CIRCUIT') {
+                        this.diffList[element.item_mode].items.push(element);
+                    }
+                });
+            }),
+            tap((data: any) => {
+                if (data.listInstance !== undefined) {
+                    data.listInstance.forEach((element: any) => {
+                        if (element.item_mode == 'cc') {
+                            element.item_mode = 'copy';
+                        }
+                        if (this.keepRoles.indexOf(element.item_mode) > -1 && this.diffList[element.item_mode].items.map((e: any) => { return e.item_id; }).indexOf(element.item_id) == -1) {
+                            this.diffList[element.item_mode].items.push(element);
+                        }
+                        if (this.keepDestForRedirection && element.item_mode == "dest" && this.diffList["copy"].items.map((e: any) => { return e.item_id; }).indexOf(element.item_id) == -1) {
+                            this.diffList["copy"].items.push(element);
+                        }
+                    });
+                }
+            }),
+            tap((data: any) => {
+                if (this.diffFormControl !== undefined) {
+                    this.setFormValues();
+                }
+            }),
+            finalize(() => this.loading = false),
+            catchError((err: any) => {
+                this.notify.handleErrors(err);
+                return of(false);
+            })
+        ).subscribe();
+
+        /*if (this.availableRoles.length === 0) {
             this.http.get("../../rest/listTemplates/types/entity_id/roles")
                 .subscribe((data: any) => {
                     data['roles'].forEach((element: any) => {
@@ -82,7 +231,7 @@ export class DiffusionsListComponent implements OnInit {
                 this.diffList[element.id].items = [];
             });
             this.getListmodel(entityId);
-        }
+        }*/
 
     }
 
@@ -170,6 +319,24 @@ export class DiffusionsListComponent implements OnInit {
         });
     }
 
+    initRoles() {
+        this.http.get('../../rest/listTemplates/types/entity_id/roles').pipe(
+            tap(() => {
+                this.availableRoles.forEach(element => {
+                    this.diffList[element.id] = {
+                        'label': element.label,
+                        'items': []
+                    };
+                });
+            }),
+            finalize(() => this.loading = false),
+            catchError((err: any) => {
+                this.notify.handleErrors(err);
+                return of(false);
+            })
+        ).subscribe();
+    }
+
     deleteItem(roleId: string, index: number) {
         this.diffList[roleId].items.splice(index, 1);
     }
@@ -247,4 +414,97 @@ export class DiffusionsListComponent implements OnInit {
             this.diffList['copy'].items.unshift(newElemListModel);
         }
     }
+
+    isEmptyList() {
+        let state = true;
+        if (this.diffList !== null) {
+            Object.keys(this.diffList).forEach((element: any) => {
+                if (this.diffList[element].items.length > 0) {
+                    state = false;
+                }
+            });
+        }
+        return state;
+    }
+
+    changeRole(user: any, oldRole: any, newRole: any) {
+
+        let indexFound = -1;
+
+        if (this.diffFormControl !== undefined) {
+            this.http.get("../../rest/users/9/entities").pipe(
+                map((data: any) => {
+                    data.entities = data.entities.map((entity: any) => entity.id)
+                    return data;
+                }),
+                tap((data: any) => {
+                    let isAllowed: boolean = false;
+                    this.allowedEntities.forEach(allowedEntity => {
+                        if (data.entities.indexOf(allowedEntity) > -1) {
+                            isAllowed = true;
+                        }
+                    });
+                    if (isAllowed) {
+                        if (newRole.id === 'dest') {
+                            if (this.keepDestForRedirection) {
+                                const destUser = this.diffList[oldRole.id].items[0];
+                                indexFound = this.diffList[oldRole.id].items.map((item: any) => item.id).indexOf(destUser.id);
+                
+                                if (indexFound > -1) {
+                                    this.diffList[oldRole.id].items.push(destUser);
+                                }
+                            }
+                            indexFound = this.diffList[oldRole.id].items.map((item: any) => item.id).indexOf(user.id);
+                
+                            if (indexFound > -1) {
+                                this.diffList[oldRole.id].items.splice(indexFound, 1);
+                            }
+                            this.diffList[newRole.id].items[0] = user;
+                
+                        } else {
+                            indexFound = this.diffList[oldRole.id].items.map((item: any) => item.id).indexOf(user.id);
+                
+                            if (indexFound > -1) {
+                                this.diffList[oldRole.id].items.splice(indexFound, 1);
+                            }
+                            this.diffList[newRole.id].items.push(user);
+                        }
+                    } else {
+                        alert('Non autorisé');
+                    }
+                }),
+            ).subscribe();
+        }
+
+        /*const newDest = {
+            difflist_type: "entity_id",
+            item_type: "user_id",
+            item_id: user.user_id,
+            labelToDisplay: user.labelToDisplay,
+            descriptionToDisplay: user.descriptionToDisplay,
+            item_mode: "dest"
+        };
+        this.diffList['dest'].items[0] = newDest;*/
+    }
+
+    switchMode() {
+        this.adminMode = !this.adminMode;
+    }
+
+    setFormValues() {
+        let arrValues: any[] = [];
+        Object.keys(this.diffList).forEach(role => {
+            arrValues = arrValues.concat(
+                this.diffList[role].items.map((item: any) => {
+                    return {
+                        id: item.item_id,
+                        mode: item.item_mode,
+                        type: item.item_type === 'user_id' ? 'user' : 'entity'
+                    }
+                })
+            );
+        });
+        this.diffFormControl.setValue(arrValues);
+        this.diffFormControl.markAsTouched();
+    }
 }
\ No newline at end of file
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 834429955f9..787644c6b6d 100644
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.html
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.html
@@ -158,9 +158,33 @@
                                 <i class="fas fa-times" style="color:red;font-size:15px;"
                                     *ngIf="!adminMode && arrFormControl[field.identifier].touched && arrFormControl[field.identifier].hasError('required')"></i>
                                 <i class="fas fa-check" style="color:green;font-size:15px;"
-                                    *ngIf="!adminMode && arrFormControl[field.identifier].valid && (arrFormControl[field.identifier].value!==null && arrFormControl[field.identifier].value!=='' && arrFormControl[field.identifier].value.length > 0)"></i>
+                                    *ngIf="!adminMode && arrFormControl[field.identifier].valid && !isEmptyField(field)"></i>
                             </div>
                         </div>
+                        <div *ngIf="field.identifier === 'destination' && !adminMode">
+                            <mat-divider></mat-divider>
+                            <div style="padding: 10px;font-size: 16px;color: #135F7F;letter-spacing: 2px;font-weight: bold;display: flex;
+                                align-items: center;">
+                                <div style="display: flex;flex: 1;align-items: center;">
+                                    Liste de diffusion <button mat-icon-button color="primary"
+                                            (click)="appDiffusionsList.switchMode()">
+                                            <mat-icon class="fa fa-edit"></mat-icon>
+                                        </button>
+                                </div>
+                                <div class="fieldState" style="width: 20px;padding: 0px;">
+                                    <i class="fas fa-asterisk"
+                                        *ngIf="adminMode || (arrFormControl['diffusionList'].hasError('required') && arrFormControl['diffusionList'].untouched)"
+                                        [class.noMandatory]="!field.mandatory"></i>
+                                    <i class="fas fa-times" style="color:red;font-size:15px;"
+                                        *ngIf="!adminMode && arrFormControl['diffusionList'].touched && arrFormControl['diffusionList'].hasError('required')"></i>
+                                    <i class="fas fa-check" style="color:green;font-size:15px;"
+                                        *ngIf="!adminMode && arrFormControl['diffusionList'].valid && !isEmptyField(field)"></i>
+                                </div>
+                            </div>
+                            <app-diffusions-list #appDiffusionsList [entityId]="arrFormControl[field.identifier].value" [diffFormControl]="arrFormControl['diffusionList']" [allowedEntities]="[1,2,3,5]">
+                            </app-diffusions-list>
+                            <mat-divider></mat-divider>
+                        </div>
                     </ng-container>
                 </div>
             </div>
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 f2dd29808ab..4691838139d 100644
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnInit, Input } from '@angular/core';
+import { Component, OnInit, Input, ViewChild } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 import { LANG } from '../../translate.component';
 import { NotificationService } from '../../notification.service';
@@ -10,6 +10,7 @@ import { of, forkJoin } from 'rxjs';
 import { SortPipe } from '../../../plugins/sorting.pipe';
 import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
 import { FormControl, Validators, FormGroup, ValidationErrors, ValidatorFn, AbstractControl } from '@angular/forms';
+import { DiffusionsListComponent } from '../../diffusions/diffusions-list.component';
 
 @Component({
     selector: 'app-indexing-form',
@@ -28,6 +29,8 @@ export class IndexingFormComponent implements OnInit {
     @Input('groupId') groupId: number;
     @Input('admin') adminMode: boolean;
 
+    @ViewChild('appDiffusionsList', { static: false }) appDiffusionsList: DiffusionsListComponent;
+
     fieldCategories: any[] = ['mail', 'contact', 'process', 'classement'];
 
     indexingModelsCore: any[] = [
@@ -339,7 +342,6 @@ export class IndexingFormComponent implements OnInit {
                                 let defaultVal = data.entities.filter((entity: any) => entity.enabled === true && entity.id === elem.default_value);
                                 elem.default_value = defaultVal.length > 0 ? defaultVal[0].id : '';
                                 this.arrFormControl[elem.identifier].setValue(defaultVal.length > 0 ? defaultVal[0].id : '');
-
                                 elem.values = data.entities.map((entity: any) => {
                                     title = entity.entity_label;
 
@@ -353,6 +355,7 @@ export class IndexingFormComponent implements OnInit {
                                         disabled: !entity.enabled
                                     }
                                 });
+                                elem.event = 'loadDiffusionList';
                             }
                         } else if (elem.identifier === 'arrivalDate') {
                             elem.startDate = 'docDate';
@@ -373,7 +376,7 @@ export class IndexingFormComponent implements OnInit {
                         } else if (elem.identifier === 'folder') {
                             elem.values = null;
 
-                        }  else if (elem.identifier === 'category_id') {
+                        } else if (elem.identifier === 'category_id') {
                             elem.values = data.categories;
 
                         } else if (elem.identifier === 'priority') {
@@ -599,6 +602,19 @@ export class IndexingFormComponent implements OnInit {
         }
 
         this.arrFormControl[field.identifier].setValidators(valArr);
+
+        if (field.identifier === 'destination') {
+            let valArr: ValidatorFn[] = [];
+
+            valArr.push(Validators.required);
+
+            this.arrFormControl['diffusionList'] = new FormControl({ value: null, disabled: false });
+
+            this.arrFormControl['diffusionList'].setValidators(valArr);
+
+            this.arrFormControl['diffusionList'].setValue([]);
+
+        }
     }
 
     regexValidator(regex: RegExp, error: ValidationErrors): ValidatorFn {
@@ -612,7 +628,6 @@ export class IndexingFormComponent implements OnInit {
     }
 
     isValidForm() {
-        console.log(this.indexingFormGroup.controls['folder']);
         if (!this.indexingFormGroup.valid) {
             Object.keys(this.indexingFormGroup.controls).forEach(key => {
 
@@ -628,6 +643,14 @@ export class IndexingFormComponent implements OnInit {
         return this.indexingFormGroup.valid;
     }
 
+    isEmptyField(field: any) {
+        if (this.arrFormControl[field.identifier].value !== null || String(this.arrFormControl[field.identifier].value) !== '' || this.arrFormControl[field.identifier].value.length > 0 ) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
     getMinDate(id: string) {
         if (this.arrFormControl[id] !== undefined) {
             return this.arrFormControl[id].value;
@@ -692,4 +715,8 @@ export class IndexingFormComponent implements OnInit {
     changeCategory(categoryId: string) {
         this.currentCategory = categoryId;
     }
+
+    loadDiffusionList(field: any, value: any) {
+        this.appDiffusionsList.loadListModel(value);
+    }
 }
diff --git a/src/frontend/plugins/autocomplete/autocomplete.component.html b/src/frontend/plugins/autocomplete/autocomplete.component.html
index cecb05d57ab..a48ad16b3ff 100644
--- a/src/frontend/plugins/autocomplete/autocomplete.component.html
+++ b/src/frontend/plugins/autocomplete/autocomplete.component.html
@@ -18,7 +18,7 @@
           </mat-icon>&nbsp;<span color="primary">{{option[key]}}</span>&nbsp;<small>{{option[subInfoKey]}}</small>
         </mat-option>
       </ng-container>
-      <mat-option class="autoCompleteInfoResult" *ngIf="options.length === 0 && !loading" [class.smallInputInfo]="size === 'small'" disabled
+      <mat-option class="autoCompleteInfoResult smallInputInfo" *ngIf="options.length === 0 && !loading" disabled
         [innerHTML]="listInfo">
       </mat-option>
       <mat-option *ngIf="loading" disabled>
-- 
GitLab