From b9e15a240f04491729fd33657eead86417865d48 Mon Sep 17 00:00:00 2001
From: Vikhyat Korrapati <vikhyatk@gmail.com>
Date: Thu, 15 May 2014 23:44:30 +0530
Subject: [PATCH 1/2] Allow registering ES6 modules from plugins.

---
 lib/plugin/instance.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb
index 297726f779d..55fffea1147 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -212,7 +212,7 @@ class Plugin::Instance
 
   def register_assets!
     assets.each do |asset, opts|
-      if asset =~ /\.js$|\.js\.erb$/
+      if asset =~ /\.js$|\.js\.erb$|\.js\.es6$/
         if opts == :admin
           DiscoursePluginRegistry.admin_javascripts << asset
         else

From a0b7637f5ead53d268cae4fa7b6dc8ebd7c20320 Mon Sep 17 00:00:00 2001
From: Vikhyat Korrapati <vikhyatk@gmail.com>
Date: Thu, 15 May 2014 23:54:53 +0530
Subject: [PATCH 2/2] Extract poll plugin controller into an ES6 module.

---
 .../assets/javascripts/poll-controller.js.es6 | 44 +++++++++++++++++++
 plugins/poll/assets/javascripts/poll_ui.js    | 44 +------------------
 plugins/poll/plugin.rb                        |  1 +
 3 files changed, 46 insertions(+), 43 deletions(-)
 create mode 100644 plugins/poll/assets/javascripts/poll-controller.js.es6

diff --git a/plugins/poll/assets/javascripts/poll-controller.js.es6 b/plugins/poll/assets/javascripts/poll-controller.js.es6
new file mode 100644
index 00000000000..5deef83b3b3
--- /dev/null
+++ b/plugins/poll/assets/javascripts/poll-controller.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));
+    }
+  }
+});
+
diff --git a/plugins/poll/assets/javascripts/poll_ui.js b/plugins/poll/assets/javascripts/poll_ui.js
index 81ebc3767d1..7f2362e52e5 100644
--- a/plugins/poll/assets/javascripts/poll_ui.js
+++ b/plugins/poll/assets/javascripts/poll_ui.js
@@ -41,49 +41,7 @@ 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'),
-  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 PollController = require("javascripts/poll-controller").default;
 
 var PollView = Ember.View.extend({
   templateName: "poll",
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index fddf8251617..14f576dabb2 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -142,6 +142,7 @@ after_initialize do
 end
 
 # Poll UI.
+register_asset "javascripts/poll-controller.js.es6"
 register_asset "javascripts/discourse/templates/poll.js.handlebars"
 register_asset "javascripts/poll_ui.js"
 register_asset "javascripts/poll_bbcode.js", :server_side