Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ObjectController proxying behavior. #4748

Merged
merged 1 commit into from Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .jscsrc
@@ -1,4 +1,5 @@
{
"additionalRules": [ "core/test/utils/jscs-rules/*.js" ],
"requireCurlyBraces": [
"if",
"else",
Expand Down
6 changes: 4 additions & 2 deletions Gruntfile.js
Expand Up @@ -203,13 +203,15 @@ var _ = require('lodash'),
client: {
options: {
config: '.jscsrc',
esnext: true
esnext: true,
disallowObjectController: true
}
},
clientTests: {
options: {
config: '.jscsrc',
esnext: true
esnext: true,
disallowObjectController: true
}
},
test: {
Expand Down
2 changes: 1 addition & 1 deletion core/client/controllers/editor/edit.js
@@ -1,5 +1,5 @@
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';

var EditorEditController = Ember.ObjectController.extend(EditorControllerMixin);
var EditorEditController = Ember.Controller.extend(EditorControllerMixin);

export default EditorEditController;
2 changes: 1 addition & 1 deletion core/client/controllers/editor/new.js
@@ -1,6 +1,6 @@
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';

var EditorNewController = Ember.ObjectController.extend(EditorControllerMixin, {
var EditorNewController = Ember.Controller.extend(EditorControllerMixin, {
actions: {
/**
* Redirect to editor after the first save
Expand Down
6 changes: 3 additions & 3 deletions core/client/controllers/modals/delete-tag.js
@@ -1,6 +1,6 @@
var DeleteTagController = Ember.ObjectController.extend({
postInflection: Ember.computed('post_count', function () {
return this.get('post_count') > 1 ? 'posts' : 'post';
var DeleteTagController = Ember.Controller.extend({
postInflection: Ember.computed('model.post_count', function () {
return this.get('model.post_count') > 1 ? 'posts' : 'post';
}),

actions: {
Expand Down
6 changes: 3 additions & 3 deletions core/client/controllers/modals/delete-user.js
@@ -1,8 +1,8 @@
var DeleteUserController = Ember.ObjectController.extend({
userPostCount: Ember.computed('id', function () {
var DeleteUserController = Ember.Controller.extend({
userPostCount: Ember.computed('model.id', function () {
var promise,
query = {
author: this.get('slug'),
author: this.get('model.slug'),
status: 'all'
};

Expand Down
92 changes: 47 additions & 45 deletions core/client/controllers/post-settings-menu.js
Expand Up @@ -5,21 +5,23 @@ 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(SettingsMenuMixin, {
var PostSettingsMenuController = Ember.Controller.extend(SettingsMenuMixin, {
debounceId: null,
lastPromise: null,

selectedAuthor: null,
uploaderReference: null,

initializeSelectedAuthor: function () {
var self = this;

return this.get('author').then(function (author) {
return this.get('model.author').then(function (author) {
self.set('selectedAuthor', author);
return author;
});
}.observes('model'),

changeAuthor: function () {
var author = this.get('author'),
var author = this.get('model.author'),
selectedAuthor = this.get('selectedAuthor'),
model = this.get('model'),
self = this;
Expand All @@ -32,7 +34,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
model.set('author', selectedAuthor);

// if this is a new post (never been saved before), don't try to save it
if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand Down Expand Up @@ -61,8 +63,8 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
}),

/*jshint unused:false */
publishedAtValue: Ember.computed('published_at', function (key, value) {
var pubDate = this.get('published_at');
publishedAtValue: Ember.computed('model.published_at', function (key, value) {
var pubDate = this.get('model.published_at');

// We're using a fake setter to reset
// the cache for this property
Expand All @@ -78,7 +80,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
}),
/*jshint unused:true */

slugValue: boundOneWay('slug'),
slugValue: boundOneWay('model.slug'),

// Lazy load the slug generator
slugGenerator: Ember.computed(function () {
Expand All @@ -91,12 +93,12 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
// Requests slug from title
generateAndSetSlug: function (destination) {
var self = this,
title = this.get('titleScratch'),
title = this.get('model.titleScratch'),
afterSave = this.get('lastPromise'),
promise;

// Only set an "untitled" slug once per post
if (title === '(Untitled)' && this.get('slug')) {
if (title === '(Untitled)' && this.get('model.slug')) {
return;
}

Expand All @@ -113,13 +115,13 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
this.set('lastPromise', promise);
},

metaTitleScratch: boundOneWay('meta_title'),
metaDescriptionScratch: boundOneWay('meta_description'),
metaTitleScratch: boundOneWay('model.meta_title'),
metaDescriptionScratch: boundOneWay('model.meta_description'),

seoTitle: Ember.computed('titleScratch', 'metaTitleScratch', function () {
seoTitle: Ember.computed('model.titleScratch', 'metaTitleScratch', function () {
var metaTitle = this.get('metaTitleScratch') || '';

metaTitle = metaTitle.length > 0 ? metaTitle : this.get('titleScratch');
metaTitle = metaTitle.length > 0 ? metaTitle : this.get('model.titleScratch');

if (metaTitle.length > 70) {
metaTitle = metaTitle.substring(0, 70).trim();
Expand All @@ -130,7 +132,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
return metaTitle;
}),

seoDescription: Ember.computed('scratch', 'metaDescriptionScratch', function () {
seoDescription: Ember.computed('model.scratch', 'metaDescriptionScratch', function () {
var metaDescription = this.get('metaDescriptionScratch') || '',
el,
html = '',
Expand Down Expand Up @@ -166,9 +168,9 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
return placeholder;
}),

seoURL: Ember.computed('slug', function () {
seoURL: Ember.computed('model.slug', function () {
var blogUrl = this.get('config').blogUrl,
seoSlug = this.get('slug') ? this.get('slug') : '',
seoSlug = this.get('model.slug') ? this.get('model.slug') : '',
seoURL = blogUrl + '/' + seoSlug;

// only append a slash to the URL if the slug exists
Expand All @@ -187,18 +189,18 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
// observe titleScratch, keeping the post's slug in sync
// with it until saved for the first time.
addTitleObserver: function () {
if (this.get('isNew') || this.get('title') === '(Untitled)') {
this.addObserver('titleScratch', this, 'titleObserver');
if (this.get('model.isNew') || this.get('model.title') === '(Untitled)') {
this.addObserver('model.titleScratch', this, 'titleObserver');
}
}.observes('model'),

titleObserver: function () {
var debounceId,
title = this.get('title');
title = this.get('model.title');

// generate a slug if a post is new and doesn't have a title yet or
// if the title is still '(Untitled)' and the slug is unaltered.
if ((this.get('isNew') && !title) || title === '(Untitled)') {
if ((this.get('model.isNew') && !title) || title === '(Untitled)') {
debounceId = Ember.run.debounce(this, 'generateAndSetSlug', ['slug'], 700);
}

Expand All @@ -218,10 +220,10 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
togglePage: function () {
var self = this;

this.toggleProperty('page');
this.toggleProperty('model.page');
// If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button
if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand All @@ -234,11 +236,11 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
toggleFeatured: function () {
var self = this;

this.toggleProperty('featured');
this.toggleProperty('model.featured');

// If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button
if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand All @@ -252,7 +254,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
* triggered by user manually changing slug
*/
updateSlug: function (newSlug) {
var slug = this.get('slug'),
var slug = this.get('model.slug'),
self = this;

newSlug = newSlug || slug;
Expand Down Expand Up @@ -294,15 +296,15 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
}
}

self.set('slug', serverSlug);
self.set('model.slug', serverSlug);

if (self.hasObserverFor('titleScratch')) {
self.removeObserver('titleScratch', self, 'titleObserver');
if (self.hasObserverFor('model.titleScratch')) {
self.removeObserver('model.titleScratch', self, 'titleObserver');
}

// If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button
if (self.get('isNew')) {
if (self.get('model.isNew')) {
return;
}

Expand All @@ -321,13 +323,13 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
setPublishedAt: function (userInput) {
var errMessage = '',
newPublishedAt = parseDateString(userInput),
publishedAt = this.get('published_at'),
publishedAt = this.get('model.published_at'),
self = this;

if (!userInput) {
// Clear out the published_at field for a draft
if (this.get('isDraft')) {
this.set('published_at', null);
if (this.get('model.isDraft')) {
this.set('model.published_at', null);
}

return;
Expand Down Expand Up @@ -355,11 +357,11 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
}

// Validation complete
this.set('published_at', newPublishedAt);
this.set('model.published_at', newPublishedAt);

// If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button
if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand All @@ -371,18 +373,18 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin

setMetaTitle: function (metaTitle) {
var self = this,
currentTitle = this.get('meta_title') || '';
currentTitle = this.get('model.meta_title') || '';

// Only update if the title has changed
if (currentTitle === metaTitle) {
return;
}

this.set('meta_title', metaTitle);
this.set('model.meta_title', metaTitle);

// If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button
if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand All @@ -393,18 +395,18 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin

setMetaDescription: function (metaDescription) {
var self = this,
currentDescription = this.get('meta_description') || '';
currentDescription = this.get('model.meta_description') || '';

// Only update if the description has changed
if (currentDescription === metaDescription) {
return;
}

this.set('meta_description', metaDescription);
this.set('model.meta_description', metaDescription);

// If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button
if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand All @@ -416,9 +418,9 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
setCoverImage: function (image) {
var self = this;

this.set('image', image);
this.set('model.image', image);

if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand All @@ -431,9 +433,9 @@ var PostSettingsMenuController = Ember.ObjectController.extend(SettingsMenuMixin
clearCoverImage: function () {
var self = this;

this.set('image', '');
this.set('model.image', '');

if (this.get('isNew')) {
if (this.get('model.isNew')) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions core/client/controllers/post-tags-input.js
@@ -1,9 +1,9 @@
var PostTagsInputController = Ember.Controller.extend({
tagEnteredOrder: Ember.A(),

tags: Ember.computed('parentController.tags', function () {
tags: Ember.computed('parentController.model.tags', function () {
var proxyTags = Ember.ArrayProxy.create({
content: this.get('parentController.tags')
content: this.get('parentController.model.tags')
}),
temp = proxyTags.get('arrangedContent').slice();

Expand Down
8 changes: 4 additions & 4 deletions core/client/controllers/posts/post.js
@@ -1,13 +1,13 @@
var PostController = Ember.ObjectController.extend({
isPublished: Ember.computed.equal('status', 'published'),
classNameBindings: ['featured'],
var PostController = Ember.Controller.extend({
isPublished: Ember.computed.equal('model.status', 'published'),
classNameBindings: ['model.featured'],

actions: {
toggleFeatured: function () {
var options = {disableNProgress: true},
self = this;

this.toggleProperty('featured');
this.toggleProperty('model.featured');
this.get('model').save(options).catch(function (errors) {
self.notifications.showErrors(errors);
});
Expand Down
2 changes: 1 addition & 1 deletion core/client/controllers/settings/app.js
Expand Up @@ -9,7 +9,7 @@ appStates = {
inactive: 'inactive'
};

SettingsAppController = Ember.ObjectController.extend({
SettingsAppController = Ember.Controller.extend({
appState: appStates.active,
buttonText: '',

Expand Down
2 changes: 1 addition & 1 deletion core/client/controllers/settings/code-injection.js
@@ -1,4 +1,4 @@
var SettingsCodeInjectionController = Ember.ObjectController.extend({
var SettingsCodeInjectionController = Ember.Controller.extend({
actions: {
save: function () {
var self = this;
Expand Down