diff --git a/core/client/controllers/feature.js b/core/client/controllers/feature.js new file mode 100644 index 0000000000..bb449f7f41 --- /dev/null +++ b/core/client/controllers/feature.js @@ -0,0 +1,37 @@ +var FeatureController = Ember.Controller.extend(Ember.PromiseProxyMixin, { + init: function () { + var promise; + + promise = this.store.find('setting', {type: 'blog,theme'}).then(function (settings) { + return settings.get('firstObject'); + }); + + this.set('promise', promise); + }, + + setting: Ember.computed.alias('content'), + + labs: Ember.computed('isSettled', 'setting.labs', function () { + var value = {}; + + if (this.get('isFulfilled')) { + try { + value = JSON.parse(this.get('setting.labs') || {}); + } catch (err) { + value = {}; + } + } + + return value; + }), + + tagsUI: Ember.computed('config.tagsUI', 'labs.tagsUI', function () { + return this.get('config.tagsUI') || this.get('labs.tagsUI'); + }), + + codeInjectionUI: Ember.computed('config.codeInjectionUI', 'labs.codeInjectionUI', function () { + return this.get('config.codeInjectionUI') || this.get('labs.codeInjectionUI'); + }) +}); + +export default FeatureController; diff --git a/core/client/controllers/settings.js b/core/client/controllers/settings.js index df07e47fd7..090251c267 100644 --- a/core/client/controllers/settings.js +++ b/core/client/controllers/settings.js @@ -1,15 +1,17 @@ var SettingsController = Ember.Controller.extend({ + needs: ['feature'], + showGeneral: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true; }), showUsers: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') ? false : true; }), - showTags: Ember.computed('session.user.name', 'feature.tagsUI', function () { - return this.get('session.user.isAuthor') || !this.get('feature.tagsUI') ? false : true; + showTags: Ember.computed('session.user.name', 'controllers.feature.tagsUI', function () { + return this.get('session.user.isAuthor') || !this.get('controllers.feature.tagsUI') ? false : true; }), - showCodeInjection: Ember.computed('session.user.name', 'feature.codeInjectionUI', function () { - return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('feature.codeInjectionUI') ? false : true; + showCodeInjection: Ember.computed('session.user.name', 'controllers.feature.codeInjectionUI', function () { + return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('controllers.feature.codeInjectionUI') ? false : true; }), showLabs: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true; diff --git a/core/client/controllers/settings/labs.js b/core/client/controllers/settings/labs.js index c111d765ba..531d91d01c 100644 --- a/core/client/controllers/settings/labs.js +++ b/core/client/controllers/settings/labs.js @@ -1,4 +1,6 @@ var LabsController = Ember.Controller.extend(Ember.Evented, { + needs: ['feature'], + uploadButtonText: 'Import', importErrors: '', labsJSON: Ember.computed('model.labs', function () { @@ -23,24 +25,24 @@ var LabsController = Ember.Controller.extend(Ember.Evented, { tagsUIFlag: Ember.computed.alias('config.tagsUI'), codeUIFlag: Ember.computed.alias('config.codeInjectionUI'), - useTagsUI: Ember.computed('tagsUI', function (key, value) { + useTagsUI: Ember.computed('controllers.feature.tagsUI', function (key, value) { // setter if (arguments.length > 1) { this.saveLabs('tagsUI', value); } // getter - return this.get('feature.tagsUI') || false; + return this.get('controllers.feature.tagsUI') || false; }), - useCodeInjectionUI: Ember.computed('codeInjectionUI', function (key, value) { + useCodeInjectionUI: Ember.computed('controllers.feature.tagsUI', function (key, value) { // setter if (arguments.length > 1) { this.saveLabs('codeInjectionUI', value); } // getter - return this.get('feature.codeInjectionUI') || false; + return this.get('controllers.feature.codeInjectionUI') || false; }), actions: { diff --git a/core/client/initializers/feature.js b/core/client/initializers/feature.js deleted file mode 100644 index 52ff88e15e..0000000000 --- a/core/client/initializers/feature.js +++ /dev/null @@ -1,17 +0,0 @@ -import Feature from 'ghost/utils/feature'; - -var injectFeatureInitializer = { - name: 'injectFeature', - after: ['config', 'store'], - - initialize: function (container, application) { - application.register('feature:main', Feature); - application.inject('feature:main', 'store', 'store:main'); - application.inject('feature:main', 'config', 'ghost:config'); - - application.inject('controller', 'feature', 'feature:main'); - application.inject('route', 'feature', 'feature:main'); - } -}; - -export default injectFeatureInitializer; diff --git a/core/client/routes/settings/code-injection.js b/core/client/routes/settings/code-injection.js index 2d1f4f3c1d..78bf8c798f 100644 --- a/core/client/routes/settings/code-injection.js +++ b/core/client/routes/settings/code-injection.js @@ -7,9 +7,24 @@ var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingInd classNames: ['settings-view-code'], beforeModel: function () { + var feature = this.controllerFor('feature'), + self = this; + + if (!feature) { + this.generateController('feature'); + feature = this.controllerFor('feature'); + } + return this.currentUser() .then(this.transitionAuthor()) - .then(this.transitionEditor()); + .then(this.transitionEditor()) + .then(function () { + return feature.then(function () { + if (!feature.get('codeInjectionUI')) { + return self.transitionTo('settings.general'); + } + }); + }); }, model: function () { diff --git a/core/client/routes/settings/tags.js b/core/client/routes/settings/tags.js index d133ded146..d51502f475 100644 --- a/core/client/routes/settings/tags.js +++ b/core/client/routes/settings/tags.js @@ -12,7 +12,6 @@ paginationSettings = { }; TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, { - actions: { willTransition: function () { this.send('closeSettingsMenu'); @@ -22,12 +21,23 @@ TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, titleToken: 'Tags', beforeModel: function () { - if (!this.get('feature.tagsUI')) { - return this.transitionTo('settings.general'); + var feature = this.controllerFor('feature'), + self = this; + + if (!feature) { + this.generateController('feature'); + feature = this.controllerFor('feature'); } return this.currentUser() - .then(this.transitionAuthor()); + .then(this.transitionAuthor()) + .then(function () { + return feature.then(function () { + if (!feature.get('tagsUI')) { + return self.transitionTo('settings.general'); + } + }); + }); }, model: function () { diff --git a/core/client/utils/feature.js b/core/client/utils/feature.js deleted file mode 100644 index 185cbd9f39..0000000000 --- a/core/client/utils/feature.js +++ /dev/null @@ -1,24 +0,0 @@ -var Feature; - -Feature = Ember.Object.extend({ - init: function () { - var self = this; - this.store.find('setting').then(function (settings) { - self.set('setting', settings.get('firstObject')); - }); - }, - labs: Ember.computed('setting', 'setting.labs', function () { - if (this.setting) { - return JSON.parse(this.get('setting.labs') || {}); - } - return {}; - }), - tagsUI: Ember.computed('config.tagsUI', 'labs.tagsUI', function () { - return this.config.tagsUI || this.get('labs.tagsUI'); - }), - codeInjectionUI: Ember.computed('config.codeInjectionUI', 'labs.codeInjectionUI', function () { - return this.config.codeInjectionUI || this.get('labs.codeInjectionUI'); - }) -}); - -export default Feature;