UX: disable 'Hide results' button when poll is closed

This commit is contained in:
Régis Hanol
2015-09-16 13:01:08 +02:00
parent e211bf7d0b
commit cc75890cd4
5 changed files with 82 additions and 77 deletions

View File

@@ -1,4 +1,5 @@
import PostView from "discourse/views/post";
import { on } from "ember-addons/ember-computed-decorators";
function createPollView(container, post, poll, vote) {
const controller = container.lookup("controller:poll", { singleton: false }),
@@ -22,12 +23,14 @@ export default {
messageBus.subscribe("/polls", data => {
const post = container.lookup("controller:topic").get('model.postStream').findLoadedPost(data.post_id);
// HACK to trigger the "postViewUpdated" event
Em.run.next(_ => post.set("cooked", post.get("cooked") + " "));
Em.run.next(() => post.set("cooked", post.get("cooked") + " "));
});
// overwrite polls
PostView.reopen({
_createPollViews: function($post) {
@on("postViewInserted", "postViewUpdated")
_createPollViews($post) {
const post = this.get("post"),
polls = post.get("polls"),
votes = post.get("polls_votes") || {};
@@ -48,11 +51,11 @@ export default {
pollView = createPollView(container, post, polls[pollName], votes[pollName]);
$poll.replaceWith($div);
Em.run.next(_ => pollView.renderer.replaceIn(pollView, $div[0]));
Em.run.next(() => pollView.renderer.replaceIn(pollView, $div[0]));
pollViews[pollName] = pollView;
});
messageBus.subscribe("/polls/" + this.get("post.id"), results => {
messageBus.subscribe(`/polls/${this.get("post.id")}`, results => {
if (results && results.polls) {
_.forEach(results.polls, poll => {
if (pollViews[poll.name]) {
@@ -63,15 +66,16 @@ export default {
});
this.set("pollViews", pollViews);
}.on("postViewInserted", "postViewUpdated"),
},
_cleanUpPollViews: function() {
messageBus.unsubscribe("/polls/" + this.get("post.id"));
@on("willClearRender")
_cleanUpPollViews() {
messageBus.unsubscribe(`/polls/${this.get("post.id")}`);
if (this.get("pollViews")) {
_.forEach(this.get("pollViews"), v => v.destroy());
}
}.on("willClearRender")
}
});
}
};