diff --git a/app/assets/javascripts/admin/models/site_setting.js b/app/assets/javascripts/admin/models/site_setting.js index 55f45e20ed5..5284c30437a 100644 --- a/app/assets/javascripts/admin/models/site_setting.js +++ b/app/assets/javascripts/admin/models/site_setting.js @@ -103,21 +103,25 @@ Discourse.SiteSetting = Discourse.Model.extend({ Discourse.SiteSetting.reopenClass({ - /** - Retrieve all settings from the server - - @method findAll - **/ findAll: function() { - var result = Em.A(); - Discourse.ajax("/admin/site_settings").then(function (settings) { + return Discourse.ajax("/admin/site_settings").then(function (settings) { + // Group the results by category + var categoryNames = [], + categories = {}, + result = Em.A(); _.each(settings.site_settings,function(s) { s.originalValue = s.value; - result.pushObject(Discourse.SiteSetting.create(s)); + if (!categoryNames.contains(s.category)) { + categoryNames.pushObject(s.category); + categories[s.category] = Em.A(); + } + categories[s.category].pushObject(Discourse.SiteSetting.create(s)); }); - result.set('diags', settings.diags); + _.each(categoryNames, function(n) { + result.pushObject({nameKey: n, name: I18n.t('admin.site_settings.categories.' + n),siteSettings: categories[n]}); + }); + return result; }); - return result; }, update: function(key, value) { @@ -126,6 +130,7 @@ Discourse.SiteSetting.reopenClass({ data: { value: value } }); } + }); diff --git a/app/assets/javascripts/admin/routes/admin_routes.js b/app/assets/javascripts/admin/routes/admin_routes.js index 58e39cf8170..11e2ece7af9 100644 --- a/app/assets/javascripts/admin/routes/admin_routes.js +++ b/app/assets/javascripts/admin/routes/admin_routes.js @@ -7,7 +7,9 @@ Discourse.Route.buildRoutes(function() { this.resource('admin', { path: '/admin' }, function() { this.route('dashboard', { path: '/' }); - this.route('site_settings', { path: '/site_settings' }); + this.resource('adminSiteSettings', { path: '/site_settings' }, function() { + this.resource('adminSiteSettingsCategory', { path: 'category/:category_id'} ); + }); this.resource('adminSiteContents', { path: '/site_contents' }, function() { diff --git a/app/assets/javascripts/admin/routes/admin_site_setting_category_route.js b/app/assets/javascripts/admin/routes/admin_site_setting_category_route.js new file mode 100644 index 00000000000..889be542d31 --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin_site_setting_category_route.js @@ -0,0 +1,18 @@ +/** + Handles routes related to viewing and editing site settings within one category. + + @class AdminSiteSettingCategoryRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.AdminSiteSettingsCategoryRoute = Discourse.Route.extend({ + model: function(params) { + var category = this.modelFor('adminSiteSettings').find(function(siteSettingCategory) { + return siteSettingCategory.nameKey === params.category_id; + }); + if (category) { + return category.siteSettings; + } + } +}); diff --git a/app/assets/javascripts/admin/routes/admin_site_settings_route.js b/app/assets/javascripts/admin/routes/admin_site_settings_route.js index 164bd6361a1..3dbe5ad1fae 100644 --- a/app/assets/javascripts/admin/routes/admin_site_settings_route.js +++ b/app/assets/javascripts/admin/routes/admin_site_settings_route.js @@ -11,3 +11,13 @@ Discourse.AdminSiteSettingsRoute = Discourse.Route.extend({ return Discourse.SiteSetting.findAll(); } }); + +/** + Handles when you click the Site Settings tab in admin, but haven't + chosen a category. It will redirect to the first category. +**/ +Discourse.AdminSiteSettingsIndexRoute = Discourse.Route.extend({ + model: function() { + this.transitionTo('adminSiteSettingsCategory', this.modelFor('adminSiteSettings')[0].nameKey); + } +}); \ No newline at end of file diff --git a/app/assets/javascripts/admin/templates/admin.js.handlebars b/app/assets/javascripts/admin/templates/admin.js.handlebars index 5a09dd52f3a..acb69cde5f2 100644 --- a/app/assets/javascripts/admin/templates/admin.js.handlebars +++ b/app/assets/javascripts/admin/templates/admin.js.handlebars @@ -5,7 +5,7 @@