diff --git a/src/app/api-connector/vo.service.ts b/src/app/api-connector/vo.service.ts index f9e82980e4..2e663fbd61 100644 --- a/src/app/api-connector/vo.service.ts +++ b/src/app/api-connector/vo.service.ts @@ -40,7 +40,24 @@ export class VoService { } - sendMailToVo(subject, message,reply?): Observable { + sendNewsletterToVo(subject, message,reply?): Observable { + let urlSearchParams = new URLSearchParams(); + urlSearchParams.append('subject', subject); + urlSearchParams.append('message', message); + urlSearchParams.append('reply',reply) + + let header = new Headers({ + 'X-CSRFToken': this.settings.getCSRFToken(), + }); + return this.http.post(this.settings.getApiBaseURL() + 'vo_manager/sendNewsletterToMembers/', urlSearchParams, { + withCredentials: true, + headers: header, + }).map((res: Response) => res.json()).catch((error: any) => Observable.throw(error.json().error || 'Server error')) + + } + + + sendMailToVo(subject, message,reply?): Observable { let urlSearchParams = new URLSearchParams(); urlSearchParams.append('subject', subject); urlSearchParams.append('message', message); diff --git a/src/app/vo_manager/VoOverviewComponent.ts b/src/app/vo_manager/VoOverviewComponent.ts index 3d25f07efa..1fc43e69bd 100644 --- a/src/app/vo_manager/VoOverviewComponent.ts +++ b/src/app/vo_manager/VoOverviewComponent.ts @@ -3,7 +3,7 @@ import {VoService} from "../api-connector/vo.service"; import {Project} from "../projectmanagement/project.model"; import {ProjectMember} from "../projectmanagement/project_member.model"; import {GroupService} from "../api-connector/group.service"; -import * as moment from 'moment'; +import * as moment from 'moment'; @Component({ selector: 'voOverview', @@ -16,9 +16,12 @@ import * as moment from 'moment'; export class VoOverviewComponent { public emailSubject: string; - public emailReply:string=''; + public emailReply: string = ''; public emailText: string; public emailStatus: number = 0; + public emailHeader: string; + public emailVerify: string; + public emailType: number; public newsletterSubscriptionCounter: number; member_id: number; @@ -45,8 +48,35 @@ export class VoOverviewComponent { } - sendMailToVo(subject: string, message: string,reply?:string) { - this.voserice.sendMailToVo(encodeURIComponent(subject), encodeURIComponent(message),encodeURIComponent(reply)).subscribe(result => { + + sendEmail(subject: string, message: string, reply?: string) { + switch (this.emailType) { + case 0: { + this.sendMailToVo(subject, message, reply); + break; + } + case 1: { + this.sendNewsletterToVo(subject, message, reply); + break; + } + } + } + + sendNewsletterToVo(subject: string, message: string, reply?: string) { + this.voserice.sendNewsletterToVo(encodeURIComponent(subject), encodeURIComponent(message), encodeURIComponent(reply)).subscribe(result => { + if (result == 1) { + this.emailStatus = 1; + } + else { + this.emailStatus = 2; + } + }) + + } + + + sendMailToVo(subject: string, message: string, reply?: string) { + this.voserice.sendMailToVo(encodeURIComponent(subject), encodeURIComponent(message), encodeURIComponent(reply)).subscribe(result => { if (result == 1) { this.emailStatus = 1; } @@ -57,12 +87,33 @@ export class VoOverviewComponent { } + setEmailType(type: number) { + this.emailType = type; + switch (this.emailType) { + case 0: { + this.emailHeader = 'Send email to all members of\n' + + ' the vo'; + this.emailVerify = 'Are you sure you want to send this email to all members of the vo?'; + break; + } + case 1: { + this.emailHeader = 'Send newsletter to vo'; + this.emailVerify = 'Are you sure you want to send this newsletter?' + break; + } + + } + + } public resetEmailModal() { - this.emailSubject=null; - this.emailText=null; - this.emailReply=''; + this.emailHeader = null; + this.emailSubject = null; + this.emailText = null; + this.emailType=null; + this.emailVerify=null; + this.emailReply = ''; this.emailStatus = 0; } @@ -92,15 +143,15 @@ export class VoOverviewComponent { is_admin, [result['Facility'], result['FacilityId']] ) - newProject.Lifetime = group['lifetime'] - if (newProject.Lifetime != -1){ - newProject.LifetimeDays=Math.ceil(Math.abs(moment(dateCreated).add(newProject.Lifetime,'months').toDate().getTime()-dateCreated.getTime()))/(1000*3600*24) + newProject.Lifetime = group['lifetime'] + if (newProject.Lifetime != -1) { + newProject.LifetimeDays = Math.ceil(Math.abs(moment(dateCreated).add(newProject.Lifetime, 'months').toDate().getTime() - dateCreated.getTime())) / (1000 * 3600 * 24) - } - else{ - newProject.LifetimeDays=-1; } - this.projects.push(newProject); + else { + newProject.LifetimeDays = -1; + } + this.projects.push(newProject); }) } diff --git a/src/app/vo_manager/voOverview.component.html b/src/app/vo_manager/voOverview.component.html index 8879fd8461..5947047062 100644 --- a/src/app/vo_manager/voOverview.component.html +++ b/src/app/vo_manager/voOverview.component.html @@ -9,11 +9,16 @@

Vo Overview
- + +
@@ -109,8 +114,7 @@