Refactor some deprecations for newer versions of Ember. Also set up
injection for some globals so we can migrate away from them.
This commit is contained in:
parent
6e6819d57d
commit
af6936cf72
|
@ -28,11 +28,11 @@ export default Ember.ArrayController.extend({
|
|||
}
|
||||
}.property("status.isOperationRunning"),
|
||||
|
||||
readOnlyModeTitle: function() { return this._readOnlyModeI18n("title"); }.property("Discourse.isReadOnly"),
|
||||
readOnlyModeText: function() { return this._readOnlyModeI18n("text"); }.property("Discourse.isReadOnly"),
|
||||
readOnlyModeTitle: function() { return this._readOnlyModeI18n("title"); }.property("site.isReadOnly"),
|
||||
readOnlyModeText: function() { return this._readOnlyModeI18n("text"); }.property("site.isReadOnly"),
|
||||
|
||||
_readOnlyModeI18n: function(value) {
|
||||
var action = Discourse.get("isReadOnly") ? "disable" : "enable";
|
||||
var action = this.site.get("isReadOnly") ? "disable" : "enable";
|
||||
return I18n.t("admin.backups.read_only." + action + "." + value);
|
||||
},
|
||||
|
||||
|
@ -45,7 +45,7 @@ export default Ember.ArrayController.extend({
|
|||
**/
|
||||
toggleReadOnlyMode: function() {
|
||||
var self = this;
|
||||
if (!Discourse.get("isReadOnly")) {
|
||||
if (!this.site.get("isReadOnly")) {
|
||||
bootbox.confirm(
|
||||
I18n.t("admin.backups.read_only.enable.confirm"),
|
||||
I18n.t("no_value"),
|
||||
|
@ -65,11 +65,12 @@ export default Ember.ArrayController.extend({
|
|||
},
|
||||
|
||||
_toggleReadOnlyMode: function(enable) {
|
||||
var site = this.site;
|
||||
Discourse.ajax("/admin/backups/readonly", {
|
||||
type: "PUT",
|
||||
data: { enable: enable }
|
||||
}).then(function() {
|
||||
Discourse.set("isReadOnly", enable);
|
||||
site.set("isReadOnly", enable);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="container">
|
||||
{{Discourse.globalNotice}}
|
||||
{{global-notice}}
|
||||
<div class="row">
|
||||
<div class="full-width">
|
||||
|
||||
|
|
|
@ -132,38 +132,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||
}
|
||||
}
|
||||
return this.get("currentAssetVersion");
|
||||
}.property(),
|
||||
|
||||
globalNotice: function(){
|
||||
var notices = [];
|
||||
|
||||
if(this.get("isReadOnly")){
|
||||
notices.push(I18n.t("read_only_mode.enabled"));
|
||||
}
|
||||
|
||||
if(Discourse.User.currentProp('admin') && Discourse.SiteSettings.show_create_topics_notice) {
|
||||
var topic_count = 0,
|
||||
post_count = 0;
|
||||
_.each(Discourse.Site.currentProp('categories'), function(c) {
|
||||
if (!c.get('read_restricted')) {
|
||||
topic_count += c.get('topic_count');
|
||||
post_count += c.get('post_count');
|
||||
}
|
||||
});
|
||||
if (topic_count < 5 || post_count < Discourse.SiteSettings.tl1_requires_read_posts) {
|
||||
notices.push(I18n.t("too_few_topics_notice", {posts: Discourse.SiteSettings.tl1_requires_read_posts}));
|
||||
}
|
||||
}
|
||||
|
||||
if(!_.isEmpty(Discourse.SiteSettings.global_notice)){
|
||||
notices.push(Discourse.SiteSettings.global_notice);
|
||||
}
|
||||
|
||||
if(notices.length > 0) {
|
||||
return new Handlebars.SafeString(_.map(notices, function(text) {
|
||||
return "<div class='row'><div class='alert alert-info'>" + text + "</div></div>";
|
||||
}).join(""));
|
||||
}
|
||||
}.property("isReadOnly")
|
||||
}.property()
|
||||
|
||||
});
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
export default Ember.Component.extend({
|
||||
|
||||
shouldRerender: Discourse.View.renderIfChanged("site.isReadOnly"),
|
||||
|
||||
render: function(buffer) {
|
||||
var notices = [];
|
||||
|
||||
if (this.site.get("isReadOnly")) {
|
||||
notices.push(I18n.t("read_only_mode.enabled"));
|
||||
}
|
||||
|
||||
if (Discourse.User.currentProp('admin') && this.siteSettings.show_create_topics_notice) {
|
||||
var topic_count = 0,
|
||||
post_count = 0;
|
||||
_.each(this.site.get('categories'), function(c) {
|
||||
if (!c.get('read_restricted')) {
|
||||
topic_count += c.get('topic_count');
|
||||
post_count += c.get('post_count');
|
||||
}
|
||||
});
|
||||
if (topic_count < 5 || post_count < this.siteSettings.tl1_requires_read_posts) {
|
||||
notices.push(I18n.t("too_few_topics_notice", {posts: this.siteSettings.tl1_requires_read_posts}));
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isEmpty(this.siteSettings.global_notice)) {
|
||||
notices.push(this.siteSettings.global_notice);
|
||||
}
|
||||
|
||||
if (notices.length > 0) {
|
||||
buffer.push(_.map(notices, function(text) {
|
||||
return "<div class='row'><div class='alert alert-info'>" + text + "</div></div>";
|
||||
}).join(""));
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,6 +1,8 @@
|
|||
export default {
|
||||
name: "inject-app-events",
|
||||
name: "inject-objects",
|
||||
initialize: function(container, application) {
|
||||
|
||||
// Inject appEvents everywhere
|
||||
var appEvents = Ember.Object.createWithMixins(Ember.Evented);
|
||||
application.register('app-events:main', appEvents, { instantiate: false });
|
||||
|
||||
|
@ -9,7 +11,23 @@ export default {
|
|||
application.inject('route', 'appEvents', 'app-events:main');
|
||||
application.inject('view', 'appEvents', 'app-events:main');
|
||||
application.inject('model', 'appEvents', 'app-events:main');
|
||||
|
||||
Discourse.URL.appEvents = appEvents;
|
||||
|
||||
// Inject Discourse.Site to avoid using Discourse.Site.current()
|
||||
var site = Discourse.Site.current();
|
||||
application.register('site:main', site, { instantiate: false });
|
||||
application.inject('controller', 'site', 'site:main');
|
||||
application.inject('component', 'site', 'site:main');
|
||||
application.inject('route', 'site', 'site:main');
|
||||
application.inject('view', 'site', 'site:main');
|
||||
application.inject('model', 'site', 'site:main');
|
||||
|
||||
// Inject Discourse.SiteSettings to avoid using Discourse.SiteSettings globals
|
||||
application.register('site-settings:main', Discourse.SiteSettings, { instantiate: false });
|
||||
application.inject('controller', 'siteSettings', 'site-settings:main');
|
||||
application.inject('component', 'siteSettings', 'site-settings:main');
|
||||
application.inject('route', 'siteSettings', 'site-settings:main');
|
||||
application.inject('view', 'siteSettings', 'site-settings:main');
|
||||
application.inject('model', 'siteSettings', 'site-settings:main');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
export default {
|
||||
name: "inject-app-events",
|
||||
initialize: function(container, application) {
|
||||
var appEvents = Ember.Object.createWithMixins(Ember.Evented);
|
||||
application.register('app-events:main', appEvents, { instantiate: false });
|
||||
|
||||
application.inject('controller', 'appEvents', 'app-events:main');
|
||||
application.inject('component', 'appEvents', 'app-events:main');
|
||||
application.inject('route', 'appEvents', 'app-events:main');
|
||||
application.inject('view', 'appEvents', 'app-events:main');
|
||||
application.inject('model', 'appEvents', 'app-events:main');
|
||||
|
||||
Discourse.URL.appEvents = appEvents;
|
||||
}
|
||||
};
|
|
@ -6,13 +6,10 @@ export default {
|
|||
after: "message-bus",
|
||||
|
||||
initialize: function () {
|
||||
// initialize read-only mode and subscribe to updates via the message bus
|
||||
Discourse.set("isReadOnly", Discourse.Site.currentProp("is_readonly"));
|
||||
|
||||
if (!Discourse.MessageBus) { return; }
|
||||
|
||||
Discourse.MessageBus.subscribe("/site/read-only", function (enabled) {
|
||||
Discourse.set("isReadOnly", enabled);
|
||||
Discourse.Site.currentProp('isReadOnly', enabled);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
**/
|
||||
Discourse.Site = Discourse.Model.extend({
|
||||
|
||||
isReadOnly: Em.computed.alias('is_readonly'),
|
||||
|
||||
notificationLookup: function() {
|
||||
var result = [];
|
||||
_.each(this.get('notification_types'), function(v,k) {
|
||||
|
|
|
@ -41,7 +41,7 @@ var ApplicationRoute = Em.Route.extend({
|
|||
showLogin: function() {
|
||||
var self = this;
|
||||
|
||||
if (Discourse.get("isReadOnly")) {
|
||||
if (this.site.get("isReadOnly")) {
|
||||
bootbox.alert(I18n.t("read_only_mode.login_disabled"));
|
||||
} else {
|
||||
if(Discourse.SiteSettings.enable_sso) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class='container'>
|
||||
{{custom-html "top"}}
|
||||
{{Discourse.globalNotice}}
|
||||
{{global-notice}}
|
||||
{{discourse-banner user=currentUser banner=Discourse.banner}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class='container'>
|
||||
{{custom-html "top"}}
|
||||
{{Discourse.globalNotice}}
|
||||
{{global-notice}}
|
||||
{{discourse-banner user=currentUser banner=Discourse.banner overlay=view.hasScrolled}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class='container'>
|
||||
{{custom-html "top"}}
|
||||
{{Discourse.globalNotice}}
|
||||
{{global-notice}}
|
||||
</div>
|
||||
|
||||
{{#unless loading}}
|
||||
|
|
Loading…
Reference in New Issue