Set up poll plugin javascript using an Ember initializer.

This commit is contained in:
Vikhyat Korrapati 2014-05-18 13:36:27 +05:30
parent 55e5515657
commit 5cb2df8f09
3 changed files with 34 additions and 26 deletions

7
.gitignore vendored
View File

@ -40,9 +40,10 @@ config/discourse.conf
log/ log/
# Ignore plugins except for the bundled ones. # Ignore plugins except for the bundled ones.
/plugins /plugins/*
!/plugins/emoji !/plugins/emoji/
!/plugins/poll !/plugins/poll/
/plugins/*/auto_generated/
/spec/fixtures/plugins/my_plugin/auto_generated /spec/fixtures/plugins/my_plugin/auto_generated

View File

@ -1,3 +1,5 @@
import PollController from "discourse/plugins/poll/controllers/poll";
var Poll = Discourse.Model.extend({ var Poll = Discourse.Model.extend({
post: null, post: null,
options: [], options: [],
@ -41,8 +43,6 @@ var Poll = Discourse.Model.extend({
} }
}); });
var PollController = require("discourse/plugins/poll/controllers/poll").default;
var PollView = Ember.View.extend({ var PollView = Ember.View.extend({
templateName: "poll", templateName: "poll",
classNames: ['poll-ui'], classNames: ['poll-ui'],
@ -73,29 +73,36 @@ function initializePollView(self) {
return pollView; return pollView;
} }
Discourse.PostView.reopen({
createPollUI: function($post) {
var post = this.get('post');
if (!post.get('poll_details')) { export default {
return; name: 'poll',
}
var view = initializePollView(this); initialize: function() {
Discourse.PostView.reopen({
createPollUI: function($post) {
var post = this.get('post');
var pollContainer = $post.find(".poll-ui:first"); if (!post.get('poll_details')) {
if (pollContainer.length === 0) { return;
pollContainer = $post.find("ul:first"); }
}
view.replaceElement(pollContainer); var view = initializePollView(this);
this.set('pollView', view);
}.on('postViewInserted'), var pollContainer = $post.find(".poll-ui:first");
if (pollContainer.length === 0) {
pollContainer = $post.find("ul:first");
}
clearPollView: function() { view.replaceElement(pollContainer);
if (this.get('pollView')) { this.set('pollView', view);
this.get('pollView').destroy();
} }.on('postViewInserted'),
}.on('willClearRender')
}); clearPollView: function() {
if (this.get('pollView')) {
this.get('pollView').destroy();
}
}.on('willClearRender')
});
}
}

View File

@ -144,7 +144,7 @@ end
# Poll UI. # Poll UI.
register_asset "javascripts/controllers/poll.js.es6" register_asset "javascripts/controllers/poll.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/initializers/poll.js.es6"
register_asset "javascripts/poll_bbcode.js", :server_side register_asset "javascripts/poll_bbcode.js", :server_side
register_css <<CSS register_css <<CSS