Commit 2c07e8c8 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #16633 TIME 1 add cc + cci + show dest in create ar + externalize mail component

parent b927e3a0
<div class="mat-dialog-content-container">
<h1 mat-dialog-title>{{data.action.label}}</h1>
<div mat-dialog-content *ngIf="!loadingInit">
<div id="modal-content" mat-dialog-content>
<div *ngIf="loading" class="loading" style="display:flex;height:100%;">
<mat-spinner style="margin:auto;"></mat-spinner>
</div>
<div class="row">
<div class="col-md-12">
<p *ngIf="arMode == 'both' || acknowledgement.sendEmail || acknowledgement.sendPaper">
{{'lang.makeActionOn' | translate}}
<b *ngIf="data.resIds.length === 0" color="primary"
class="highlight">{{'lang.currentIndexingMail' | translate}}</b>
<b *ngIf="data.resIds.length == 1" color="primary" class="highlight">{{data.resource.chrono}}</b>
<b *ngIf="data.resIds.length > 1" color="primary" class="highlight">{{data.resIds.length}}
{{'lang.elements' | translate}}</b> ?
<div *ngIf="arMode == 'both'">
<mat-slide-toggle [(ngModel)]="manualAR" color="primary"
(change)="toggleArManual($event.checked)">
{{'lang.editAcknowledgementReceipt' | translate}}</mat-slide-toggle>
</div>
<div *ngIf="manualAR && realResSelected.length > 0">
<mat-form-field floatLabel="never">
<span matPrefix><span
class="attachLabel">{{'lang.object' | translate}}&nbsp;:&nbsp;</span>[AR]&nbsp;</span>
<input matInput [(ngModel)]="emailsubject" maxlength="100">
</mat-form-field>
<div class="models">
<plugin-select-search *ngIf="availableEmailModels.length > 0" [label]="'lang.emailModel' | translate"
[placeholderLabel]="'lang.emailModel' | translate" [datas]="availableEmailModels"
[formControlSelect]="templateEmailListForm"
(afterSelected)="mergeEmailTemplate($event)">
</plugin-select-search>
<plugin-select-search #templateList *ngIf="availableSignEmailModels.length > 0"
[label]="'lang.emailSignatures' | translate" [placeholderLabel]="'lang.emailSignatures' | translate"
[datas]="availableSignEmailModels" [formControlSelect]="emailSignListForm"
(afterSelected)="mergeSignEmailTemplate($event)">
</plugin-select-search>
{{'lang.makeActionOn' | translate}}
<b *ngIf="data.resIds.length === 0" color="primary"
class="highlight">{{'lang.currentIndexingMail' | translate}}</b>
<b *ngIf="data.resIds.length == 1" color="primary" class="highlight">{{data.resource.chrono}}</b>
<b *ngIf="data.resIds.length > 1" color="primary" class="highlight">{{data.resIds.length}}
{{'lang.elements' | translate}}</b> ?
<app-maarch-message *ngIf="acknowledgement.alreadySend?.number" mode="info">
<p>
<b>{{acknowledgement.alreadySend.number}}</b>&nbsp;<span [innerHTML]="'lang.arAlreadySend' | translate"></span> :
</p>
<div class="chronoList">
<div style="text-decoration: underline;display: inline-block;" *ngFor="let info of acknowledgement.alreadySend.list | sortBy : 'alt_identifier'">
{{info.alt_identifier}}
</div>
<textarea style="padding-top: 10px;" name="emailSignature" id="emailSignature"
[(ngModel)]="emailContent"></textarea>
</div>
<div *ngIf="acknowledgement.alreadySend.number">
<div class="alert-message alert-message-info acknowledgementList" role="alert">
<p>
<b>{{acknowledgement.alreadySend.number}}</b> {{'lang.arAlreadySend' | translate}} :
</p>
<ul>
<li *ngFor="let info of acknowledgement.alreadySend.list">
{{info.alt_identifier}}
</li>
</ul>
</div>
</div>
<div *ngIf="acknowledgement.alreadyGenerated.number">
<div class="alert-message alert-message-info acknowledgementList" role="alert">
<p>
<b>{{acknowledgement.alreadyGenerated.number}}</b> {{'lang.arAlreadyGenerated' | translate}} :
</p>
<ul>
<li *ngFor="let info of acknowledgement.alreadyGenerated.list">
{{info.alt_identifier}}
</li>
</ul>
</div>
</app-maarch-message>
<app-maarch-message *ngIf="acknowledgement.alreadyGenerated?.number" mode="info">
<p>
<b>{{acknowledgement.alreadyGenerated.number}}</b>&nbsp;<span [innerHTML]="'lang.arAlreadyGenerated' | translate"></span> :
</p>
<div style="text-decoration: underline;display: inline-block;" *ngFor="let info of acknowledgement.alreadyGenerated.list">
{{info.alt_identifier}}
</div>
<div *ngIf="acknowledgement.noSendAR.number">
<div class="alert-message alert-message-info acknowledgementList" role="alert">
<p><b>{{acknowledgement.noSendAR.number}}</b> {{'lang.canNotSendAr' | translate}} :</p>
<ul>
<li *ngFor="let info of acknowledgement.noSendAR.list">
<b>{{info.alt_identifier != null ? info.alt_identifier : 'lang.undefined' | translate}}</b> :
{{info.info}}
</li>
</ul>
</div>
</app-maarch-message>
<app-maarch-message *ngIf="acknowledgement.noSendAR?.number" mode="info">
<p><b>{{acknowledgement.noSendAR.number}}</b>&nbsp;<span [innerHTML]="'lang.canNotSendAr' | translate"></span> :</p>
<div class="acknowledgementList">
<ng-container *ngFor="let info of acknowledgement.noSendAR.list | sortBy : 'info'">
<div class="chrono">
{{info.alt_identifier != null ? info.alt_identifier : 'lang.undefined' | translate}}
</div>
<div>
{{info.info}}
</div>
</ng-container>
</div>
</app-maarch-message>
<app-maarch-message *ngIf="acknowledgement.sendEmail" mode="success"
[content]="'lang.readyToSendElectronicAr' | translate : {nb : acknowledgement.sendEmail}">
</app-maarch-message>
<app-maarch-message *ngIf="acknowledgement.sendPaper" mode="success"
[content]="'lang.readyToGeneratePaperAr' | translate : {nb : acknowledgement.sendPaper}">
</app-maarch-message>
<div *ngIf="acknowledgement.sendEmail || acknowledgement.sendPaper"
class="alert-message alert-message-success acknowledgementList" role="alert"
style="padding: 10px;">
<div *ngIf="acknowledgement.sendEmail">
<b>{{acknowledgement.sendEmail}}</b>
{{'lang.readyToSendElectronicAr' | translate}}
</div>
<div *ngIf="acknowledgement.sendPaper">
<b>{{acknowledgement.sendPaper}}</b>
{{'lang.readyToGeneratePaperAr' | translate}}
</div>
</div>
<app-mail-editor #appMailEditor
*ngIf="!manualAR && realResSelected.length > 0"
[availableSenders]="senders"
[currentSender]="senders[0]"
[recipientDisabled]="true"
[recipientHide]="data.resIds.length > 1"
[recipientDisabled]="true"
[senderDisabled]="senders.length === 1"
[cCDisabled]="!canAddCopies"
[cCIDisabled]="!canAddCopies"
[attachmentsHide]="true"
[bodyHide]="true"
[subjectHide]="true"
[resId]="data.resIds.length === 1 ? data.resIds[0] : null"
></app-mail-editor>
<div *ngIf="arMode == 'both'">
<mat-slide-toggle [(ngModel)]="manualAR" color="primary" (change)="toggleArManual($event.checked)">
{{'lang.editAcknowledgementReceipt' | translate}}</mat-slide-toggle>
</div>
<app-mail-editor #appMailEditor
*ngIf="manualAR && realResSelected.length > 0"
[availableSenders]="senders"
[currentSender]="senders[0]"
[recipientDisabled]="true"
[recipientHide]="data.resIds.length > 1"
[senderDisabled]="senders.length === 1"
[cCDisabled]="!canAddCopies"
[cCIDisabled]="!canAddCopies"
[attachmentsHide]="true"
[resId]="data.resIds.length === 1 ? data.resIds[0] : null"
[subjectPrefix]="'[AR]'"
></app-mail-editor>
</div>
<div class="col-md-12" *ngIf="acknowledgement.sendEmail || acknowledgement.sendPaper">
<app-note-editor #noteEditor [resIds]="data.resIds"></app-note-editor>
......@@ -99,6 +94,7 @@
<button mat-raised-button mat-button color="primary"
[disabled]="loading || (!acknowledgement.sendEmail && !acknowledgement.sendPaper)"
(click)="onSubmit()">{{'lang.validate' | translate}}</button>
<button mat-raised-button mat-button [disabled]="loading" [mat-dialog-close]="">{{'lang.cancel' | translate}}</button>
<button mat-raised-button mat-button [disabled]="loading"
[mat-dialog-close]="">{{'lang.cancel' | translate}}</button>
</div>
</div>
\ No newline at end of file
......@@ -12,30 +12,28 @@
width: 100%;
height: 100%;
background: #ffffffb3;
z-index: 1;
z-index: 2;
overflow: hidden;
}
.acknowledgementList {
ul {
font-size: 12px;
max-height: 100px;
overflow: auto;
padding-left: 25px;
padding-right: 5px;
padding-bottom: 10px;
margin-top: 10px;
}
display: grid;
grid-template-columns: 1fr 2fr;
grid-gap: 10px;
max-height: 100px;
overflow: auto;
p {
//font-size: 18px;
margin: 0;
.chrono {
text-align: right;
text-decoration: underline;
}
}
b {
font-size: 120%;
}
.chronoList {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 10px;
max-height: 100px;
}
.models {
......@@ -48,4 +46,8 @@
.attachLabel {
color: $primary;
}
.no-scroll {
overflow: hidden;
}
\ No newline at end of file
import { Component, OnInit, Inject, ViewChild, OnDestroy } from '@angular/core';
import { Component, OnInit, Inject, ViewChild } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { NotificationService } from '@service/notification/notification.service';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
......@@ -6,27 +6,19 @@ import { HttpClient } from '@angular/common/http';
import { NoteEditorComponent } from '../../notes/note-editor.component';
import { tap, finalize, catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import { FormControl } from '@angular/forms';
import { AppService } from '@service/app.service';
import { FunctionsService } from '../../../service/functions.service';
declare var tinymce: any;
import { FunctionsService } from '@service/functions.service';
import { MailEditorComponent } from '@plugins/mail-editor/mail-editor.component';
@Component({
templateUrl: "create-acknowledgement-receipt-action.component.html",
templateUrl: 'create-acknowledgement-receipt-action.component.html',
styleUrls: ['create-acknowledgement-receipt-action.component.scss'],
})
export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDestroy {
export class CreateAcknowledgementReceiptActionComponent implements OnInit {
loading: boolean = false;
loadingInit: boolean = false;
@ViewChild('appMailEditor', { static: false }) appMailEditor: MailEditorComponent;
@ViewChild('noteEditor', { static: false }) noteEditor: NoteEditorComponent;
emailsubject: string = '';
emailContent: string = '';
availableEmailModels: any[] = [];
availableSignEmailModels: any[] = [];
emailSignListForm = new FormControl();
templateEmailListForm = new FormControl();
loading: boolean = true;
acknowledgement: any = {
alReadyGenerated: {},
......@@ -37,82 +29,100 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
sendList: []
};
realResSelected: number[]= [];
realResSelected: number[] = [];
currentMode: string = '';
manualAR: boolean = false;
arMode: 'auto' | 'manual' | 'both' = 'auto';
canAddCopies: boolean = false;
senders: any[] = [];
@ViewChild('noteEditor', { static: false }) noteEditor: NoteEditorComponent;
loadingExport: boolean;
constructor(
public translate: TranslateService,
public http: HttpClient,
private notify: NotificationService,
public dialogRef: MatDialogRef<CreateAcknowledgementReceiptActionComponent>,
public http: HttpClient,
private notify: NotificationService,
public dialogRef: MatDialogRef<CreateAcknowledgementReceiptActionComponent>,
public functions: FunctionsService,
@Inject(MAT_DIALOG_DATA) public data: any) { }
ngOnInit(): void {
this.loadingInit = true;
async ngOnInit(): Promise<void> {
await this.checkAcknowledgementReceipt();
this.loading = false;
}
startLoader() {
document.getElementById('modal-content').scrollTo(0, 0);
document.getElementById('modal-content').classList.add('no-scroll');
this.loading = true;
}
this.checkAcknowledgementReceipt();
endLoader() {
document.getElementById('modal-content').classList.remove('no-scroll');
this.loading = false;
}
checkAcknowledgementReceipt() {
this.http.post('../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkAcknowledgementReceipt?' + this.currentMode, { resources: this.data.resIds })
.subscribe((data: any) => {
this.acknowledgement = data;
this.realResSelected = data.sendList;
this.loadingInit = false;
this.arMode = data.mode;
if (this.arMode === 'manual') {
this.toggleArManual(true);
}
}, (err) => {
this.notify.error(err.error.errors);
this.dialogRef.close();
this.loadingInit = false;
});
return new Promise((resolve) => {
this.http.post('../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkAcknowledgementReceipt?' + this.currentMode, { resources: this.data.resIds }).pipe(
tap((data: any) => {
this.acknowledgement = data;
this.realResSelected = data.sendList;
this.arMode = data.mode;
this.canAddCopies = data.canAddCopies;
this.senders = data.emailSenders;
if (this.arMode === 'manual') {
this.toggleArManual(true);
}
}),
finalize(() => resolve(true)),
catchError((err: any) => {
this.notify.error(err.error.errors);
this.dialogRef.close();
return of(false);
})
).subscribe();
});
}
onSubmit() {
this.loading = true;
this.startLoader();
if (this.data.resIds.length > 0) {
this.executeAction();
}
}
ngOnDestroy(): void {
tinymce.remove();
}
executeAction() {
let data = null;
let data = {};
const emaildata = this.appMailEditor.formatEmail();
if (this.manualAR) {
if (this.functions.empty(tinymce.get('emailSignature').getContent())) {
if (this.functions.empty(emaildata.body)) {
this.notify.error(this.translate.instant('lang.arContentIsEmpty'));
this.loading = false;
return false;
}
data = {
subject : this.emailsubject,
content : tinymce.get('emailSignature').getContent(),
subject : emaildata.object,
content : emaildata.body,
manual : true
};
}
if (this.canAddCopies) {
data = {...data, sender : this.appMailEditor.getSender(), cc : this.appMailEditor.getCopies(), cci : this.appMailEditor.getInvisibleCopies()};
}
this.http.put(this.data.processActionRoute, { resources: this.realResSelected, note: this.noteEditor.getNote(), data }).pipe(
tap((data: any) => {
if (data && data.data != null) {
this.downloadAcknowledgementReceipt(data.data);
tap((res: any) => {
if (res && res.data != null) {
this.downloadAcknowledgementReceipt(res.data);
}
if (data && data.errors != null) {
this.notify.error(data.errors);
if (res && res.errors != null) {
this.notify.error(res.errors);
}
this.dialogRef.close(this.realResSelected);
}),
finalize(() => this.loading = false),
finalize(() => this.endLoader()),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);
......@@ -122,28 +132,11 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
downloadAcknowledgementReceipt(data: any) {
this.loadingExport = true;
this.http.post('../rest/acknowledgementReceipts', { 'resources': data }, { responseType: "blob" })
.subscribe((data) => {
let downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(data);
let today: any;
let dd: any;
let mm: any;
let yyyy: any;
today = new Date();
dd = today.getDate();
mm = today.getMonth() + 1;
yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
today = dd + '-' + mm + '-' + yyyy;
downloadLink.setAttribute('download', "acknowledgement_receipt_maarch_" + today + ".pdf");
this.http.post('../rest/acknowledgementReceipts', { 'resources': data }, { responseType: 'blob' })
.subscribe((dataFile) => {
const downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(dataFile);
downloadLink.setAttribute('download', this.functions.getFormatedFileName('acknowledgement_receipt_maarch', 'pdf'));
document.body.appendChild(downloadLink);
downloadLink.click();
this.loadingExport = false;
......@@ -154,134 +147,15 @@ export class CreateAcknowledgementReceiptActionComponent implements OnInit, OnDe
toggleArManual(state: boolean) {
if (state) {
if (this.currentMode != 'mode=manual') {
if (this.currentMode !== 'mode=manual') {
this.currentMode = 'mode=manual';
this.checkAcknowledgementReceipt();
}
this.manualAR = true;
if (this.data.resIds.length === 1) {
this.emailsubject = this.data.resource.subject;
this.emailsubject = this.emailsubject.substring(0, 100);
}
this.initEmailModelsList();
this.initSignEmailModelsList();
setTimeout(() => {
this.initMce();
}, 800);
} else {
this.currentMode = 'mode=auto';
this.checkAcknowledgementReceipt();
tinymce.remove();
this.manualAR = false;
}
}
initMce() {
tinymce.init({
selector: "textarea#emailSignature",
base_url: '../node_modules/tinymce/',
readonly: false,
suffix: '.min',
language: this.translate.instant('lang.langISO').replace('-', '_'),
language_url: `../node_modules/tinymce-i18n/langs/${this.translate.instant('lang.langISO').replace('-', '_')}.js`,
menubar: false,
statusbar: false,
plugins: [
'autolink', 'autoresize'
],
external_plugins: {
'maarch_b64image': "../../src/frontend/plugins/tinymce/maarch_b64image/plugin.min.js"
},
toolbar_sticky: true,
toolbar_drawer: 'floating',
toolbar: 'undo redo | fontselect fontsizeselect | bold italic underline strikethrough forecolor | maarch_b64image | \
alignleft aligncenter alignright alignjustify \
bullist numlist outdent indent | removeformat'
});
}
mergeEmailTemplate(templateId: any) {
this.templateEmailListForm.reset();
this.http.post(`../rest/templates/${templateId}/mergeEmail`, { data: { resId: this.data.resIds[0] } }).pipe(
tap((data: any) => {
var div = document.createElement('div');
div.innerHTML = tinymce.get('emailSignature').getContent();
if (div.getElementsByClassName('signature').length > 0) {
const signatureContent = div.getElementsByClassName('signature')[0].innerHTML;
div.getElementsByClassName('signature')[0].remove();
tinymce.get('emailSignature').setContent(`${div.innerHTML}${data.mergedDocument}<div class="signature">${signatureContent}</div>`);
} else {
tinymce.get('emailSignature').setContent(`${tinymce.get('emailSignature').getContent()}${data.mergedDocument}`);
}
}),
catchError((err) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}
mergeSignEmailTemplate(templateId: any) {
this.emailSignListForm.reset();
this.http.get(`../rest/currentUser/emailSignatures/${templateId}`).pipe(
tap((data: any) => {
var div = document.createElement('div');
div.innerHTML = tinymce.get('emailSignature').getContent();
if (div.getElementsByClassName('signature').length > 0) {
div.getElementsByClassName('signature')[0].remove();
tinymce.get('emailSignature').setContent(`${div.innerHTML}<div class="signature">${data.emailSignature.content}</div>`);
} else {
tinymce.get('emailSignature').setContent(`${tinymce.get('emailSignature'