mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
Extract poll plugin controller into an ES6 module.
This commit is contained in:
44
plugins/poll/assets/javascripts/poll-controller.js.es6
Normal file
44
plugins/poll/assets/javascripts/poll-controller.js.es6
Normal file
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -41,49 +41,7 @@ var Poll = Discourse.Model.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var PollController = Discourse.Controller.extend({
|
var PollController = require("javascripts/poll-controller").default;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var PollView = Ember.View.extend({
|
var PollView = Ember.View.extend({
|
||||||
templateName: "poll",
|
templateName: "poll",
|
||||||
|
@ -142,6 +142,7 @@ after_initialize do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Poll UI.
|
# Poll UI.
|
||||||
|
register_asset "javascripts/poll-controller.js.es6"
|
||||||
register_asset "javascripts/discourse/templates/poll.js.handlebars"
|
register_asset "javascripts/discourse/templates/poll.js.handlebars"
|
||||||
register_asset "javascripts/poll_ui.js"
|
register_asset "javascripts/poll_ui.js"
|
||||||
register_asset "javascripts/poll_bbcode.js", :server_side
|
register_asset "javascripts/poll_bbcode.js", :server_side
|
||||||
|
Reference in New Issue
Block a user