Revision 53699
Added by Sofia Baltzi over 5 years ago
modules/uoa-connect-portal/trunk/src/app/utils/subscribe/invite.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import { Http, Response, Headers, RequestOptions } from '@angular/http'; |
|
3 |
import { Observable } from 'rxjs/Rx'; |
|
4 |
import {COOKIE} from "../../openaireLibrary/login/utils/helper.class" |
|
5 |
|
|
6 |
|
|
7 |
@Injectable() |
|
8 |
export class InviteService { |
|
9 |
|
|
10 |
constructor(private http:Http) { |
|
11 |
} |
|
12 |
inviteUsers(url:string, subject:string, body:string, recipients:string[]){ |
|
13 |
var email = {"subject":subject, "body":body, recipients: recipients }; |
|
14 |
return this.http.post(url+"/email", JSON.stringify(email), this.getAuthOptionsWithBody()) |
|
15 |
.map(res => <any> res.json()) |
|
16 |
.do(res => {console.log("Response is "+res)}); |
|
17 |
} |
|
18 |
public getAuthOptionsWithBody():RequestOptions{ |
|
19 |
let headers = new Headers(); |
|
20 |
headers.append('Content-Type', 'application/json'); |
|
21 |
headers.append('X-XSRF-TOKEN', COOKIE.getCookie(COOKIE.cookieName_id)); |
|
22 |
let options = new RequestOptions({ headers: headers, withCredentials:true }); |
|
23 |
return options; |
|
24 |
} |
|
25 |
|
|
26 |
} |
modules/uoa-connect-portal/trunk/src/app/utils/subscribe/invite.component.ts | ||
---|---|---|
1 |
import { Component, Input, ViewChild } from '@angular/core'; |
|
2 |
import { Location } from '@angular/common'; |
|
3 |
import {ActivatedRoute} from '@angular/router'; |
|
4 |
import { EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; |
|
5 |
|
|
6 |
import {InviteService} from './invite.service'; |
|
7 |
import {Session} from '../../openaireLibrary/login/utils/helper.class'; |
|
8 |
@Component({ |
|
9 |
selector: 'invite', |
|
10 |
template: ` |
|
11 |
<form class="uk-form-stacked"> |
|
12 |
<div> |
|
13 |
<label class="uk-form-label">Subject</label> |
|
14 |
<input type="text" placeholder="Subject" [(ngModel)]=subject name="subject"> |
|
15 |
</div> |
|
16 |
<div> |
|
17 |
<div class="uk-form-label">Message</div> |
|
18 |
<textarea cols="" rows="6" placeholder="Email message..." [(ngModel)]=body name="body"></textarea> |
|
19 |
</div> |
|
20 |
<a class="uk-button uk-button-primary" (click)="invite()"> Invite</a> |
|
21 |
</form> |
|
22 |
|
|
23 |
` |
|
24 |
}) |
|
25 |
|
|
26 |
export class InviteComponent { |
|
27 |
@Input() communityName:boolean; |
|
28 |
@Input() communityId:string; |
|
29 |
properties:EnvProperties; |
|
30 |
|
|
31 |
subject:string; |
|
32 |
body:string; |
|
33 |
recipients:string[] = []; |
|
34 |
|
|
35 |
constructor (private route: ActivatedRoute, |
|
36 |
private _inviteService: InviteService |
|
37 |
) { |
|
38 |
} |
|
39 |
|
|
40 |
public ngOnInit() { |
|
41 |
this.route.data |
|
42 |
.subscribe((data: { envSpecific: EnvProperties }) => { |
|
43 |
this.properties = data.envSpecific; |
|
44 |
this.subject = "["+this.communityName+"] Invitation to join community"; |
|
45 |
this.body = "Dear sir or madame, \n\nWe would like to invite you to join "+this.communityName + |
|
46 |
" OpenAIRE community (beta."+this.communityId+".openaire.eu)"; |
|
47 |
}); |
|
48 |
|
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
invite(){ |
|
53 |
var email = Session.getUserEmail(); |
|
54 |
//TODO |
|
55 |
this._inviteService.inviteUsers( this.properties.adminToolsAPIURL,this.subject, this.body, ["argirok@di.uoa.gr"]).subscribe ( |
|
56 |
res => { |
|
57 |
console.log(res); |
|
58 |
|
|
59 |
}); |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
} |
modules/uoa-connect-portal/trunk/src/app/utils/subscribe/invite.module.ts | ||
---|---|---|
1 |
import { NgModule} from '@angular/core'; |
|
2 |
import { CommonModule } from '@angular/common'; |
|
3 |
import { RouterModule } from '@angular/router'; |
|
4 |
import {FormsModule} from '@angular/forms'; |
|
5 |
|
|
6 |
import { InviteService } from './invite.service'; |
|
7 |
import {InviteComponent} from './invite.component'; |
|
8 |
import {AlertModalModule} from '../../openaireLibrary/utils/modal/alertModal.module'; |
|
9 |
|
|
10 |
@NgModule({ |
|
11 |
imports: [ |
|
12 |
CommonModule, RouterModule, AlertModalModule, FormsModule |
|
13 |
], |
|
14 |
declarations: [ |
|
15 |
InviteComponent |
|
16 |
], |
|
17 |
providers:[ |
|
18 |
InviteService |
|
19 |
], |
|
20 |
exports: [ |
|
21 |
InviteComponent |
|
22 |
] |
|
23 |
}) |
|
24 |
export class InviteModule { } |
Also available in: Unified diff
Delete previous version of invite to subscribe