diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 58072742843..0b3d018cbbc 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -73,11 +73,14 @@ Discourse = Ember.Application.createWithMixins({ user.set('unread_notifications', data.unread_notifications); user.set('unread_private_messages', data.unread_private_messages); }), user.notification_channel_position); + bus.subscribe("/categories", function(data){ - Discourse.get('site').set('categories', data.categories.map(function(c){ - return Discourse.Category.create(c); - })); + var site = Discourse.Site.instance(); + data.categories.each(function(c){ + site.updateCategory(c) + }); }); + } }.observes('currentUser'), diff --git a/app/assets/javascripts/discourse/models/archetype.js b/app/assets/javascripts/discourse/models/archetype.js index 0ff2cb78d25..dd6f07b0051 100644 --- a/app/assets/javascripts/discourse/models/archetype.js +++ b/app/assets/javascripts/discourse/models/archetype.js @@ -13,9 +13,9 @@ Discourse.Archetype = Discourse.Model.extend({ return this.get('options').length > 0; }).property('options.@each'), - isDefault: (function() { - return this.get('id') === Discourse.get('site.default_archetype'); - }).property('id') + isDefault: function() { + return this.get('id') === Discourse.Site.instance().get('default_archetype'); + }.property('id') }); diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index 24db481ed85..96a995c5dd9 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -70,6 +70,11 @@ Discourse.Category = Discourse.Model.extend({ }); Discourse.Category.reopenClass({ + + list: function() { + return Discourse.Site.instance().get('categories'); + }, + findBySlugOrId: function(slugOrId) { return Discourse.ajax("/categories/" + slugOrId + ".json").then(function (result) { return Discourse.Category.create(result.category); diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index e4d7d51590b..c4a287379b6 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -22,15 +22,18 @@ EDIT = 'edit'; REPLY_AS_NEW_TOPIC_KEY = "reply_as_new_topic"; Discourse.Composer = Discourse.Model.extend({ - archetypesBinding: 'Discourse.site.archetypes', init: function() { this._super(); var val = Discourse.KeyValueStore.get('composer.showPreview') || 'true'; this.set('showPreview', val === 'true'); - this.set('archetypeId', Discourse.get('site.default_archetype')); + this.set('archetypeId', Discourse.Site.instance().get('default_archetype')); }, + archetypes: function() { + return Discourse.Site.instance().get('archetypes'); + }.property(), + creatingTopic: function() { return this.get('action') === CREATE_TOPIC; }.property('action'), @@ -238,7 +241,7 @@ Discourse.Composer = Discourse.Model.extend({ } this.set('categoryName', opts.categoryName || this.get('topic.category.name')); - this.set('archetypeId', opts.archetypeId || Discourse.get('site.default_archetype')); + this.set('archetypeId', opts.archetypeId || Discourse.Site.instance().get('default_archetype')); this.set('metaData', opts.metaData ? Em.Object.create(opts.metaData) : null); this.set('reply', opts.reply || this.get("reply") || ""); if (opts.postId) { @@ -354,7 +357,7 @@ Discourse.Composer = Discourse.Model.extend({ user_id: currentUser.get('id'), metaData: this.get('metaData'), archetype: this.get('archetypeId'), - post_type: Discourse.get('site.post_types.regular'), + post_type: Discourse.Site.instance().get('post_types.regular'), target_usernames: this.get('targetUsernames'), actions_summary: Em.A(), moderator: currentUser.get('moderator'), diff --git a/app/assets/javascripts/discourse/models/notification.js b/app/assets/javascripts/discourse/models/notification.js index 2c44f40acdc..d1360772604 100644 --- a/app/assets/javascripts/discourse/models/notification.js +++ b/app/assets/javascripts/discourse/models/notification.js @@ -19,8 +19,7 @@ Discourse.Notification = Discourse.Model.extend({ }.property(), rendered: function() { - var notificationName; - notificationName = Discourse.get('site.notificationLookup')[this.notification_type]; + var notificationName = Discourse.Site.instance().get('notificationLookup')[this.notification_type]; return Em.String.i18n("notifications." + notificationName, { username: this.data.display_username, link: "" + this.data.topic_title + "" diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index be63fd05ab4..fcd2251626f 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -124,7 +124,7 @@ Discourse.Post = Discourse.Model.extend({ flagsAvailable: function() { var _this = this; - var flags = Discourse.get('site.flagTypes').filter(function(item) { + var flags = Discourse.Site.instance().get('flagTypes').filter(function(item) { return _this.get("actionByName." + (item.get('name_key')) + ".can_act"); }); return flags; @@ -153,7 +153,7 @@ Discourse.Post = Discourse.Model.extend({ } }).then(function(result) { // If we received a category update, update it - if (result.category) Discourse.get('site').updateCategory(result.category); + if (result.category) Discourse.Site.instance().updateCategory(result.category); if (complete) complete(Discourse.Post.create(result.post)); }, function(result) { // Post failed to update diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js index 8f6e987599c..4ad9877cfb3 100644 --- a/app/assets/javascripts/discourse/models/site.js +++ b/app/assets/javascripts/discourse/models/site.js @@ -8,21 +8,17 @@ **/ Discourse.Site = Discourse.Model.extend({ - notificationLookup: (function() { - var result; - result = []; + notificationLookup: function() { + var result = []; Object.keys(this.get('notification_types'), function(k, v) { result[v] = k; }); return result; - }).property('notification_types'), + }.property('notification_types'), flagTypes: function() { - var postActionTypes; - postActionTypes = this.get('post_action_types'); - if (!postActionTypes) { - return []; - } + var postActionTypes = this.get('post_action_types'); + if (!postActionTypes) return []; return postActionTypes.filterProperty('is_flag', true); }.property('post_action_types.@each'), diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 9ba308645c6..d7e1a269644 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -130,9 +130,9 @@ Discourse.Topic = Discourse.Model.extend({ return null; }.property('views'), - archetypeObject: (function() { - return Discourse.get('site.archetypes').findProperty('id', this.get('archetype')); - }).property('archetype'), + archetypeObject: function() { + return Discourse.Site.instance().get('archetypes').findProperty('id', this.get('archetype')); + }.property('archetype'), isPrivateMessage: (function() { return this.get('archetype') === 'private_message'; diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js index bc6a37e5c9a..080bb6c6379 100644 --- a/app/assets/javascripts/discourse/models/user.js +++ b/app/assets/javascripts/discourse/models/user.js @@ -92,7 +92,7 @@ Discourse.User = Discourse.Model.extend({ @type {Integer} **/ trustLevel: function() { - return Discourse.get('site.trust_levels').findProperty('id', this.get('trust_level')); + return Discourse.Site.instance().get('trust_levels').findProperty('id', this.get('trust_level')); }.property('trust_level'), /** diff --git a/app/assets/javascripts/discourse/routes/list_category_route.js b/app/assets/javascripts/discourse/routes/list_category_route.js index c2127df8653..7ac95308382 100644 --- a/app/assets/javascripts/discourse/routes/list_category_route.js +++ b/app/assets/javascripts/discourse/routes/list_category_route.js @@ -9,10 +9,9 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({ model: function(params) { - var categories = Discourse.Site.instance().get('categories'); + var categories = Discourse.Category.list(); var slug = Em.get(params, 'slug'); - var category = categories.findProperty('slug', Em.get(params, 'slug')) // In case the slug didn't work, try to find it by id instead. diff --git a/app/assets/javascripts/discourse/views/modal/edit_category_view.js b/app/assets/javascripts/discourse/views/modal/edit_category_view.js index 0d99c4c6b56..46561d0dd92 100644 --- a/app/assets/javascripts/discourse/views/modal/edit_category_view.js +++ b/app/assets/javascripts/discourse/views/modal/edit_category_view.js @@ -97,7 +97,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({ // We need the topic_count to be correct, so get the most up-to-date info about this category from the server. Discourse.Category.findBySlugOrId( this.get('category.slug') || this.get('category.id') ).then( function(cat) { categoryView.set('category', cat); - Discourse.get('site').updateCategory(cat); + Discourse.Site.instance().updateCategory(cat); categoryView.set('id', categoryView.get('category.slug')); categoryView.set('loading', false); }); diff --git a/app/assets/javascripts/discourse/views/modal/flag_view.js b/app/assets/javascripts/discourse/views/modal/flag_view.js index 7c9ac37d7eb..20e2151a68f 100644 --- a/app/assets/javascripts/discourse/views/modal/flag_view.js +++ b/app/assets/javascripts/discourse/views/modal/flag_view.js @@ -47,7 +47,7 @@ Discourse.FlagView = Discourse.ModalBodyView.extend({ var action = this.get('selected'); var postAction = this.get('post.actionByName.' + (action.get('name_key'))); - var actionType = Discourse.get('site').postActionTypeById(this.get('postActionTypeId')); + var actionType = Discourse.Site.instance().postActionTypeById(this.get('postActionTypeId')); if (postAction) { postAction.act({ message: action.get('message') diff --git a/app/assets/javascripts/discourse/views/modal/login_view.js b/app/assets/javascripts/discourse/views/modal/login_view.js index 8bf21210f47..fd73662379c 100644 --- a/app/assets/javascripts/discourse/views/modal/login_view.js +++ b/app/assets/javascripts/discourse/views/modal/login_view.js @@ -8,11 +8,15 @@ **/ Discourse.LoginView = Discourse.ModalBodyView.extend({ templateName: 'modal/login', - siteBinding: 'Discourse.site', title: Em.String.i18n('login.title'), authenticate: null, loggingIn: false, + + site: function() { + return Discourse.Site.instance(); + }.property(), + showView: function(view) { return this.get('controller').show(view); }, diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index faadf48cdac..bb6be7f6694 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -29,7 +29,7 @@ Discourse.PostView = Discourse.View.extend({ }.property('parentView'), postTypeClass: function() { - return this.get('post.post_type') === Discourse.get('site.post_types.moderator_action') ? 'moderator' : 'regular'; + return this.get('post.post_type') === Discourse.Site.instance().get('post_types.moderator_action') ? 'moderator' : 'regular'; }.property('post.post_type'), // If the cooked content changed, add the quote controls