Convert a lot of Globals to ES6 modules
This commit is contained in:
parent
124f47529a
commit
f42a5c1ba3
|
@ -4,15 +4,8 @@
|
||||||
@param hexValue is a reference to the color's hex value.
|
@param hexValue is a reference to the color's hex value.
|
||||||
@param brightnessValue is a number from 0 to 255 representing the brightness of the color. See ColorSchemeColor.
|
@param brightnessValue is a number from 0 to 255 representing the brightness of the color. See ColorSchemeColor.
|
||||||
@params valid is a boolean indicating if the input field is a valid color.
|
@params valid is a boolean indicating if the input field is a valid color.
|
||||||
|
|
||||||
@class Discourse.ColorInputComponent
|
|
||||||
@extends Ember.Component
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
**/
|
||||||
Discourse.ColorInputComponent = Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
layoutName: 'components/color-input',
|
|
||||||
|
|
||||||
hexValueChanged: function() {
|
hexValueChanged: function() {
|
||||||
var hex = this.get('hexValue');
|
var hex = this.get('hexValue');
|
||||||
if (this.get('valid')) {
|
if (this.get('valid')) {
|
||||||
|
@ -22,11 +15,10 @@ Discourse.ColorInputComponent = Ember.Component.extend({
|
||||||
}
|
}
|
||||||
}.observes('hexValue', 'brightnessValue', 'valid'),
|
}.observes('hexValue', 'brightnessValue', 'valid'),
|
||||||
|
|
||||||
didInsertElement: function() {
|
_triggerHexChanged: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this._super();
|
|
||||||
Em.run.schedule('afterRender', function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
self.hexValueChanged();
|
self.hexValueChanged();
|
||||||
});
|
});
|
||||||
}
|
}.on('didInsertElement')
|
||||||
});
|
});
|
|
@ -3,16 +3,8 @@
|
||||||
|
|
||||||
@param settingValue is a reference to SiteSetting.value.
|
@param settingValue is a reference to SiteSetting.value.
|
||||||
@param choices is a reference to SiteSetting.choices
|
@param choices is a reference to SiteSetting.choices
|
||||||
|
|
||||||
@class Discourse.ListSettingComponent
|
|
||||||
@extends Ember.Component
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
**/
|
||||||
|
export default Ember.Component.extend({
|
||||||
Discourse.ListSettingComponent = Ember.Component.extend({
|
|
||||||
tagName: 'div',
|
|
||||||
|
|
||||||
|
|
||||||
_select2FormatSelection: function(selectedObject, jqueryWrapper, htmlEscaper) {
|
_select2FormatSelection: function(selectedObject, jqueryWrapper, htmlEscaper) {
|
||||||
var text = selectedObject.text;
|
var text = selectedObject.text;
|
||||||
|
@ -22,9 +14,8 @@ Discourse.ListSettingComponent = Ember.Component.extend({
|
||||||
return htmlEscaper(text);
|
return htmlEscaper(text);
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement: function(){
|
_initializeSelect2: function(){
|
||||||
|
var options = {
|
||||||
var select2_options = {
|
|
||||||
multiple: false,
|
multiple: false,
|
||||||
separator: "|",
|
separator: "|",
|
||||||
tokenSeparators: ["|"],
|
tokenSeparators: ["|"],
|
||||||
|
@ -35,24 +26,27 @@ Discourse.ListSettingComponent = Ember.Component.extend({
|
||||||
|
|
||||||
var settingName = this.get('settingName');
|
var settingName = this.get('settingName');
|
||||||
if (typeof settingName === 'string' && settingName.indexOf('colors') > -1) {
|
if (typeof settingName === 'string' && settingName.indexOf('colors') > -1) {
|
||||||
select2_options.formatSelection = this._select2FormatSelection;
|
options.formatSelection = this._select2FormatSelection;
|
||||||
}
|
}
|
||||||
this.$("input").select2(select2_options).on("change", function(obj) {
|
|
||||||
this.set("settingValue", obj.val.join("|"));
|
var self = this;
|
||||||
this.refreshSortables();
|
this.$("input").select2(options).on("change", function(obj) {
|
||||||
}.bind(this));
|
self.set("settingValue", obj.val.join("|"));
|
||||||
|
self.refreshSortables();
|
||||||
|
});
|
||||||
|
|
||||||
this.refreshSortables();
|
this.refreshSortables();
|
||||||
},
|
}.on('didInsertElement'),
|
||||||
|
|
||||||
refreshOnReset: function() {
|
refreshOnReset: function() {
|
||||||
this.$("input").select2("val", this.get("settingValue").split("|"));
|
this.$("input").select2("val", this.get("settingValue").split("|"));
|
||||||
}.observes("settingValue"),
|
}.observes("settingValue"),
|
||||||
|
|
||||||
refreshSortables: function() {
|
refreshSortables: function() {
|
||||||
|
var self = this;
|
||||||
this.$("ul.select2-choices").sortable().on('sortupdate', function() {
|
this.$("ul.select2-choices").sortable().on('sortupdate', function() {
|
||||||
this.$("input").select2("onSortEnd");
|
self.$("input").select2("onSortEnd");
|
||||||
}.bind(this));
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,12 +53,13 @@ export default Ember.ArrayController.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
rejectUsers: function() {
|
rejectUsers: function() {
|
||||||
|
var maxPostAge = this.siteSettings.delete_user_max_post_age;
|
||||||
var controller = this;
|
var controller = this;
|
||||||
Discourse.AdminUser.bulkReject(this.get('model').filterProperty('selected')).then(function(result){
|
Discourse.AdminUser.bulkReject(this.get('model').filterProperty('selected')).then(function(result){
|
||||||
var message = I18n.t("admin.users.reject_successful", {count: result.success});
|
var message = I18n.t("admin.users.reject_successful", {count: result.success});
|
||||||
if (result.failed > 0) {
|
if (result.failed > 0) {
|
||||||
message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed});
|
message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed});
|
||||||
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age});
|
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: maxPostAge});
|
||||||
}
|
}
|
||||||
bootbox.alert(message);
|
bootbox.alert(message);
|
||||||
controller._refreshUsers();
|
controller._refreshUsers();
|
||||||
|
|
|
@ -2,6 +2,6 @@ import DiscourseController from 'discourse/controllers/controller';
|
||||||
|
|
||||||
export default DiscourseController.extend({
|
export default DiscourseController.extend({
|
||||||
showBadges: function() {
|
showBadges: function() {
|
||||||
return this.get('currentUser.admin') && Discourse.SiteSettings.enable_badges;
|
return this.get('currentUser.admin') && this.siteSettings.enable_badges;
|
||||||
}.property()
|
}.property()
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
/**
|
|
||||||
Handles the default admin route
|
|
||||||
|
|
||||||
@class AdminDashboardRoute
|
|
||||||
@extends Discourse.Route
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
|
|
||||||
setupController: function(c) {
|
setupController: function(c) {
|
||||||
|
@ -16,8 +7,9 @@ export default Discourse.Route.extend({
|
||||||
fetchDashboardData: function(c) {
|
fetchDashboardData: function(c) {
|
||||||
if( !c.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > c.get('dashboardFetchedAt') ) {
|
if( !c.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > c.get('dashboardFetchedAt') ) {
|
||||||
c.set('dashboardFetchedAt', new Date());
|
c.set('dashboardFetchedAt', new Date());
|
||||||
|
var versionChecks = this.siteSettings.version_checks;
|
||||||
Discourse.AdminDashboard.find().then(function(d) {
|
Discourse.AdminDashboard.find().then(function(d) {
|
||||||
if( Discourse.SiteSettings.version_checks ){
|
if (versionChecks) {
|
||||||
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
|
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
|
||||||
}
|
}
|
||||||
_.each(d.reports,function(report){
|
_.each(d.reports,function(report){
|
||||||
|
|
|
@ -22,9 +22,10 @@ export default Ember.Component.extend({
|
||||||
ratioText: function() {
|
ratioText: function() {
|
||||||
var ratio = this.get('ratio');
|
var ratio = this.get('ratio');
|
||||||
|
|
||||||
if (ratio > Discourse.SiteSettings.topic_post_like_heat_high) { return 'high'; }
|
var settings = this.siteSettings;
|
||||||
if (ratio > Discourse.SiteSettings.topic_post_like_heat_medium) { return 'med'; }
|
if (ratio > settings.topic_post_like_heat_high) { return 'high'; }
|
||||||
if (ratio > Discourse.SiteSettings.topic_post_like_heat_low) { return 'low'; }
|
if (ratio > settings.topic_post_like_heat_medium) { return 'med'; }
|
||||||
|
if (ratio > settings.topic_post_like_heat_low) { return 'low'; }
|
||||||
return '';
|
return '';
|
||||||
}.property('ratio'),
|
}.property('ratio'),
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
/**
|
// Append our CSRF token to AJAX requests when necessary.
|
||||||
Append our CSRF token to AJAX requests when necessary.
|
|
||||||
**/
|
|
||||||
export default {
|
export default {
|
||||||
name: "csrf-token",
|
name: "csrf-token",
|
||||||
initialize: function() {
|
after: 'inject-objects',
|
||||||
var session = Discourse.Session;
|
initialize: function(container) {
|
||||||
|
|
||||||
|
var session = container.lookup('session:main');
|
||||||
|
|
||||||
// Add a CSRF token to all AJAX requests
|
// Add a CSRF token to all AJAX requests
|
||||||
session.currentProp('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
session.set('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
||||||
|
|
||||||
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
||||||
if (!options.crossDomain) {
|
if (!options.crossDomain) {
|
||||||
xhr.setRequestHeader('X-CSRF-Token', session.currentProp('csrfToken'));
|
xhr.setRequestHeader('X-CSRF-Token', session.get('csrfToken'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import Session from 'discourse/models/session';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "inject-objects",
|
name: "inject-objects",
|
||||||
initialize: function(container, application) {
|
initialize: function(container, application) {
|
||||||
|
@ -29,5 +31,13 @@ export default {
|
||||||
application.inject('route', 'siteSettings', 'site-settings:main');
|
application.inject('route', 'siteSettings', 'site-settings:main');
|
||||||
application.inject('view', 'siteSettings', 'site-settings:main');
|
application.inject('view', 'siteSettings', 'site-settings:main');
|
||||||
application.inject('model', 'siteSettings', 'site-settings:main');
|
application.inject('model', 'siteSettings', 'site-settings:main');
|
||||||
|
|
||||||
|
// Inject Session for transient data
|
||||||
|
application.register('session:main', Session.current(), { instantiate: false });
|
||||||
|
application.inject('controller', 'session', 'session:main');
|
||||||
|
application.inject('component', 'session', 'session:main');
|
||||||
|
application.inject('route', 'session', 'session:main');
|
||||||
|
application.inject('view', 'session', 'session:main');
|
||||||
|
application.inject('model', 'session', 'session:main');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
/**
|
|
||||||
A data model representing current session data. You can put transient
|
|
||||||
data here you might want later. It is not stored or serialized anywhere.
|
|
||||||
|
|
||||||
@class Session
|
|
||||||
@extends Discourse.Model
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.Session = Discourse.Model.extend({
|
|
||||||
init: function() {
|
|
||||||
this.set('highestSeenByTopic', {});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Discourse.Session.reopenClass(Discourse.Singleton);
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// A data model representing current session data. You can put transient
|
||||||
|
// data here you might want later. It is not stored or serialized anywhere.
|
||||||
|
var Session = Discourse.Model.extend({
|
||||||
|
init: function() {
|
||||||
|
this.set('highestSeenByTopic', {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Session.reopenClass(Discourse.Singleton);
|
||||||
|
|
||||||
|
export default Session;
|
|
@ -24,7 +24,7 @@ Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse
|
||||||
|
|
||||||
loadingComplete: function() {
|
loadingComplete: function() {
|
||||||
this.controllerFor('discovery').set('loading', false);
|
this.controllerFor('discovery').set('loading', false);
|
||||||
if (!Discourse.Session.currentProp('topicListScrollPosition')) {
|
if (!this.session.get('topicListScrollPosition')) {
|
||||||
this._scrollTop();
|
this._scrollTop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -172,7 +172,7 @@ var TopicRoute = Discourse.Route.extend(ShowFooter, {
|
||||||
isTransitioning = false;
|
isTransitioning = false;
|
||||||
|
|
||||||
var topic = this.modelFor('topic');
|
var topic = this.modelFor('topic');
|
||||||
Discourse.Session.currentProp('lastTopicIdViewed', parseInt(topic.get('id'), 10));
|
this.session.set('lastTopicIdViewed', parseInt(topic.get('id'), 10));
|
||||||
this.controllerFor('search').set('searchContext', topic.get('searchContext'));
|
this.controllerFor('search').set('searchContext', topic.get('searchContext'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default Discourse.View.extend(LoadMore, UrlRefresh, {
|
||||||
},
|
},
|
||||||
|
|
||||||
_readjustScrollPosition: function() {
|
_readjustScrollPosition: function() {
|
||||||
var scrollTo = Discourse.Session.currentProp('topicListScrollPosition');
|
var scrollTo = this.session.get('topicListScrollPosition');
|
||||||
|
|
||||||
if (typeof scrollTo !== "undefined") {
|
if (typeof scrollTo !== "undefined") {
|
||||||
Em.run.schedule('afterRender', function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
|
@ -35,7 +35,7 @@ export default Discourse.View.extend(LoadMore, UrlRefresh, {
|
||||||
|
|
||||||
// Remember where we were scrolled to
|
// Remember where we were scrolled to
|
||||||
saveScrollPosition: function() {
|
saveScrollPosition: function() {
|
||||||
Discourse.Session.current().set('topicListScrollPosition', $(window).scrollTop());
|
this.session.set('topicListScrollPosition', $(window).scrollTop());
|
||||||
},
|
},
|
||||||
|
|
||||||
// When the topic list is scrolled
|
// When the topic list is scrolled
|
||||||
|
|
|
@ -17,11 +17,9 @@ export default Discourse.GroupedView.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_highlightIfNeeded: function() {
|
_highlightIfNeeded: function() {
|
||||||
var session = Discourse.Session.current();
|
|
||||||
|
|
||||||
// highlight the last topic viewed
|
// highlight the last topic viewed
|
||||||
if (session.get('lastTopicIdViewed') === this.get('content.id')) {
|
if (this.session.get('lastTopicIdViewed') === this.get('content.id')) {
|
||||||
session.set('lastTopicIdViewed', null);
|
this.session.set('lastTopicIdViewed', null);
|
||||||
this.highlight();
|
this.highlight();
|
||||||
} else if (this.get('content.highlight')) {
|
} else if (this.get('content.highlight')) {
|
||||||
// highlight new topics that have been loaded from the server or the one we just created
|
// highlight new topics that have been loaded from the server or the one we just created
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import Session from "discourse/models/session";
|
||||||
|
|
||||||
module("Discourse.Session");
|
module("Discourse.Session");
|
||||||
|
|
||||||
test('highestSeenByTopic', function() {
|
test('highestSeenByTopic', function() {
|
||||||
var session = Discourse.Session.current();
|
var session = Session.current();
|
||||||
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
|
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue