discourse/plugins/poll/assets/javascripts/controllers/poll.js.es6
Régis Hanol 4714a562d9 FIX: Poll requires logged in user to log in again
FIX: Open/Closing the poll wasn't updating the UI
REFACTOR: ES6 FTW
2015-03-03 16:17:07 +01:00

48 lines
1.2 KiB
JavaScript

import DiscourseController from 'discourse/controllers/controller';
export default DiscourseController.extend({
poll: null,
showResults: Em.computed.oneWay('poll.closed'),
disableRadio: Em.computed.any('poll.closed', 'loading'),
showToggleClosePoll: Em.computed.alias('poll.post.topic.details.can_edit'),
actions: {
selectOption(option) {
if (this.get('disableRadio')) {
return;
}
if (!this.get('postController.currentUser.id')) {
this.get('postController').send('showLogin');
return;
}
this.set('loading', true);
const self = this;
this.get('poll').saveVote(option).then(function() {
self.setProperties({ loading: false, showResults: true});
});
},
toggleShowResults() {
this.toggleProperty('showResults');
},
toggleClosePoll() {
const self = this;
this.set('loading', true);
return Discourse.ajax('/poll/toggle_close', {
type: 'PUT',
data: { post_id: this.get('poll.post.id') }
}).then(function(result) {
self.set('poll.post.topic.title', result.basic_topic.title);
self.set('poll.post.topic.fancy_title', result.basic_topic.title);
self.set('loading', false);
});
}
}
});