FIX: editing a poll/post with a poll wasn't working properly

This commit is contained in:
Régis Hanol
2015-04-26 00:12:19 +02:00
parent 84c65aeb60
commit 151dea4088
4 changed files with 70 additions and 46 deletions
@@ -32,6 +32,9 @@ export default {
// don't even bother when there's no poll
if (!polls) { return; }
// clean-up if needed
this._cleanUpPollViews();
const pollViews = {};
// iterate over all polls
@@ -47,14 +50,20 @@ export default {
});
this.messageBus.subscribe("/polls/" + this.get("post.id"), results => {
pollViews[results.poll.name].get("controller").set("model", Em.Object.create(results.poll));
if (results && results.polls) {
_.forEach(results.polls, poll => {
if (pollViews[poll.name]) {
pollViews[poll.name].get("controller").set("model", Em.Object.create(poll));
}
});
}
});
this.set("pollViews", pollViews);
}.on("postViewInserted"),
}.on("postViewInserted", "postViewUpdated"),
_cleanUpPollViews: function() {
this.messageBus.unsubscribe("/polls/*");
this.messageBus.unsubscribe("/polls/" + this.get("post.id"));
if (this.get("pollViews")) {
_.forEach(this.get("pollViews"), v => v.destroy());