diff --git a/app/assets/javascripts/discourse/controllers/static.js.es6 b/app/assets/javascripts/discourse/controllers/static.js.es6 new file mode 100644 index 000000000..0dd1f25b6 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/static.js.es6 @@ -0,0 +1,9 @@ +export default Em.ObjectController.extend({ + showLoginButton: Em.computed.equal('path', 'login'), + + actions: { + markFaqRead: function() { + Discourse.ajax("/users/read-faq", { method: "POST" }); + } + } +}); diff --git a/app/assets/javascripts/discourse/controllers/static_controller.js b/app/assets/javascripts/discourse/controllers/static_controller.js deleted file mode 100644 index 3be952f1b..000000000 --- a/app/assets/javascripts/discourse/controllers/static_controller.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - This controller supports displaying static content. - - @class StaticController - @extends Em.ObjectController - @namespace Discourse - @module Discourse -**/ - -Discourse.StaticController = Em.ObjectController.extend({ - showLoginButton: Em.computed.equal('path', 'login'), - - actions: { - markFaqRead: function() { - Discourse.ajax("/users/read-faq", { method: "POST" }); - } - } -}); - -Discourse.StaticController.reopenClass({ - PAGES: ['faq', 'tos', 'privacy', 'guidelines'], - CONFIGS: { - 'faq': 'faq_url', - 'tos': 'tos_url', - 'privacy': 'privacy_policy_url' - } -}); diff --git a/app/assets/javascripts/discourse/routes/static_route.js b/app/assets/javascripts/discourse/lib/static-route-builder.js.es6 similarity index 65% rename from app/assets/javascripts/discourse/routes/static_route.js rename to app/assets/javascripts/discourse/lib/static-route-builder.js.es6 index a6117316c..a1140f89a 100644 --- a/app/assets/javascripts/discourse/routes/static_route.js +++ b/app/assets/javascripts/discourse/lib/static-route-builder.js.es6 @@ -1,20 +1,17 @@ -/** - The routes used for rendering static content - - @class StaticRoute - @extends Discourse.Route - @namespace Discourse - @module Discourse -**/ -Discourse.StaticController.PAGES.forEach(function(page) { - Discourse[page.capitalize() + "Route"] = Discourse.Route.extend({ +var configs = { + 'faq': 'faq_url', + 'tos': 'tos_url', + 'privacy': 'privacy_policy_url' +}; +export default function(page) { + return Discourse.Route.extend({ renderTemplate: function() { this.render('static'); }, beforeModel: function(transition) { - var configKey = Discourse.StaticController.CONFIGS[page]; + var configKey = configs[page]; if (configKey && Discourse.SiteSettings[configKey].length > 0) { transition.abort(); Discourse.URL.redirectTo(Discourse.SiteSettings[configKey]); @@ -36,4 +33,5 @@ Discourse.StaticController.PAGES.forEach(function(page) { this.controllerFor('static').set('model', model); } }); -}); +} + diff --git a/app/assets/javascripts/discourse/models/static_page.js b/app/assets/javascripts/discourse/models/static_page.js index 1665d7327..708c4ae05 100644 --- a/app/assets/javascripts/discourse/models/static_page.js +++ b/app/assets/javascripts/discourse/models/static_page.js @@ -1,13 +1,4 @@ -/** - A model that repreesnts a static page in Discourse - - @class StaticPage - @extends Em.Object - @namespace Discourse - @module Discourse -**/ -Discourse.StaticPage = Em.Object.extend({ -}); +Discourse.StaticPage = Em.Object.extend(); Discourse.StaticPage.reopenClass({ find: function(path) { @@ -27,4 +18,3 @@ Discourse.StaticPage.reopenClass({ }); } }); - diff --git a/app/assets/javascripts/discourse/routes/application_routes.js b/app/assets/javascripts/discourse/routes/application_routes.js index 4cbbe7963..e081b665c 100644 --- a/app/assets/javascripts/discourse/routes/application_routes.js +++ b/app/assets/javascripts/discourse/routes/application_routes.js @@ -7,12 +7,6 @@ Discourse.Route.buildRoutes(function() { var router = this; - // Generate static page routes - // e.g., faq, tos, privacy, login - _.each(Discourse.StaticController.PAGES, function (page) { - router.route(page, { path: '/' + page }); - }); - // Error page this.route('exception', { path: '/exception' }); @@ -93,6 +87,10 @@ Discourse.Route.buildRoutes(function() { this.route('signup', {path: '/signup'}); this.route('login', {path: '/login'}); + this.route('faq', {path: '/faq'}); + this.route('tos', {path: '/tos'}); + this.route('privacy', {path: '/privacy'}); + this.route('guidelines', {path: '/guidelines'}); this.resource('badges', function() { this.route('show', {path: '/:id/:slug'}); diff --git a/app/assets/javascripts/discourse/routes/faq.js.es6 b/app/assets/javascripts/discourse/routes/faq.js.es6 new file mode 100644 index 000000000..9adadeba6 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/faq.js.es6 @@ -0,0 +1,3 @@ +import staticRouteBuilder from 'discourse/lib/static-route-builder'; + +export default staticRouteBuilder('faq'); diff --git a/app/assets/javascripts/discourse/routes/guidelines.js.es6 b/app/assets/javascripts/discourse/routes/guidelines.js.es6 new file mode 100644 index 000000000..0acbde03f --- /dev/null +++ b/app/assets/javascripts/discourse/routes/guidelines.js.es6 @@ -0,0 +1,3 @@ +import FaqRoute from 'discourse/routes/faq'; + +export default FaqRoute; diff --git a/app/assets/javascripts/discourse/routes/privacy.js.es6 b/app/assets/javascripts/discourse/routes/privacy.js.es6 new file mode 100644 index 000000000..92993fb6f --- /dev/null +++ b/app/assets/javascripts/discourse/routes/privacy.js.es6 @@ -0,0 +1,3 @@ +import staticRouteBuilder from 'discourse/lib/static-route-builder'; + +export default staticRouteBuilder('privacy'); diff --git a/app/assets/javascripts/discourse/routes/tos.js.es6 b/app/assets/javascripts/discourse/routes/tos.js.es6 new file mode 100644 index 000000000..df409addb --- /dev/null +++ b/app/assets/javascripts/discourse/routes/tos.js.es6 @@ -0,0 +1,3 @@ +import staticRouteBuilder from 'discourse/lib/static-route-builder'; + +export default staticRouteBuilder('tos');