From 8a24a34b1b2cb13bddf57c9bd9513a88f815e724 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 20 May 2014 12:49:25 -0400 Subject: [PATCH] ES6: More controllers --- .../controllers/navigation/categories.js.es6 | 3 +++ .../controllers/navigation/category.js.es6 | 8 ++++++ .../controllers/navigation/default.js.es6 | 17 +++++++++++++ .../navigation_default_controller.js | 25 ------------------- .../controllers/not-activated.js.es6 | 20 +++++++++++++++ .../controllers/not_activated_controller.js | 18 ------------- ...topic_controller.js => split-topic.js.es6} | 2 +- .../routes/discovery_categories_route.js | 4 +-- .../routes/discovery_route_builders.js | 8 +++--- .../discourse/routes/discovery_top_routes.js | 8 +++--- .../discourse/routes/topic_route.js | 2 +- app/assets/javascripts/main_include.js | 1 + 12 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 app/assets/javascripts/discourse/controllers/navigation/categories.js.es6 create mode 100644 app/assets/javascripts/discourse/controllers/navigation/category.js.es6 create mode 100644 app/assets/javascripts/discourse/controllers/navigation/default.js.es6 delete mode 100644 app/assets/javascripts/discourse/controllers/navigation_default_controller.js create mode 100644 app/assets/javascripts/discourse/controllers/not-activated.js.es6 delete mode 100644 app/assets/javascripts/discourse/controllers/not_activated_controller.js rename app/assets/javascripts/discourse/controllers/{split_topic_controller.js => split-topic.js.es6} (93%) diff --git a/app/assets/javascripts/discourse/controllers/navigation/categories.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/categories.js.es6 new file mode 100644 index 00000000000..bc7b489991c --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/navigation/categories.js.es6 @@ -0,0 +1,3 @@ +import NavigationDefaultController from 'discourse/controllers/navigation/default'; + +export default NavigationDefaultController.extend({}); diff --git a/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 new file mode 100644 index 00000000000..29596b84dc0 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 @@ -0,0 +1,8 @@ +import NavigationDefaultController from 'discourse/controllers/navigation/default'; + +export default NavigationDefaultController.extend({ + navItems: function() { + return Discourse.NavItem.buildList(this.get('category'), { noSubcategories: this.get('noSubcategories') }); + }.property('category', 'noSubcategories') +}); + diff --git a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 new file mode 100644 index 00000000000..84824c871cb --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 @@ -0,0 +1,17 @@ +/** + Handles the controller for the default navigation within discovery. + + @class NavigationDefaultController + @extends Discourse.Controller + @namespace Discourse + @module Discourse +**/ +export default Discourse.Controller.extend({ + categories: function() { + return Discourse.Category.list(); + }.property(), + + navItems: function() { + return Discourse.NavItem.buildList(); + }.property() +}); diff --git a/app/assets/javascripts/discourse/controllers/navigation_default_controller.js b/app/assets/javascripts/discourse/controllers/navigation_default_controller.js deleted file mode 100644 index 5d4e9760c76..00000000000 --- a/app/assets/javascripts/discourse/controllers/navigation_default_controller.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - Handles the controller for the default navigation within discovery. - - @class NavigationDefaultController - @extends Discourse.Controller - @namespace Discourse - @module Discourse -**/ -Discourse.NavigationDefaultController = Discourse.Controller.extend({ - categories: function() { - return Discourse.Category.list(); - }.property(), - - navItems: function() { - return Discourse.NavItem.buildList(); - }.property() -}); - -Discourse.NavigationCategoryController = Discourse.NavigationDefaultController.extend({ - navItems: function() { - return Discourse.NavItem.buildList(this.get('category'), { noSubcategories: this.get('noSubcategories') }); - }.property('category', 'noSubcategories') -}); - -Discourse.NavigationCategoriesController = Discourse.NavigationDefaultController.extend({}); diff --git a/app/assets/javascripts/discourse/controllers/not-activated.js.es6 b/app/assets/javascripts/discourse/controllers/not-activated.js.es6 new file mode 100644 index 00000000000..b6cb729badd --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/not-activated.js.es6 @@ -0,0 +1,20 @@ +/** + Modal displayed to a user when they are not active yet. + + @class NotActivatedController + @extends Discourse.Controller + @namespace Discourse + @uses Discourse.ModalFunctionality + @module Discourse +**/ +export default Discourse.Controller.extend(Discourse.ModalFunctionality, { + emailSent: false, + + actions: { + sendActivationEmail: function() { + Discourse.ajax('/users/' + this.get('username') + '/send_activation_email', {type: 'POST'}); + this.set('emailSent', true); + } + } + +}); diff --git a/app/assets/javascripts/discourse/controllers/not_activated_controller.js b/app/assets/javascripts/discourse/controllers/not_activated_controller.js deleted file mode 100644 index 5b529bd3dad..00000000000 --- a/app/assets/javascripts/discourse/controllers/not_activated_controller.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - Modal displayed to a user when they are not active yet. - - @class NotActivatedController - @extends Discourse.Controller - @namespace Discourse - @uses Discourse.ModalFunctionality - @module Discourse -**/ -Discourse.NotActivatedController = Discourse.Controller.extend(Discourse.ModalFunctionality, { - emailSent: false, - - sendActivationEmail: function() { - Discourse.ajax('/users/' + this.get('username') + '/send_activation_email', {type: 'POST'}); - this.set('emailSent', true); - } - -}); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/controllers/split_topic_controller.js b/app/assets/javascripts/discourse/controllers/split-topic.js.es6 similarity index 93% rename from app/assets/javascripts/discourse/controllers/split_topic_controller.js rename to app/assets/javascripts/discourse/controllers/split-topic.js.es6 index d8fae96d7f2..983f0e74cbf 100644 --- a/app/assets/javascripts/discourse/controllers/split_topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/split-topic.js.es6 @@ -7,7 +7,7 @@ @uses Discourse.ModalFunctionality @module Discourse **/ -Discourse.SplitTopicController = Discourse.ObjectController.extend(Discourse.SelectedPostsCount, Discourse.ModalFunctionality, { +export default Discourse.ObjectController.extend(Discourse.SelectedPostsCount, Discourse.ModalFunctionality, { needs: ['topic'], topicController: Em.computed.alias('controllers.topic'), diff --git a/app/assets/javascripts/discourse/routes/discovery_categories_route.js b/app/assets/javascripts/discourse/routes/discovery_categories_route.js index 42d2cfc78ef..82edf2971c2 100644 --- a/app/assets/javascripts/discourse/routes/discovery_categories_route.js +++ b/app/assets/javascripts/discourse/routes/discovery_categories_route.js @@ -13,7 +13,7 @@ Discourse.DiscoveryCategoriesRoute = Discourse.Route.extend({ }, beforeModel: function() { - this.controllerFor('navigationCategories').set('filterMode', 'categories'); + this.controllerFor('navigation/categories').set('filterMode', 'categories'); }, model: function() { @@ -34,7 +34,7 @@ Discourse.DiscoveryCategoriesRoute = Discourse.Route.extend({ setupController: function(controller, model) { controller.set('model', model); Discourse.set('title', I18n.t('filters.categories.title')); - this.controllerFor('navigationCategories').set('canCreateCategory', model.get('can_create_category')); + this.controllerFor('navigation/categories').set('canCreateCategory', model.get('can_create_category')); }, actions: { diff --git a/app/assets/javascripts/discourse/routes/discovery_route_builders.js b/app/assets/javascripts/discourse/routes/discovery_route_builders.js index 98c06b9c02d..0d2aa32279a 100644 --- a/app/assets/javascripts/discourse/routes/discovery_route_builders.js +++ b/app/assets/javascripts/discourse/routes/discovery_route_builders.js @@ -12,7 +12,7 @@ function buildTopicRoute(filter) { }, beforeModel: function() { - this.controllerFor('navigationDefault').set('filterMode', filter); + this.controllerFor('navigation/default').set('filterMode', filter); }, model: function(data, transaction) { @@ -73,7 +73,7 @@ function buildTopicRoute(filter) { } } - this.controllerFor('navigationDefault').set('canCreateTopic', model.get('can_create_topic')); + this.controllerFor('navigation/default').set('canCreateTopic', model.get('can_create_topic')); }, renderTemplate: function() { @@ -107,7 +107,7 @@ function buildCategoryRoute(filter, params) { var opts = { category: model, filterMode: filterMode }; opts.noSubcategories = params && params.no_subcategories; opts.canEditCategory = Discourse.User.currentProp('staff'); - this.controllerFor('navigationCategory').setProperties(opts); + this.controllerFor('navigation/category').setProperties(opts); return Discourse.TopicList.list(listFilter, params).then(function(list) { var tracking = Discourse.TopicTrackingState.current(); @@ -130,7 +130,7 @@ function buildCategoryRoute(filter, params) { Discourse.set('title', I18n.t('filters.with_category', { filter: filterText, category: model.get('name').capitalize() })); - this.controllerFor('navigationCategory').set('canCreateTopic', topics.get('can_create_topic')); + this.controllerFor('navigation/category').set('canCreateTopic', topics.get('can_create_topic')); this.controllerFor('discovery/topics').setProperties({ model: topics, category: model, diff --git a/app/assets/javascripts/discourse/routes/discovery_top_routes.js b/app/assets/javascripts/discourse/routes/discovery_top_routes.js index ede068388b8..118f1f3f75f 100644 --- a/app/assets/javascripts/discourse/routes/discovery_top_routes.js +++ b/app/assets/javascripts/discourse/routes/discovery_top_routes.js @@ -8,7 +8,7 @@ **/ Discourse.DiscoveryTopRoute = Discourse.Route.extend(Discourse.OpenComposer, { beforeModel: function() { - this.controllerFor('navigationDefault').set('filterMode', 'top'); + this.controllerFor('navigation/default').set('filterMode', 'top'); }, model: function() { @@ -19,7 +19,7 @@ Discourse.DiscoveryTopRoute = Discourse.Route.extend(Discourse.OpenComposer, { var filterText = I18n.t('filters.top.title'); Discourse.set('title', I18n.t('filters.with_topics', {filter: filterText})); this.controllerFor('discovery/top').setProperties({ model: model, category: null }); - this.controllerFor('navigationDefault').set('canCreateTopic', model.get('can_create_topic')); + this.controllerFor('navigation/default').set('canCreateTopic', model.get('can_create_topic')); // If there's a draft, open the create topic composer if (model.draft) { @@ -70,7 +70,7 @@ Discourse.DiscoveryTopCategoryRoute = Discourse.Route.extend(Discourse.OpenCompo var opts = { category: model, filterMode: filterMode }; opts.noSubcategories = noSubcategories; opts.canEditCategory = Discourse.User.currentProp('staff'); - this.controllerFor('navigationCategory').setProperties(opts); + this.controllerFor('navigation/category').setProperties(opts); return Discourse.TopList.find(filterMode).then(function(list) { // If all the categories are the same, we can hide them @@ -89,7 +89,7 @@ Discourse.DiscoveryTopCategoryRoute = Discourse.Route.extend(Discourse.OpenCompo var topList = this.get('topList'); var filterText = I18n.t('filters.top.title'); Discourse.set('title', I18n.t('filters.with_category', {filter: filterText, category: model.get('name').capitalize()})); - this.controllerFor('navigationCategory').set('canCreateTopic', topList.get('can_create_topic')); + this.controllerFor('navigation/category').set('canCreateTopic', topList.get('can_create_topic')); this.controllerFor('discovery/top').setProperties({ model: topList, category: model, diff --git a/app/assets/javascripts/discourse/routes/topic_route.js b/app/assets/javascripts/discourse/routes/topic_route.js index 247f7b039a9..5f74ea772a6 100644 --- a/app/assets/javascripts/discourse/routes/topic_route.js +++ b/app/assets/javascripts/discourse/routes/topic_route.js @@ -69,7 +69,7 @@ Discourse.TopicRoute = Discourse.Route.extend({ }, splitTopic: function() { - Discourse.Route.showModal(this, 'splitTopic', this.modelFor('topic')); + Discourse.Route.showModal(this, 'split-topic', this.modelFor('topic')); }, changeOwner: function() { diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index 273d9b88ea8..14f912ef239 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -18,6 +18,7 @@ //= require ./discourse/models/composer //= require ./discourse/controllers/controller //= require ./discourse/controllers/object_controller +//= require ./discourse/controllers/navigation/default //= require ./discourse/views/modal/modal_body_view //= require ./discourse/views/modal/flag_view //= require ./discourse/views/combobox_view