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

FEAT #12072 TIME 0:35 autosave draft + optimization

parent 79699c8f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
<span style="flex: 1;">
{{data.title}}
</span>
<button [title]="lang.close" mat-icon-button (click)="closeModal()">
<button [title]="lang.saveAndClose" mat-icon-button (click)="saveDraft()">
<mat-icon class="fa fa-times"></mat-icon>
</button></h1>
<mat-dialog-content class="modal-container">
......@@ -181,7 +181,6 @@
<button mat-raised-button color="primary"
*ngIf="canManageMail() && privilegeService.hasCurrentUserPrivilege('sendmail')" (click)="onSubmit()"
[disabled]="recipients.length === 0">{{lang.send}}</button>
<button mat-raised-button color="primary" *ngIf="canManageMail()" (click)="saveDraft()">{{lang.saveDraft}}</button>
<button mat-raised-button color="warn" (click)="deleteEmail()" *ngIf="data.emailId && data.emailType === 'email'"
[disabled]="headerService.user.id !== emailCreatorId">{{lang.delete}}</button>
</div>
......@@ -107,19 +107,27 @@ export class SentResourcePageComponent implements OnInit {
this.emailAttach[element] = [];
}
});
this.initEmailModelsList();
this.initEmailsList();
this.initSignEmailModelsList();
await this.getAttachElements();
await this.getResourceData();
await this.getUserEmails();
if (this.data.emailId && this.data.emailType === 'email') {
await this.getEmailData(this.data.emailId);
} else if (this.data.emailId && this.data.emailType === 'acknowledgementReceipt') {
await this.getAcknowledgementReceiptData(this.data.emailId);
}
if (this.canManageMail()) {
this.initEmailModelsList();
this.initEmailsList();
this.initSignEmailModelsList();
await this.getResourceData();
await this.getUserEmails();
if (this.emailStatus !== 'DRAFT') {
this.setDefaultInfo();
}
}
this.loading = false;
setTimeout(() => {
this.initMce();
......@@ -160,7 +168,7 @@ export class SentResourcePageComponent implements OnInit {
{
label: value.trim(),
email: value.trim(),
badFormat : this.isBadEmailFormat(value.trim())
badFormat: this.isBadEmailFormat(value.trim())
});
}
......@@ -292,21 +300,21 @@ export class SentResourcePageComponent implements OnInit {
return {
label: item,
email: item,
badFormat : this.isBadEmailFormat(item)
badFormat: this.isBadEmailFormat(item)
}
});
this.copies = data.cc.map((item: any) => {
return {
label: item,
email: item,
badFormat : this.isBadEmailFormat(item)
badFormat: this.isBadEmailFormat(item)
}
});
this.invisibleCopies = data.cci.map((item: any) => {
return {
label: item,
email: item,
badFormat : this.isBadEmailFormat(item)
badFormat: this.isBadEmailFormat(item)
}
});
......@@ -318,7 +326,7 @@ export class SentResourcePageComponent implements OnInit {
this.emailStatus = data.status;
this.currentSender = {
entityId : data.sender.entityId,
entityId: data.sender.entityId,
label: data.sender.label,
email: data.sender.email
};
......@@ -334,7 +342,7 @@ export class SentResourcePageComponent implements OnInit {
...item,
format: dataAttach.original || dataAttach.original === undefined ? item.format : 'pdf',
original: dataAttach.original,
size : dataAttach.original || dataAttach.original === undefined ? item.size : item.convertedDocument.size
size: dataAttach.original || dataAttach.original === undefined ? item.size : item.convertedDocument.size
}
})
}
......@@ -345,7 +353,7 @@ export class SentResourcePageComponent implements OnInit {
this.emailAttach.document.size = this.emailAttach.document.original ? this.emailAttachTool.document.list[0].size : this.emailAttachTool.document.list[0].convertedDocument.size
}
});
resolve(true);
}),
catchError((err) => {
......@@ -400,16 +408,10 @@ export class SentResourcePageComponent implements OnInit {
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;
if (!this.functions.empty(this.resourceData.senders)) {
this.resourceData.senders.forEach((sender: any) => {
this.setSender(sender.id);
});
}
resolve(true);
}),
catchError((err) => {
......@@ -421,6 +423,17 @@ export class SentResourcePageComponent implements OnInit {
});
}
setDefaultInfo() {
this.emailsubject = `[${this.resourceData.chrono}] ${this.resourceData.subject}`;
this.emailsubject = this.emailsubject.substring(0, 70);
this.currentSender = this.availableSenders[0];
if (!this.functions.empty(this.resourceData.senders)) {
this.resourceData.senders.forEach((sender: any) => {
this.setSender(sender.id);
});
}
}
setSender(id: number) {
this.http.get(`../../rest/contacts/${id}`).pipe(
tap((data: any) => {
......@@ -445,7 +458,6 @@ export class SentResourcePageComponent implements OnInit {
this.http.get('../../rest/currentUser/availableEmails').pipe(
tap((data: any) => {
this.availableSenders = data.emails;
this.currentSender = this.availableSenders[0];
resolve(true);
}),
catchError((err) => {
......@@ -568,7 +580,7 @@ export class SentResourcePageComponent implements OnInit {
} else {
if (this.emailsubject === '') {
const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.confirm, msg: this.lang.warnEmptySubject } });
dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
tap(() => {
......@@ -588,7 +600,7 @@ export class SentResourcePageComponent implements OnInit {
this.http.post(`../../rest/emails`, this.formatEmail()).pipe(
tap(() => {
if (this.emailStatus === 'DRAFT') {
this.notify.success(this.lang.draftSaved);
// this.notify.success(this.lang.draftSaved);
} else {
this.notify.success(`${this.lang.sendingEmail}...`);
}
......@@ -626,7 +638,7 @@ export class SentResourcePageComponent implements OnInit {
this.http.put(`../../rest/emails/${this.data.emailId}`, this.formatEmail()).pipe(
tap(() => {
if (this.emailStatus === 'DRAFT') {
this.notify.success(this.lang.draftUpdated);
// this.notify.success(this.lang.draftUpdated);
} else {
this.notify.success(`${this.lang.sendingEmail}...`);
}
......@@ -643,11 +655,19 @@ export class SentResourcePageComponent implements OnInit {
}
saveDraft() {
this.emailStatus = 'DRAFT';
if (this.data.emailId === null) {
this.createEmail();
if (this.canManageMail()) {
this.emailStatus = 'DRAFT';
if (this.data.emailId === null) {
if (!this.functions.empty(tinymce.get('emailSignature').getContent())) {
this.createEmail(true);
} else {
this.closeModal();
}
} else {
this.updateEmail(true);
}
} else {
this.updateEmail();
this.closeModal();
}
}
......@@ -674,7 +694,7 @@ export class SentResourcePageComponent implements OnInit {
...item,
format: mode !== 'pdf' ? item.format : 'pdf',
original: mode !== 'pdf',
size : mode === 'pdf' ? item.convertedDocument.size : item.size
size: mode === 'pdf' ? item.convertedDocument.size : item.size
});
}
}
......@@ -706,7 +726,7 @@ export class SentResourcePageComponent implements OnInit {
}
})
).subscribe();
}
}
......@@ -732,7 +752,7 @@ export class SentResourcePageComponent implements OnInit {
}
}
});
let formatSender = {
email: this.currentSender.email,
entityId: !this.functions.empty(this.currentSender.entityId) ? this.currentSender.entityId : null
......@@ -745,7 +765,7 @@ export class SentResourcePageComponent implements OnInit {
cc: this.showCopies ? this.copies.map(copy => copy.email) : [],
cci: this.showInvisibleCopies ? this.invisibleCopies.map((invCopy => invCopy.email)) : [],
object: this.emailsubject,
body: this.htmlMode ? tinymce.get('emailSignature').getContent() : tinymce.get('emailSignature').getContent({format: 'text'}),
body: this.htmlMode ? tinymce.get('emailSignature').getContent() : tinymce.get('emailSignature').getContent({ format: 'text' }),
isHtml: true,
status: this.emailStatus
};
......@@ -770,9 +790,9 @@ export class SentResourcePageComponent implements OnInit {
}
isAllEmailRightFormat() {
let state = true;
let state = true;
const allEmail = this.recipients.concat(this.copies).concat(this.invisibleCopies);
allEmail.map(item => item.email).forEach(email => {
if (this.isBadEmailFormat(email)) {
state = false;
......
......@@ -1580,4 +1580,5 @@ export const LANG_EN = {
"mailingMsg" : "<b>Mailing enbled</b> : <br><br><p>A <b>master</b> attachment will be created without merged field <b>contact</b> (attachmentRecipient).</p><p>If you click on Mailing, the attachmenets will be generated <b>NOW</b>.<br><br>If you click on Validate, They will be generated <b>BEFORE</b> to send to the first <b>signatory</b> of visa circuit.</p><p><b>One</b> attachment will be generated for <b>each contact</b> linked to the mail.</p>",
"attachmentGenerated" : "Attachment generated",
"mustEditAttachmentFirst" : "You must edit the attachment first",
"saveAndClose" : "Save and close",
};
......@@ -1619,4 +1619,5 @@ export const LANG_FR = {
"mailingMsg" : "<b>Publipostage activé</b> : <br><br><p>Une pièce jointe <b>maître</b> sera créée sans le champ de fusion <b>contact</b> (attachmentRecipient).</p><p>Si vous cliquez sur Publipostage, les pièces jointes seront générées <b>TOUT DE SUITE</b>.<br><br>Si vous cliquez sur Valider, elles seront générées <b>AVANT</b> transmission au premier <b>signataire</b> du circuit de visa.</p><br><p><b>Une</b> pièce jointe sera générée <b>par contact</b> associé au courrier.</p>",
"attachmentGenerated" : "Pièces jointes générées",
"mustEditAttachmentFirst" : "Vous devez d'abord éditer la pièce jointe",
"saveAndClose" : "Enregistrer et fermer",
};
......@@ -1605,4 +1605,5 @@ export const LANG_NL = {
"mailingMsg" : "<b>Mailing enbled</b> : <br><br><p>A <b>master</b> attachment will be created without merged field <b>contact</b> (attachmentRecipient).</p><p>If you click on Mailing, the attachmenets will be generated <b>NOW</b>.<br><br>If you click on Validate, They will be generated <b>BEFORE</b> to send to the first <b>signatory</b> of visa circuit.</p><p><b>One</b> attachment will be generated for <b>each contact</b> linked to the mail.</p>", //_TO_TRANSLATE
"attachmentGenerated" : "Attachment generated", //_TO_TRANSLATE
"mustEditAttachmentFirst" : "You must edit the attachment first", //_TO_TRANSLATE
"saveAndClose" : "Save and close", //_TO_TRANSLATE
};
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