From 41a4a58af1e724428eb479683c2cc11785297db9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 15 May 2014 17:57:13 -0400 Subject: [PATCH] FIX: Thanks .gitignore, I missed a necessary file! --- .../javascripts/controllers/poll.js.es6 | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/poll/assets/javascripts/controllers/poll.js.es6 diff --git a/plugins/poll/assets/javascripts/controllers/poll.js.es6 b/plugins/poll/assets/javascripts/controllers/poll.js.es6 new file mode 100644 index 00000000000..5deef83b3b3 --- /dev/null +++ b/plugins/poll/assets/javascripts/controllers/poll.js.es6 @@ -0,0 +1,44 @@ +export default Discourse.Controller.extend({ + poll: null, + showResults: Em.computed.oneWay('poll.closed'), + disableRadio: Em.computed.any('poll.closed', 'loading'), + showToggleClosePoll: function() { + return this.get('poll.post.topic.details.can_edit') && !Discourse.SiteSettings.allow_user_locale; + }.property('poll.post.topic.details.can_edit'), + + actions: { + selectOption: function(option) { + if (this.get('disableRadio')) { + return; + } + + if (!this.get('currentUser.id')) { + this.get('postController').send('showLogin'); + return; + } + + this.set('loading', true); + this.get('poll').saveVote(option).then(function() { + this.set('loading', false); + this.set('showResults', true); + }.bind(this)); + }, + + 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)); + } + } +}); +