Create settings-menu-mixin for subview state tracking

Ref #4642
- Move duplicate code from PSM and SettingsTags to a mixin
This commit is contained in:
Matt Enlow 2014-12-13 20:09:19 -07:00
parent d224930e23
commit 0d95ce4b8a
3 changed files with 31 additions and 47 deletions

View File

@ -1,27 +1,13 @@
/* global moment */ /* global moment */
import {parseDateString, formatDate} from 'ghost/utils/date-formatting'; import {parseDateString, formatDate} from 'ghost/utils/date-formatting';
import SettingsMenuMixin from 'ghost/mixins/settings-menu-controller';
import SlugGenerator from 'ghost/models/slug-generator'; import SlugGenerator from 'ghost/models/slug-generator';
import boundOneWay from 'ghost/utils/bound-one-way'; import boundOneWay from 'ghost/utils/bound-one-way';
import isNumber from 'ghost/utils/isNumber'; import isNumber from 'ghost/utils/isNumber';
var PostSettingsMenuController = Ember.ObjectController.extend({ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin, {
// State for if the user is viewing a tab's pane.
needs: 'application',
lastPromise: null, 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, selectedAuthor: null,
initializeSelectedAuthor: function () { initializeSelectedAuthor: function () {
var self = this; 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 () { resetUploader: function () {
var uploader = this.get('uploaderReference'); var uploader = this.get('uploaderReference');

View File

@ -1,11 +1,10 @@
import PaginationMixin from 'ghost/mixins/pagination-controller'; import PaginationMixin from 'ghost/mixins/pagination-controller';
import SettingsMenuMixin from 'ghost/mixins/settings-menu-controller';
import boundOneWay from 'ghost/utils/bound-one-way'; 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'), tags: Ember.computed.alias('model'),
needs: 'application',
activeTag: null, activeTag: null,
activeTagNameScratch: boundOneWay('activeTag.name'), activeTagNameScratch: boundOneWay('activeTag.name'),
activeTagSlugScratch: boundOneWay('activeTag.slug'), activeTagSlugScratch: boundOneWay('activeTag.slug'),
@ -19,18 +18,6 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, {
this._super(options); 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) { showErrors: function (errors) {
errors = Ember.isArray(errors) ? errors : [errors]; errors = Ember.isArray(errors) ? errors : [errors];
this.notifications.showErrors(errors); this.notifications.showErrors(errors);
@ -147,14 +134,6 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, {
this.saveActiveTagProperty('meta_description', metaDescription); this.saveActiveTagProperty('meta_description', metaDescription);
}, },
showSubview: function () {
this.set('isViewingSubview', true);
},
closeSubview: function () {
this.set('isViewingSubview', false);
},
setCoverImage: function (image) { setCoverImage: function (image) {
this.saveActiveTagProperty('image', image); this.saveActiveTagProperty('image', image);
}, },

View File

@ -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;