Switch the awkward poll.post.poll_details.closed to poll.closed.

This commit is contained in:
Vikhyat Korrapati 2014-04-11 08:13:02 +05:30
parent 668a5ff526
commit edbbf7ffbb
1 changed files with 9 additions and 6 deletions

View File

@ -1,12 +1,13 @@
var Poll = Discourse.Model.extend({
post: null,
options: [],
closed: false,
postObserver: function() {
this.updateOptionsFromJson(this.get('post.poll_details'));
this.updateFromJson(this.get('post.poll_details'));
}.observes('post.poll_details'),
updateOptionsFromJson: function(json) {
updateFromJson: function(json) {
var selectedOption = json["selected"];
var options = [];
@ -18,6 +19,8 @@ var Poll = Discourse.Model.extend({
}));
});
this.set('options', options);
this.set('closed', json.closed);
},
saveVote: function(option) {
@ -29,16 +32,16 @@ var Poll = Discourse.Model.extend({
type: "PUT",
data: {post_id: this.get('post.id'), option: option}
}).then(function(newJSON) {
this.updateOptionsFromJson(newJSON);
this.updateFromJson(newJSON);
}.bind(this));
}
});
var PollController = Discourse.Controller.extend({
poll: null,
showResults: Em.computed.oneWay('poll.post.poll_details.closed'),
showResults: Em.computed.oneWay('poll.closed'),
disableRadio: Em.computed.any('poll.post.poll_details.closed', 'loading'),
disableRadio: Em.computed.any('poll.closed', 'loading'),
actions: {
selectOption: function(option) {
@ -80,7 +83,7 @@ function initializePollView(self) {
var pollDetails = post.get('poll_details');
var poll = Poll.create({post: post});
poll.updateOptionsFromJson(pollDetails);
poll.updateFromJson(pollDetails);
var pollController = PollController.create({
poll: poll,