REFACTOR: Introduce `Discourse.computed.setting` to create a computed
property that links to a `Discourse.SiteSetting`
This commit is contained in:
parent
cdd2101e4f
commit
cf6cbb955b
|
@ -20,13 +20,8 @@ Discourse.AdminUserController = Discourse.ObjectController.extend({});
|
|||
Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
|
||||
editingTitle: false,
|
||||
|
||||
showApproval: function() {
|
||||
return Discourse.SiteSettings.must_approve_users;
|
||||
}.property(),
|
||||
|
||||
showBadges: function() {
|
||||
return Discourse.SiteSettings.enable_badges;
|
||||
}.property(),
|
||||
showApproval: Discourse.computed.setting('must_approve_users'),
|
||||
showBadges: Discourse.computed.setting('enable_badges'),
|
||||
|
||||
primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'),
|
||||
|
||||
|
|
|
@ -9,15 +9,8 @@ Discourse.HomeLogoComponent = Ember.Component.extend({
|
|||
return !Discourse.Mobile.mobileView && this.get("minimized");
|
||||
}.property("minimized"),
|
||||
|
||||
smallLogoUrl: function() {
|
||||
return Discourse.SiteSettings.logo_small_url;
|
||||
}.property(),
|
||||
smallLogoUrl: Discourse.computed.setting('logo_small_url'),
|
||||
bigLogoUrl: Discourse.computed.setting('logo_url'),
|
||||
title: Discourse.computed.setting('title'),
|
||||
|
||||
bigLogoUrl: function() {
|
||||
return Discourse.SiteSettings.logo_url;
|
||||
}.property(),
|
||||
|
||||
title: function() {
|
||||
return Discourse.SiteSettings.title;
|
||||
}.property()
|
||||
});
|
||||
|
|
|
@ -324,9 +324,7 @@ Discourse.CreateAccountController = Discourse.Controller.extend(Discourse.ModalF
|
|||
});
|
||||
},
|
||||
|
||||
tosAcceptRequired: function() {
|
||||
return Discourse.SiteSettings.tos_accept_required;
|
||||
}.property(),
|
||||
tosAcceptRequired: Discourse.computed.setting('tos_accept_required'),
|
||||
|
||||
actions: {
|
||||
createAccount: function() {
|
||||
|
|
|
@ -58,9 +58,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||
return false;
|
||||
}.property('saving', 'name', 'color', 'deleting'),
|
||||
|
||||
emailInEnabled: function() {
|
||||
return Discourse.SiteSettings.email_in;
|
||||
},
|
||||
emailInEnabled: Discourse.computed.setting('email_in'),
|
||||
|
||||
deleteDisabled: function() {
|
||||
return (this.get('deleting') || this.get('saving') || false);
|
||||
|
|
|
@ -20,9 +20,7 @@ Discourse.PosterExpansionController = Discourse.ObjectController.extend({
|
|||
|
||||
hasUserFilters: Em.computed.gt('postStream.userFilters.length', 0),
|
||||
|
||||
showBadges: function() {
|
||||
return Discourse.SiteSettings.enable_badges;
|
||||
}.property(),
|
||||
showBadges: Discourse.computed.setting('enable_badges'),
|
||||
|
||||
moreBadgesCount: function() {
|
||||
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
||||
|
|
|
@ -7,13 +7,9 @@
|
|||
@module Discourse
|
||||
**/
|
||||
Discourse.PreferencesController = Discourse.ObjectController.extend({
|
||||
allowAvatarUpload: function() {
|
||||
return Discourse.SiteSettings.allow_uploaded_avatars;
|
||||
}.property(),
|
||||
|
||||
allowUserLocale: function() {
|
||||
return Discourse.SiteSettings.allow_user_locale;
|
||||
}.property(),
|
||||
allowAvatarUpload: Discourse.computed.setting('allow_uploaded_avatars'),
|
||||
allowUserLocale: Discourse.computed.setting('allow_user_locale'),
|
||||
|
||||
selectedCategories: function(){
|
||||
return [].concat(this.get("watchedCategories"), this.get("trackedCategories"), this.get("mutedCategories"));
|
||||
|
@ -34,9 +30,7 @@ Discourse.PreferencesController = Discourse.ObjectController.extend({
|
|||
cannotDeleteAccount: Em.computed.not('can_delete_account'),
|
||||
deleteDisabled: Em.computed.or('saving', 'deleting', 'cannotDeleteAccount'),
|
||||
|
||||
canEditName: function() {
|
||||
return Discourse.SiteSettings.enable_names;
|
||||
}.property(),
|
||||
canEditName: Discourse.computed.setting('enable_names'),
|
||||
|
||||
canSelectTitle: function() {
|
||||
if (!Discourse.SiteSettings.enable_badges || this.get('model.badge_count') === 0) {
|
||||
|
|
|
@ -13,9 +13,7 @@ Discourse.SiteMapController = Ember.ArrayController.extend(Discourse.HasCurrentU
|
|||
return Discourse.SiteSettings.faq_url ? Discourse.SiteSettings.faq_url : Discourse.getURL('/faq');
|
||||
}.property(),
|
||||
|
||||
showMobileToggle: function() {
|
||||
return Discourse.SiteSettings.enable_mobile_theme;
|
||||
}.property(),
|
||||
showMobileToggle: Discourse.computed.setting('enable_mobile_theme'),
|
||||
|
||||
mobileViewLinkTextKey: function() {
|
||||
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view";
|
||||
|
|
|
@ -31,9 +31,7 @@ Discourse.UserInvitedController = Ember.ObjectController.extend({
|
|||
|
||||
@property maxInvites
|
||||
**/
|
||||
maxInvites: function() {
|
||||
return Discourse.SiteSettings.invites_shown;
|
||||
}.property(),
|
||||
maxInvites: Discourse.computed.setting('invites_shown'),
|
||||
|
||||
/**
|
||||
Can the currently logged in user invite users to the site
|
||||
|
|
|
@ -128,5 +128,19 @@ Discourse.computed = {
|
|||
if (typeof result !== "undefined" && result.toString() === defaultValue) { return; }
|
||||
return result;
|
||||
}).property(path);
|
||||
},
|
||||
|
||||
/**
|
||||
Creates a property from a SiteSetting. In the future the plan is for them to
|
||||
be able to update when changed.
|
||||
|
||||
@method setting
|
||||
@param {String} name of site setting
|
||||
**/
|
||||
setting: function(name) {
|
||||
return Ember.computed(function() {
|
||||
return Discourse.SiteSettings[name];
|
||||
}).property();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -10,6 +10,17 @@ module("Discourse.Computed", {
|
|||
}
|
||||
});
|
||||
|
||||
test("setting", function() {
|
||||
var t = Em.Object.extend({
|
||||
vehicle: Discourse.computed.setting('vehicle'),
|
||||
missingProp: Discourse.computed.setting('madeUpThing')
|
||||
}).create();
|
||||
|
||||
Discourse.SiteSettings.vehicle = "airplane";
|
||||
equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
|
||||
ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
|
||||
});
|
||||
|
||||
test("propertyEqual", function() {
|
||||
var t = Em.Object.extend({
|
||||
same: Discourse.computed.propertyEqual('cookies', 'biscuits')
|
||||
|
|
Loading…
Reference in New Issue