Skip to content
Snippets Groups Projects
Commit 563a5bb7 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #12072 TIME 4 front existing email page

parent 03d91102
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@
</div>
<mat-table #table [dataSource]="dataSource" matSort matSortActive="creationDate" matSortDirection="desc">
<ng-container matColumnDef="creationDate">
<mat-cell *matCellDef="let row" class="dataLine" style="flex: 1;padding: 0px;flex-direction: column;">
<mat-cell *matCellDef="let row" class="dataLine" style="flex: 1;padding: 0px;flex-direction: column;" (click)="openPromptMail(row.id)">
<div class="subinfo">
<span style="flex:1" [title]="row.creationDate | fullDate">
{{lang.createdAlt}} : <b>{{row.creationDate | timeAgo : 'full'}}</b>
......@@ -49,9 +49,7 @@
</span>
</div>
<div class="desc">
{{row.desc}}
</div>
<div class="contact">
<span *ngIf="row.sender" style="white-space: pre;overflow: hidden;text-overflow: ellipsis;" [title]="row.sender">
......
......@@ -46,11 +46,11 @@ export class SendedResourceListComponent implements OnInit {
public privilegeService: PrivilegeService) { }
async ngOnInit(): Promise<void> {
this.sendedResources = [];
this.loadList();
}
async loadList() {
this.sendedResources = [];
this.loading = true;
await this.initAcknowledgementReceipList();
await this.initEmailList();
......@@ -193,9 +193,9 @@ export class SendedResourceListComponent implements OnInit {
this.dataSource.filter = ev.value;
}
openPromptMail() {
openPromptMail(emailId: number = null) {
const dialogRef = this.dialog.open(SendedResourcePageComponent, { maxWidth: '90vw', width: '750px', disableClose: true, data: { title: `Toto`, resId: this.resId } });
const dialogRef = this.dialog.open(SendedResourcePageComponent, { maxWidth: '90vw', width: '750px', disableClose: true, data: { title: `Toto`, resId: this.resId, emailId : emailId } });
dialogRef.afterClosed().pipe(
filter((data: string) => data === 'success'),
......
......@@ -8,25 +8,26 @@
<mat-dialog-content class="modal-container">
<mat-form-field>
<span matPrefix class="attachLabel">De&nbsp;:&nbsp;</span>
<mat-select [(ngModel)]="currentSender">
<mat-option *ngFor="let email of availableSenders | sortBy: 'label'" [value]="email">
<input *ngIf="emailStatus === 'SENT'" matInput [value]="currentSender" readonly>
<mat-select *ngIf="emailStatus !== 'SENT'" [(ngModel)]="currentSender">
<mat-option *ngFor="let email of availableSenders | sortBy: 'label'" [value]="email.email">
{{email.label}} ({{email.email}})
</mat-option>
</mat-select>
<button mat-button color="primary" matSuffix [class.activeButton]="showCopies" (click)="$event.stopPropagation();showCopies = !showCopies">Cc</button>
<button mat-button color="primary" matSuffix [class.activeButton]="showInvisibleCopies"
<button mat-button color="primary" matSuffix [disabled]="emailStatus === 'SENT'" [class.activeButton]="showCopies" (click)="$event.stopPropagation();showCopies = !showCopies">Cc</button>
<button mat-button color="primary" matSuffix [disabled]="emailStatus === 'SENT'" [class.activeButton]="showInvisibleCopies"
(click)="$event.stopPropagation();showInvisibleCopies = !showInvisibleCopies">Cci</button>
</mat-form-field>
<mat-form-field>
<span matPrefix class="attachLabel">À&nbsp;:&nbsp;</span>
<mat-chip-list id="recipients-list" #recipientsList cdkDropList [cdkDropListConnectedTo]="['copies-list','invcopies-list']" [cdkDropListData]="recipients" (cdkDropListDropped)="drop($event)">
<mat-chip cdkDrag class="recipients" *ngFor="let recipient of recipients" [selectable]="selectable" removable
<mat-chip cdkDrag class="recipients" *ngFor="let recipient of recipients" [selectable]="selectable" [removable]="emailStatus !== 'SENT'"
(removed)="remove(recipient, 'recipients')" [title]="recipient.email">
{{recipient.label}}
<mat-icon matChipRemove class="fa fa-times"></mat-icon>
<mat-icon matChipRemove class="fa fa-times" *ngIf="emailStatus !== 'SENT'"></mat-icon>
</mat-chip>
<input [formControl]="recipientsInput" [matChipInputFor]="recipientsList"
<input [formControl]="recipientsInput" [disabled]="emailStatus === 'SENT'" [matChipInputFor]="recipientsList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="add($event, 'recipients')" [matAutocomplete]="autoEmails" (focus)="resetAutocomplete()">
</mat-chip-list>
......@@ -40,12 +41,12 @@
<mat-form-field *ngIf="showCopies">
<span matPrefix class="attachLabel">Cc&nbsp;:&nbsp;</span>
<mat-chip-list id="copies-list" #copiesList cdkDropList [cdkDropListConnectedTo]="['recipients-list','invcopies-list']" [cdkDropListData]="copies" (cdkDropListDropped)="drop($event)">
<mat-chip cdkDrag class="copy" *ngFor="let copy of copies" [selectable]="selectable" removable
<mat-chip cdkDrag class="copy" *ngFor="let copy of copies" [selectable]="selectable" [removable]="emailStatus !== 'SENT'"
(removed)="remove(copy, 'copies')" [title]="copy.email">
{{copy.label}}
<mat-icon matChipRemove class="fa fa-times"></mat-icon>
<mat-icon matChipRemove class="fa fa-times" *ngIf="emailStatus !== 'SENT'"></mat-icon>
</mat-chip>
<input [formControl]="recipientsInput" [matChipInputFor]="copiesList"
<input [formControl]="recipientsInput" [disabled]="emailStatus === 'SENT'" [matChipInputFor]="copiesList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="add($event, 'copies')" [matAutocomplete]="autoEmails2" (focus)="resetAutocomplete()">
</mat-chip-list>
......@@ -59,12 +60,12 @@
<mat-form-field *ngIf="showInvisibleCopies">
<span matPrefix class="attachLabel">Cci&nbsp;:&nbsp;</span>
<mat-chip-list id="invcopies-list" #invCopiesList cdkDropList [cdkDropListConnectedTo]="['recipients-list','copies-list']" [cdkDropListData]="invisibleCopies" (cdkDropListDropped)="drop($event)">
<mat-chip class="copy" *ngFor="let invCopy of invisibleCopies" [selectable]="selectable" removable
<mat-chip class="copy" *ngFor="let invCopy of invisibleCopies" [selectable]="selectable" [removable]="emailStatus !== 'SENT'"
(removed)="remove(invCopy, 'invisibleCopies')" [title]="invCopy.email">
{{invCopy.label}}
<mat-icon matChipRemove class="fa fa-times"></mat-icon>
<mat-icon matChipRemove class="fa fa-times" *ngIf="emailStatus !== 'SENT'"></mat-icon>
</mat-chip>
<input [formControl]="recipientsInput" [matChipInputFor]="invCopiesList"
<input [formControl]="recipientsInput" [disabled]="emailStatus === 'SENT'" [matChipInputFor]="invCopiesList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputAddOnBlur]="true"
(matChipInputTokenEnd)="add($event, 'invisibleCopies')" [matAutocomplete]="autoEmails3" (focus)="resetAutocomplete()">
</mat-chip-list>
......@@ -75,8 +76,8 @@
</mat-autocomplete>
</mat-form-field>
<mat-form-field floatLabel="never">
<input matInput placeholder="Sujet" [(ngModel)]="emailsubject" maxlength="70">
<button mat-icon-button matSuffix *ngFor="let keyVal of emailAttachTool | keyvalue" [disabled]="emailAttachTool[keyVal.key].list.length === 0" [title]="emailAttachTool[keyVal.key].title" (click)="$event.stopPropagation();currentEmailAttachTool=keyVal.key;" [matMenuTriggerFor]="emailAttachListMenu">
<input matInput placeholder="Sujet" [readonly]="emailStatus === 'SENT'" [(ngModel)]="emailsubject" maxlength="70">
<button mat-icon-button matSuffix *ngFor="let keyVal of emailAttachTool | keyvalue" [disabled]="emailStatus === 'SENT' || emailAttachTool[keyVal.key].list.length === 0" [title]="emailAttachTool[keyVal.key].title" (click)="$event.stopPropagation();currentEmailAttachTool=keyVal.key;" [matMenuTriggerFor]="emailAttachListMenu">
<mat-icon class="{{emailAttachTool[keyVal.key].icon}}" [class.activeButton]="(keyVal.key === 'document' && emailAttach.document.isLinked) || (keyVal.key !== 'document' && emailAttach[keyVal.key].length > 0)" color="primary"></mat-icon>
</button>
<mat-menu #emailAttachListMenu="matMenu" [class]="'attachListMenu'">
......@@ -93,22 +94,22 @@
</mat-menu>
</mat-form-field>
<mat-chip-list>
<mat-chip class="copy" *ngIf="emailAttach.document.isLinked" [selectable]="selectable" removable
<mat-chip class="copy" *ngIf="emailAttach.document.isLinked" [selectable]="selectable" [removable]="emailStatus !== 'SENT'"
(removed)="removeAttachMail(0, 'document')" [title]="emailAttach.document.chrono + ' - ' + emailAttach.document.label">
<i class="fa fa-file attachLabel"></i>&nbsp;{{emailAttach.document.label | shorten: 25: '...'}}&nbsp;<small class="attachLabel">(pdf - 25 Ko)</small>
<mat-icon matChipRemove class="fa fa-times"></mat-icon>
<mat-icon matChipRemove class="fa fa-times" *ngIf="emailStatus !== 'SENT'"></mat-icon>
</mat-chip>
<ng-container *ngFor="let keyVal of emailAttach | keyvalue">
<ng-container *ngIf="keyVal.key !== 'document'">
<mat-chip class="copy" *ngFor="let item of emailAttach[keyVal.key]; let i=index;" [selectable]="selectable" removable
<mat-chip class="copy" *ngFor="let item of emailAttach[keyVal.key]; let i=index;" [selectable]="selectable" [removable]="emailStatus !== 'SENT'"
(removed)="removeAttachMail(i, keyVal.key)" [title]="item.title">
<i class="{{emailAttachTool[keyVal.key].icon}} attachLabel"></i>&nbsp;{{item.label | shorten: 25: '...'}}&nbsp;<small class="attachLabel">({{item.format}}{{!functions.empty(item.size) ? ' - '+item.size : ''}})</small>
<mat-icon matChipRemove class="fa fa-times"></mat-icon>
<mat-icon matChipRemove class="fa fa-times" *ngIf="emailStatus !== 'SENT'"></mat-icon>
</mat-chip>
</ng-container>
</ng-container>
</mat-chip-list>
<div class="models">
<div class="models" *ngIf="emailStatus !== 'SENT'">
<plugin-select-search *ngIf="availableEmailModels.length > 0" [label]="'Modèle(s) de mail'"
[placeholderLabel]="'Modèle(s) de mail'" [datas]="availableEmailModels"
[formControlSelect]="templateEmailListForm" (afterSelected)="mergeEmailTemplate($event)"
......@@ -121,9 +122,12 @@
>
</plugin-select-search>
</div>
<textarea name="emailSignature" id="emailSignature"></textarea>
<div style="padding-top: 10px;">
<textarea style="padding-top: 10px;" name="emailSignature" id="emailSignature" [(ngModel)]="emailContent"></textarea>
</div>
</mat-dialog-content>
<div mat-dialog-actions class="actions">
<div mat-dialog-actions class="actions" *ngIf="emailStatus !== 'SENT'">
<button mat-raised-button color="primary" (click)="onSubmit()">Envoyer</button>
<button mat-raised-button color="primary" (click)="saveDraft()">Enregistrer le brouilon</button>
<button mat-raised-button color="warn" (click)="deleteEmail()" [disabled]="emailStatus === 'SENT' || emailStatus === 'WAITING'">Supprimer</button>
</div>
......@@ -61,6 +61,7 @@ export class SendedResourcePageComponent implements OnInit {
emailId: number = null;
emailsubject: string = '';
emailStatus: string = 'WAITING';
emailContent: string = '';
currentEmailAttachTool: string = '';
emailAttachTool: any = {
document: {
......@@ -111,13 +112,21 @@ export class SendedResourcePageComponent implements OnInit {
await this.getAttachElements();
await this.getResourceData();
await this.getUserEmails();
if (this.data.emailId) {
await this.getEmailData(this.data.emailId);
}
this.loading = false;
this.initMce();
setTimeout(() => {
this.initMce();
}, 0);
}
initMce() {
tinymce.init({
selector: "textarea#emailSignature",
readonly : this.emailStatus === 'SENT',
suffix: '.min',
language: this.lang.langISO.replace('-', '_'),
language_url: `../../node_modules/tinymce-i18n/langs/${this.lang.langISO.replace('-', '_')}.js`,
menubar: false,
......@@ -130,10 +139,10 @@ export class SendedResourcePageComponent implements OnInit {
},
toolbar_sticky: true,
toolbar_drawer: 'floating',
toolbar:
toolbar: this.emailStatus !== 'SENT' ?
'undo redo | fontselect fontsizeselect | bold italic underline strikethrough forecolor | maarch_b64image | \
alignleft aligncenter alignright alignjustify \
bullist numlist outdent indent | removeformat'
bullist numlist outdent indent | removeformat' : false
});
}
......@@ -255,12 +264,78 @@ export class SendedResourcePageComponent implements OnInit {
}
}
getEmailData(emailId: number) {
return new Promise((resolve, reject) => {
this.http.get(`../../rest/emails/${emailId}`).pipe(
tap((data: any) => {
this.currentSender = data.sender.email;
this.recipients = data.recipients.map((item: any) => {
return {
label: item,
email: item
}
});
this.copies = data.cc.map((item: any) => {
return {
label: item,
email: item
}
});;
this.invisibleCopies = data.cci.map((item: any) => {
return {
label: item,
email: item
}
});
this.showCopies = this.copies.length > 0;
this.showInvisibleCopies = this.invisibleCopies.length > 0;
this.emailsubject = data.object;
this.emailStatus = data.status;
this.emailContent = data.body;
Object.keys(data.document).forEach(element => {
if (['id', 'isLinked', 'original'].indexOf(element) === -1) {
data.document[element].forEach((dataAttach: any) => {
const elem = this.emailAttachTool[element].list.filter((item: any) => item.id === dataAttach.id);
if (elem.length > 0) {
this.emailAttach[element] = elem.map((item: any) => {
return {
...item,
format: dataAttach.original ? item.format : 'pdf',
original: dataAttach.original
}
})
}
});
} else if (element === 'isLinked' && data.document.isLinked === true) {
this.emailAttach.document.isLinked = true;
this.emailAttach.document.original = data.document.original;
}
});
data.document
resolve(true);
}),
catchError((err) => {
this.notify.handleSoftErrors(err);
resolve(false);
return of(false);
})
).subscribe();
});
}
getResourceData() {
return new Promise((resolve, reject) => {
this.http.get(`../../rest/resources/${this.data.resId}?light=true`).pipe(
tap((data: any) => {
this.resourceData = data;
this.emailsubject = `[${this.resourceData.chrono}] ${this.resourceData.subject}`;
this.emailsubject = this.emailsubject.substring(0, 70);
this.emailAttach.document.chrono = this.resourceData.chrono;
this.emailAttach.document.label = this.resourceData.subject;
......@@ -304,7 +379,7 @@ export class SendedResourcePageComponent implements OnInit {
this.http.get('../../rest/currentUser/availableEmails').pipe(
tap((data: any) => {
this.availableSenders = data.emails;
this.currentSender = this.availableSenders[0];
this.currentSender = this.availableSenders[0].email;
resolve(true);
}),
catchError((err) => {
......@@ -411,7 +486,7 @@ export class SendedResourcePageComponent implements OnInit {
onSubmit() {
this.emailStatus = 'WAITING';
if (this.emailId === null) {
if (this.data.emailId === null) {
if (this.emailsubject === '') {
const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.confirm, msg: 'Vous allez envoyer un courriel sans sujet, continuer ?' } });
......@@ -433,7 +508,7 @@ export class SendedResourcePageComponent implements OnInit {
createEmail(closeModal: boolean = true) {
this.http.post(`../../rest/emails`, this.formatEmail()).pipe(
tap((data: any) => {
//this.emailId = data.id;
//this.data.emailId = data.id;
if (this.emailStatus === 'DRAFT') {
this.notify.success("Brouillon enregitré");
......@@ -453,8 +528,25 @@ export class SendedResourcePageComponent implements OnInit {
).subscribe();
}
deleteEmail() {
const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.delete, msg: this.lang.confirmAction } });
dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.delete(`../../rest/emails/${this.data.emailId}`)),
tap(() => {
this.notify.success("Courriel supprimé");
this.closeModal('success');
}),
catchError((err) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}
updateEmail(closeModal: boolean = true) {
this.http.put(`../../rest/emails/${this.emailId}`, this.formatEmail()).pipe(
this.http.put(`../../rest/emails/${this.data.emailId}`, this.formatEmail()).pipe(
tap(() => {
if (this.emailStatus === 'DRAFT') {
this.notify.success("Brouillon modifié");
......@@ -475,7 +567,7 @@ export class SendedResourcePageComponent implements OnInit {
saveDraft() {
this.emailStatus = 'DRAFT';
if (this.emailId === null) {
if (this.data.emailId === null) {
this.createEmail();
} else {
this.updateEmail();
......@@ -548,7 +640,7 @@ export class SendedResourcePageComponent implements OnInit {
const data = {
document: objAttach,
sender: formatSender,
sender: { email: formatSender },
recipients: this.recipients.map(recipient => recipient.email),
cc: this.showCopies ? this.copies.map(copy => copy.email) : [],
cci: this.showInvisibleCopies ? this.invisibleCopies.map((invCopy => invCopy.email)) : [],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment