From 1014928b110f3fe148855ff89e365c1f5e0e0f00 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Mon, 17 Feb 2020 12:07:05 +0100 Subject: [PATCH] FEAT #12071 TIME 0:20 add regex control email format --- .../sended-resource-page.component.html | 21 ++++++++++++------ .../sended-resource-page.component.scss | 5 +++++ .../sended-resource-page.component.ts | 22 +++++++++++++++---- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.html b/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.html index ff206e1622f..d94cd8709ee 100644 --- a/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.html +++ b/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.html @@ -29,7 +29,8 @@ [cdkDropListConnectedTo]="['copies-list','invcopies-list']" [cdkDropListData]="recipients" (cdkDropListDropped)="drop($event)"> <mat-chip cdkDrag class="recipients" *ngFor="let recipient of recipients" [selectable]="selectable" - [removable]="canManageMail()" (removed)="remove(recipient, 'recipients')" [title]="recipient.email"> + [removable]="canManageMail()" (removed)="remove(recipient, 'recipients')" [title]="recipient.email" + [class.badFormat]="recipient.badFormat"> {{recipient.label}} <mat-icon matChipRemove class="fa fa-times" *ngIf="canManageMail()"></mat-icon> </mat-chip> @@ -51,7 +52,8 @@ [cdkDropListConnectedTo]="['recipients-list','invcopies-list']" [cdkDropListData]="copies" (cdkDropListDropped)="drop($event)"> <mat-chip cdkDrag class="copy" *ngFor="let copy of copies" [selectable]="selectable" - [removable]="canManageMail()" (removed)="remove(copy, 'copies')" [title]="copy.email"> + [removable]="canManageMail()" (removed)="remove(copy, 'copies')" [title]="copy.email" + [class.badFormat]="copy.badFormat"> {{copy.label}} <mat-icon matChipRemove class="fa fa-times" *ngIf="canManageMail()"></mat-icon> </mat-chip> @@ -73,7 +75,8 @@ [cdkDropListConnectedTo]="['recipients-list','copies-list']" [cdkDropListData]="invisibleCopies" (cdkDropListDropped)="drop($event)"> <mat-chip class="copy" *ngFor="let invCopy of invisibleCopies" [selectable]="selectable" - [removable]="canManageMail()" (removed)="remove(invCopy, 'invisibleCopies')" [title]="invCopy.email"> + [removable]="canManageMail()" (removed)="remove(invCopy, 'invisibleCopies')" [title]="invCopy.email" + [class.badFormat]="invCopy.badFormat"> {{invCopy.label}} <mat-icon matChipRemove class="fa fa-times" *ngIf="canManageMail()"></mat-icon> </mat-chip> @@ -91,7 +94,8 @@ </mat-autocomplete> </mat-form-field> <mat-form-field floatLabel="never"> - <input matInput [placeholder]="lang.object" [readonly]="!canManageMail()" [(ngModel)]="emailsubject" maxlength="70"> + <input matInput [placeholder]="lang.object" [readonly]="!canManageMail()" [(ngModel)]="emailsubject" + maxlength="70"> <button mat-icon-button matSuffix *ngFor="let keyVal of emailAttachTool | keyvalue" [disabled]="!canManageMail() || emailAttachTool[keyVal.key].list.length === 0" [title]="emailAttachTool[keyVal.key].title" @@ -161,7 +165,9 @@ </div> </mat-dialog-content> <div mat-dialog-actions class="actions" *ngIf="!loading"> - <button mat-raised-button color="primary" style="min-width: auto;width: 40px;padding: 0;" *ngIf="canManageMail() && privilegeService.hasCurrentUserPrivilege('sendmail')" [disabled]="recipients.length === 0" [matMenuTriggerFor]="emailActionMenu"> + <button mat-raised-button color="primary" style="min-width: auto;width: 40px;padding: 0;" + *ngIf="canManageMail() && privilegeService.hasCurrentUserPrivilege('sendmail')" + [disabled]="recipients.length === 0" [matMenuTriggerFor]="emailActionMenu"> <mat-icon style="height:auto;" class="fas fa-ellipsis-v"></mat-icon> </button> <mat-menu #emailActionMenu="matMenu" [class]="'attachListMenu'"> @@ -169,8 +175,9 @@ {{lang.sendInPlainText}} </button> </mat-menu> - <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() && 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> diff --git a/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.scss b/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.scss index 172618568a9..f164fdcbe41 100644 --- a/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.scss +++ b/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.scss @@ -55,4 +55,9 @@ width: auto; max-width: initial; min-height: auto; +} + +.badFormat { + background-color: red; + color: white; } \ No newline at end of file diff --git a/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.ts b/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.ts index 25e95e2d475..4b6ad252eea 100644 --- a/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.ts +++ b/src/frontend/app/sendedResource/sended-resource-page/sended-resource-page.component.ts @@ -165,7 +165,8 @@ export class SendedResourcePageComponent implements OnInit { this[type].push( { label: value.trim(), - email: value.trim() + email: value.trim(), + badFormat : this.isBadEmailFormat(value.trim()) }); } @@ -174,6 +175,16 @@ export class SendedResourcePageComponent implements OnInit { } } + isBadEmailFormat(email: string) { + const regex = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/g; + + if (email.trim().match(regex) !== null) { + return false + } else { + return true; + } + } + closeModal(state: string = '') { tinymce.remove(); this.dialogRef.close(state); @@ -286,19 +297,22 @@ export class SendedResourcePageComponent implements OnInit { this.recipients = data.recipients.map((item: any) => { return { label: item, - email: item + email: item, + badFormat : this.isBadEmailFormat(item) } }); this.copies = data.cc.map((item: any) => { return { label: item, - email: item + email: item, + badFormat : this.isBadEmailFormat(item) } });; this.invisibleCopies = data.cci.map((item: any) => { return { label: item, - email: item + email: item, + badFormat : this.isBadEmailFormat(item) } }); -- GitLab