Add close/open poll buttons to poll UI.

This commit is contained in:
Vikhyat Korrapati
2014-04-12 22:53:21 +05:30
parent cc607dc0b5
commit 5de7d889fd
5 changed files with 137 additions and 40 deletions

View File

@@ -24,6 +24,18 @@
{{/if}}
</button>
{{#if poll.post.topic.details.can_edit}}
<button {{action toggleClosePoll}} class="btn btn-small">
{{#if poll.closed}}
<i class="fa fa-unlock-alt"></i>
{{i18n poll.open_poll}}
{{else}}
<i class="fa fa-lock"></i>
{{i18n poll.close_poll}}
{{/if}}
</button>
{{/if}}
{{#if loading}}
<i class="fa fa-spin fa-spinner"></i>
{{/if}}

View File

@@ -44,7 +44,6 @@ var Poll = Discourse.Model.extend({
var PollController = Discourse.Controller.extend({
poll: null,
showResults: Em.computed.oneWay('poll.closed'),
disableRadio: Em.computed.any('poll.closed', 'loading'),
actions: {
@@ -67,6 +66,18 @@ var PollController = Discourse.Controller.extend({
toggleShowResults: function() {
this.set('showResults', !this.get('showResults'));
},
toggleClosePoll: function() {
this.set('loading', true);
return Discourse.ajax("/poll/toggle_close", {
type: "PUT",
data: {post_id: this.get('poll.post.id')}
}).then(function(topicJson) {
this.set('poll.post.topic.title', topicJson.basic_topic.title);
this.set('poll.post.topic.fancy_title', topicJson.basic_topic.title);
this.set('loading', false);
}.bind(this));
}
}
});