From 0d95ce4b8abad1be94becf918451f9b0442711d0 Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Sat, 13 Dec 2014 20:09:19 -0700 Subject: [PATCH] Create settings-menu-mixin for subview state tracking Ref #4642 - Move duplicate code from PSM and SettingsTags to a mixin --- ghost/admin/controllers/post-settings-menu.js | 26 ++---------------- ghost/admin/controllers/settings/tags.js | 25 ++--------------- .../admin/mixins/settings-menu-controller.js | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 47 deletions(-) create mode 100644 ghost/admin/mixins/settings-menu-controller.js diff --git a/ghost/admin/controllers/post-settings-menu.js b/ghost/admin/controllers/post-settings-menu.js index f31a0c8243..50946689e8 100644 --- a/ghost/admin/controllers/post-settings-menu.js +++ b/ghost/admin/controllers/post-settings-menu.js @@ -1,27 +1,13 @@ /* global moment */ import {parseDateString, formatDate} from 'ghost/utils/date-formatting'; +import SettingsMenuMixin from 'ghost/mixins/settings-menu-controller'; import SlugGenerator from 'ghost/models/slug-generator'; import boundOneWay from 'ghost/utils/bound-one-way'; import isNumber from 'ghost/utils/isNumber'; -var PostSettingsMenuController = Ember.ObjectController.extend({ - // State for if the user is viewing a tab's pane. - needs: 'application', - +var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin, { lastPromise: null, - isViewingSubview: Ember.computed('controllers.application.showSettingsMenu', function (key, value) { - // Not viewing a subview if we can't even see the PSM - if (!this.get('controllers.application.showSettingsMenu')) { - return false; - } - if (arguments.length > 1) { - return value; - } - - return false; - }), - selectedAuthor: null, initializeSelectedAuthor: function () { var self = this; @@ -449,14 +435,6 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ }); }, - showSubview: function () { - this.set('isViewingSubview', true); - }, - - closeSubview: function () { - this.set('isViewingSubview', false); - }, - resetUploader: function () { var uploader = this.get('uploaderReference'); diff --git a/ghost/admin/controllers/settings/tags.js b/ghost/admin/controllers/settings/tags.js index ea6239cf82..8c58ddeeaa 100644 --- a/ghost/admin/controllers/settings/tags.js +++ b/ghost/admin/controllers/settings/tags.js @@ -1,11 +1,10 @@ import PaginationMixin from 'ghost/mixins/pagination-controller'; +import SettingsMenuMixin from 'ghost/mixins/settings-menu-controller'; import boundOneWay from 'ghost/utils/bound-one-way'; -var TagsController = Ember.ArrayController.extend(PaginationMixin, { +var TagsController = Ember.ArrayController.extend(PaginationMixin, SettingsMenuMixin, { tags: Ember.computed.alias('model'), - needs: 'application', - activeTag: null, activeTagNameScratch: boundOneWay('activeTag.name'), activeTagSlugScratch: boundOneWay('activeTag.slug'), @@ -19,18 +18,6 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, { this._super(options); }, - isViewingSubview: Ember.computed('controllers.application.showSettingsMenu', function (key, value) { - // Not viewing a subview if we can't even see the PSM - if (!this.get('controllers.application.showSettingsMenu')) { - return false; - } - if (arguments.length > 1) { - return value; - } - - return false; - }), - showErrors: function (errors) { errors = Ember.isArray(errors) ? errors : [errors]; this.notifications.showErrors(errors); @@ -147,14 +134,6 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, { this.saveActiveTagProperty('meta_description', metaDescription); }, - showSubview: function () { - this.set('isViewingSubview', true); - }, - - closeSubview: function () { - this.set('isViewingSubview', false); - }, - setCoverImage: function (image) { this.saveActiveTagProperty('image', image); }, diff --git a/ghost/admin/mixins/settings-menu-controller.js b/ghost/admin/mixins/settings-menu-controller.js new file mode 100644 index 0000000000..69c4e44eff --- /dev/null +++ b/ghost/admin/mixins/settings-menu-controller.js @@ -0,0 +1,27 @@ +var SettingsMenuControllerMixin = Ember.Mixin.create({ + needs: 'application', + + isViewingSubview: Ember.computed('controllers.application.showSettingsMenu', function (key, value) { + // Not viewing a subview if we can't even see the PSM + if (!this.get('controllers.application.showSettingsMenu')) { + return false; + } + if (arguments.length > 1) { + return value; + } + + return false; + }), + + actions: { + showSubview: function () { + this.set('isViewingSubview', true); + }, + + closeSubview: function () { + this.set('isViewingSubview', false); + } + } +}); + +export default SettingsMenuControllerMixin;