diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts index 48d9adc..fff18eb 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts @@ -1,18 +1,30 @@ -import {Component, Input} from "ng-forward"; +import {Component, Input, Inject} from "ng-forward"; import {SideCommentsComponent} from "../side-comments/side-comments.component"; +import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; @Component({ selector: "comment-paragraph-plugin-allow-comment", templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html", directives: [SideCommentsComponent] }) +@Inject("$scope", CommentParagraphEventService) export class AllowCommentComponent { @Input() content: string; @Input() paragraphUuid: string; @Input() article: noosfero.Article; + constructor(private $scope: ng.IScope, private commentParagraphEventService: CommentParagraphEventService) { } + + ngOnInit() { + this.commentParagraphEventService.subscribeToggleCommentParagraph((article: noosfero.Article) => { + this.article = article; + this.$scope.$apply(); + }); + } + isActivated() { return this.article.setting.comment_paragraph_plugin_activate; } + } diff --git a/src/plugins/comment_paragraph/events/comment-paragraph-event.service.ts b/src/plugins/comment_paragraph/events/comment-paragraph-event.service.ts new file mode 100644 index 0000000..0872bca --- /dev/null +++ b/src/plugins/comment_paragraph/events/comment-paragraph-event.service.ts @@ -0,0 +1,19 @@ +import {Injectable, EventEmitter} from "ng-forward"; + +@Injectable() +export class CommentParagraphEventService { + + private toggleCommentParagraphEmitter: EventEmitter; + + constructor() { + this.toggleCommentParagraphEmitter = new EventEmitter(); + } + + toggleCommentParagraph(article: noosfero.Article) { + this.toggleCommentParagraphEmitter.next(article); + } + + subscribeToggleCommentParagraph(fn: (article: noosfero.Article) => void) { + this.toggleCommentParagraphEmitter.subscribe(fn); + } +} diff --git a/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts index 6d9f0ad..78e3023 100644 --- a/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts +++ b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts @@ -1,28 +1,33 @@ import { Input, Inject, Component } from "ng-forward"; import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; import {CommentParagraphService} from "../http/comment-paragraph.service"; +import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; @Component({ selector: "comment-paragraph-article-button-hotspot", templateUrl: "plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html", }) -@Inject("$scope", CommentParagraphService) +@Inject("$scope", CommentParagraphService, CommentParagraphEventService) @Hotspot("article_extra_toolbar_buttons") export class CommentParagraphArticleButtonHotspotComponent { @Input() article: noosfero.Article; - constructor(private $scope: ng.IScope, private commentParagraphService: CommentParagraphService) { } + constructor(private $scope: ng.IScope, + private commentParagraphService: CommentParagraphService, + private commentParagraphEventService: CommentParagraphEventService) { } deactivateCommentParagraph() { this.commentParagraphService.deactivateCommentParagraph(this.article).then((result: noosfero.RestResult) => { this.article = result.data; + this.commentParagraphEventService.toggleCommentParagraph(this.article); }); } activateCommentParagraph() { this.commentParagraphService.activateCommentParagraph(this.article).then((result: noosfero.RestResult) => { this.article = result.data; + this.commentParagraphEventService.toggleCommentParagraph(this.article); }); } } -- libgit2 0.21.2