profile-image-block.component.ts
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {Inject, Input, Component} from "ng-forward";
import {ProfileImageComponent} from "./../../../profile/image/image.component";
import {ProfileService} from "../../../../lib/ng-noosfero-api/http/profile.service";
import {SessionService} from "./../../../login";
import {NotificationService} from "../../../shared/services/notification.service";
@Component({
selector: "noosfero-profile-image-block",
templateUrl: 'app/layout/blocks/profile-image/profile-image-block.html',
directives: [ProfileImageComponent]
})
@Inject(ProfileService, SessionService, NotificationService)
export class ProfileImageBlockComponent {
@Input() block: noosfero.Block;
@Input() owner: noosfero.Profile;
private isMember: boolean;
constructor(private profileService: ProfileService, private session: SessionService, private notificationService: NotificationService) {
}
ngOnInit() {
this.loadMembership();
}
loadMembership() {
let person = this.session.currentUser() ? this.session.currentUser().person : null;
this.profileService.isMember(person, this.owner).then((val: boolean) => {
this.isMember = val;
});
}
join() {
let person = this.session.currentUser() ? this.session.currentUser().person : null;
this.profileService.addMember(person, this.owner).then((result: any) => {
if (result.data.pending) {
this.notificationService.success({ title: "blocks.profile_image.join.moderation.title", message: "blocks.profile_image.join.moderation.message" });
} else {
this.loadMembership();
}
});
}
leave() {
let person = this.session.currentUser() ? this.session.currentUser().person : null;
this.profileService.removeMember(person, this.owner).then(() => {
this.loadMembership();
});
}
}