mirror of
https://github.com/discourse/discourse.git
synced 2025-03-22 03:55:43 +08:00
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({
|
Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
|
||||||
editingTitle: false,
|
editingTitle: false,
|
||||||
|
|
||||||
showApproval: function() {
|
showApproval: Discourse.computed.setting('must_approve_users'),
|
||||||
return Discourse.SiteSettings.must_approve_users;
|
showBadges: Discourse.computed.setting('enable_badges'),
|
||||||
}.property(),
|
|
||||||
|
|
||||||
showBadges: function() {
|
|
||||||
return Discourse.SiteSettings.enable_badges;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'),
|
primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'),
|
||||||
|
|
||||||
|
@ -9,15 +9,8 @@ Discourse.HomeLogoComponent = Ember.Component.extend({
|
|||||||
return !Discourse.Mobile.mobileView && this.get("minimized");
|
return !Discourse.Mobile.mobileView && this.get("minimized");
|
||||||
}.property("minimized"),
|
}.property("minimized"),
|
||||||
|
|
||||||
smallLogoUrl: function() {
|
smallLogoUrl: Discourse.computed.setting('logo_small_url'),
|
||||||
return Discourse.SiteSettings.logo_small_url;
|
bigLogoUrl: Discourse.computed.setting('logo_url'),
|
||||||
}.property(),
|
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() {
|
tosAcceptRequired: Discourse.computed.setting('tos_accept_required'),
|
||||||
return Discourse.SiteSettings.tos_accept_required;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
createAccount: function() {
|
createAccount: function() {
|
||||||
|
@ -58,9 +58,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
|
|||||||
return false;
|
return false;
|
||||||
}.property('saving', 'name', 'color', 'deleting'),
|
}.property('saving', 'name', 'color', 'deleting'),
|
||||||
|
|
||||||
emailInEnabled: function() {
|
emailInEnabled: Discourse.computed.setting('email_in'),
|
||||||
return Discourse.SiteSettings.email_in;
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteDisabled: function() {
|
deleteDisabled: function() {
|
||||||
return (this.get('deleting') || this.get('saving') || false);
|
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),
|
hasUserFilters: Em.computed.gt('postStream.userFilters.length', 0),
|
||||||
|
|
||||||
showBadges: function() {
|
showBadges: Discourse.computed.setting('enable_badges'),
|
||||||
return Discourse.SiteSettings.enable_badges;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
moreBadgesCount: function() {
|
moreBadgesCount: function() {
|
||||||
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
||||||
|
@ -7,13 +7,9 @@
|
|||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.PreferencesController = Discourse.ObjectController.extend({
|
Discourse.PreferencesController = Discourse.ObjectController.extend({
|
||||||
allowAvatarUpload: function() {
|
|
||||||
return Discourse.SiteSettings.allow_uploaded_avatars;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
allowUserLocale: function() {
|
allowAvatarUpload: Discourse.computed.setting('allow_uploaded_avatars'),
|
||||||
return Discourse.SiteSettings.allow_user_locale;
|
allowUserLocale: Discourse.computed.setting('allow_user_locale'),
|
||||||
}.property(),
|
|
||||||
|
|
||||||
selectedCategories: function(){
|
selectedCategories: function(){
|
||||||
return [].concat(this.get("watchedCategories"), this.get("trackedCategories"), this.get("mutedCategories"));
|
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'),
|
cannotDeleteAccount: Em.computed.not('can_delete_account'),
|
||||||
deleteDisabled: Em.computed.or('saving', 'deleting', 'cannotDeleteAccount'),
|
deleteDisabled: Em.computed.or('saving', 'deleting', 'cannotDeleteAccount'),
|
||||||
|
|
||||||
canEditName: function() {
|
canEditName: Discourse.computed.setting('enable_names'),
|
||||||
return Discourse.SiteSettings.enable_names;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
canSelectTitle: function() {
|
canSelectTitle: function() {
|
||||||
if (!Discourse.SiteSettings.enable_badges || this.get('model.badge_count') === 0) {
|
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');
|
return Discourse.SiteSettings.faq_url ? Discourse.SiteSettings.faq_url : Discourse.getURL('/faq');
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
showMobileToggle: function() {
|
showMobileToggle: Discourse.computed.setting('enable_mobile_theme'),
|
||||||
return Discourse.SiteSettings.enable_mobile_theme;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
mobileViewLinkTextKey: function() {
|
mobileViewLinkTextKey: function() {
|
||||||
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view";
|
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view";
|
||||||
|
@ -31,9 +31,7 @@ Discourse.UserInvitedController = Ember.ObjectController.extend({
|
|||||||
|
|
||||||
@property maxInvites
|
@property maxInvites
|
||||||
**/
|
**/
|
||||||
maxInvites: function() {
|
maxInvites: Discourse.computed.setting('invites_shown'),
|
||||||
return Discourse.SiteSettings.invites_shown;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Can the currently logged in user invite users to the site
|
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; }
|
if (typeof result !== "undefined" && result.toString() === defaultValue) { return; }
|
||||||
return result;
|
return result;
|
||||||
}).property(path);
|
}).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() {
|
test("propertyEqual", function() {
|
||||||
var t = Em.Object.extend({
|
var t = Em.Object.extend({
|
||||||
same: Discourse.computed.propertyEqual('cookies', 'biscuits')
|
same: Discourse.computed.propertyEqual('cookies', 'biscuits')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user