mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: disable 'Hide results' button when poll is closed
This commit is contained in:
@@ -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")
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user