post-comment.component.ts
1.56 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
import { Inject, Input, Component } from 'ng-forward';
import { CommentService } from "../../../../lib/ng-noosfero-api/http/comment.service";
import { NotificationService } from "../../../shared/services/notification.service";
import { SessionService } from "../../../login";
import { PostCommentEventService } from "./post-comment-event.service";
@Component({
selector: 'noosfero-post-comment',
templateUrl: 'app/article/comment/post-comment/post-comment.html'
})
@Inject(CommentService, NotificationService, SessionService, PostCommentEventService)
export class PostCommentComponent {
public static EVENT_COMMENT_RECEIVED = "comment.received";
@Input() article: noosfero.Article;
@Input() parent: noosfero.Comment;
comment = <noosfero.Comment>{};
private currentUser: noosfero.User;
constructor(private commentService: CommentService,
private notificationService: NotificationService,
private session: SessionService,
private postCommentEventService: PostCommentEventService) {
this.currentUser = this.session.currentUser();
}
save() {
if (this.parent && this.comment) {
this.comment.reply_of_id = this.parent.id;
}
this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult<noosfero.Comment>) => {
this.postCommentEventService.emit(result.data);
this.comment.body = "";
this.notificationService.success({ title: "comment.post.success.title", message: "comment.post.success.message" });
});
}
}