mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 22:01:49 +03:00
Merge pull request #2911 from appleYaks/editor-controller
Split PostController amongst new Editor/PostSettingsMenu Controllers
This commit is contained in:
commit
a3cc757f1a
5
core/client/controllers/editor.js
Normal file
5
core/client/controllers/editor.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';
|
||||||
|
|
||||||
|
var EditorController = Ember.ObjectController.extend(EditorControllerMixin);
|
||||||
|
|
||||||
|
export default EditorController;
|
5
core/client/controllers/new.js
Normal file
5
core/client/controllers/new.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';
|
||||||
|
|
||||||
|
var EditorController = Ember.ObjectController.extend(EditorControllerMixin);
|
||||||
|
|
||||||
|
export default EditorController;
|
138
core/client/controllers/post-settings-menu.js
Normal file
138
core/client/controllers/post-settings-menu.js
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
import {parseDateString, formatDate} from 'ghost/utils/date-formatting';
|
||||||
|
|
||||||
|
var PostSettingsMenuController = Ember.ObjectController.extend({
|
||||||
|
isStaticPage: function (key, val) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (arguments.length > 1) {
|
||||||
|
this.set('page', val ? 1 : 0);
|
||||||
|
|
||||||
|
return this.get('model').save().then(function () {
|
||||||
|
self.notifications.showSuccess('Successfully converted to ' + (val ? 'static page' : 'post'));
|
||||||
|
|
||||||
|
return !!self.get('page');
|
||||||
|
}, this.notifications.showErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!this.get('page');
|
||||||
|
}.property('page'),
|
||||||
|
|
||||||
|
newSlugBinding: Ember.computed.oneWay('slug'),
|
||||||
|
|
||||||
|
slugPlaceholder: function () {
|
||||||
|
return this.get('model').generateSlug();
|
||||||
|
}.property('title'),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
updateSlug: function () {
|
||||||
|
var newSlug = this.get('newSlug'),
|
||||||
|
slug = this.get('slug'),
|
||||||
|
placeholder = this.get('slugPlaceholder'),
|
||||||
|
self = this;
|
||||||
|
|
||||||
|
newSlug = (!newSlug && placeholder) ? placeholder : newSlug;
|
||||||
|
|
||||||
|
// Ignore unchanged slugs
|
||||||
|
if (slug === newSlug) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//reset to model's slug on empty string
|
||||||
|
if (!newSlug) {
|
||||||
|
this.set('newSlug', slug);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Validation complete
|
||||||
|
this.set('slug', newSlug);
|
||||||
|
|
||||||
|
// If the model doesn't currently
|
||||||
|
// exist on the server
|
||||||
|
// then just update the model's value
|
||||||
|
if (!this.get('isNew')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.get('model').save().then(function () {
|
||||||
|
self.notifications.showSuccess('Permalink successfully changed to <strong>' +
|
||||||
|
self.get('slug') + '</strong>.');
|
||||||
|
}, this.notifications.showErrors);
|
||||||
|
},
|
||||||
|
|
||||||
|
updatePublishedAt: function (userInput) {
|
||||||
|
var self = this,
|
||||||
|
errMessage = '',
|
||||||
|
newPubDate = formatDate(parseDateString(userInput)),
|
||||||
|
pubDate = this.get('publishedAt'),
|
||||||
|
newPubDateMoment,
|
||||||
|
pubDateMoment;
|
||||||
|
|
||||||
|
// if there is no new pub date, mark that until the post is published,
|
||||||
|
// when we'll fill in with the current time.
|
||||||
|
if (!newPubDate) {
|
||||||
|
this.set('publishedAt', '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for missing time stamp on new data
|
||||||
|
// If no time specified, add a 12:00
|
||||||
|
if (newPubDate && !newPubDate.slice(-5).match(/\d+:\d\d/)) {
|
||||||
|
newPubDate += ' 12:00';
|
||||||
|
}
|
||||||
|
|
||||||
|
newPubDateMoment = parseDateString(newPubDate);
|
||||||
|
|
||||||
|
// If there was a published date already set
|
||||||
|
if (pubDate) {
|
||||||
|
// Check for missing time stamp on current model
|
||||||
|
// If no time specified, add a 12:00
|
||||||
|
if (!pubDate.slice(-5).match(/\d+:\d\d/)) {
|
||||||
|
pubDate += ' 12:00';
|
||||||
|
}
|
||||||
|
|
||||||
|
pubDateMoment = parseDateString(pubDate);
|
||||||
|
|
||||||
|
// Quit if the new date is the same
|
||||||
|
if (pubDateMoment.isSame(newPubDateMoment)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate new Published date
|
||||||
|
if (!newPubDateMoment.isValid() || newPubDate.substr(0, 12) === 'Invalid date') {
|
||||||
|
errMessage = 'Published Date must be a valid date with format: ' +
|
||||||
|
'DD MMM YY @ HH:mm (e.g. 6 Dec 14 @ 15:00)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPubDateMoment.diff(new Date(), 'h') > 0) {
|
||||||
|
errMessage = 'Published Date cannot currently be in the future.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errMessage) {
|
||||||
|
// Show error message
|
||||||
|
this.notifications.showError(errMessage);
|
||||||
|
//Hack to push a "change" when it's actually staying
|
||||||
|
// the same.
|
||||||
|
//This alerts the listener on post-settings-menu
|
||||||
|
this.notifyPropertyChange('publishedAt');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Validation complete
|
||||||
|
this.set('published_at', newPubDateMoment.toDate());
|
||||||
|
|
||||||
|
// If the model doesn't currently
|
||||||
|
// exist on the server
|
||||||
|
// then just update the model's value
|
||||||
|
if (!this.get('isNew')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.get('model').save().then(function () {
|
||||||
|
this.notifications.showSuccess('Publish date successfully changed to <strong>' +
|
||||||
|
self.get('publishedAt') + '</strong>.');
|
||||||
|
}, this.notifications.showErrors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PostSettingsMenuController;
|
@ -1,176 +1,11 @@
|
|||||||
/* global console */
|
|
||||||
import {parseDateString, formatDate} from 'ghost/utils/date-formatting';
|
|
||||||
|
|
||||||
var PostController = Ember.ObjectController.extend({
|
var PostController = Ember.ObjectController.extend({
|
||||||
//## Computed post properties
|
|
||||||
isPublished: Ember.computed.equal('status', 'published'),
|
isPublished: Ember.computed.equal('status', 'published'),
|
||||||
isDraft: Ember.computed.equal('status', 'draft'),
|
|
||||||
/**
|
|
||||||
* By default, a post will not change its publish state.
|
|
||||||
* Only with a user-set value (via setSaveType action)
|
|
||||||
* can the post's status change.
|
|
||||||
*/
|
|
||||||
willPublish: function (key, val) {
|
|
||||||
if (val) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return this.get('isPublished');
|
|
||||||
}.property('isPublished'),
|
|
||||||
isStaticPage: function (key, val) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
this.set('page', val ? 1 : 0);
|
|
||||||
|
|
||||||
return this.get('model').save().then(function () {
|
|
||||||
self.notifications.showSuccess('Successfully converted to ' + (val ? 'static page' : 'post'));
|
|
||||||
|
|
||||||
return !!self.get('page');
|
|
||||||
}, this.notifications.showErrors);
|
|
||||||
}
|
|
||||||
|
|
||||||
return !!this.get('page');
|
|
||||||
}.property('page'),
|
|
||||||
|
|
||||||
newSlugBinding: Ember.computed.oneWay('slug'),
|
|
||||||
|
|
||||||
slugPlaceholder: function () {
|
|
||||||
return this.get('model').generateSlug();
|
|
||||||
}.property('title'),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save: function () {
|
|
||||||
var status = this.get('willPublish') ? 'published' : 'draft',
|
|
||||||
self = this;
|
|
||||||
|
|
||||||
this.set('model.status', status);
|
|
||||||
this.get('model').save().then(function () {
|
|
||||||
console.log('saved');
|
|
||||||
self.notifications.showSuccess('Post status saved as <strong>' +
|
|
||||||
self.get('model.status') + '</strong>.');
|
|
||||||
}, this.notifications.showErrors);
|
|
||||||
},
|
|
||||||
setSaveType: function (newType) {
|
|
||||||
if (newType === 'publish') {
|
|
||||||
this.set('willPublish', true);
|
|
||||||
} else if (newType === 'draft') {
|
|
||||||
this.set('willPublish', false);
|
|
||||||
} else {
|
|
||||||
console.warn('Received invalid save type; ignoring.');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toggleFeatured: function () {
|
toggleFeatured: function () {
|
||||||
this.set('featured', !this.get('featured'));
|
this.set('featured', !this.get('featured'));
|
||||||
|
|
||||||
this.get('model').save();
|
this.get('model').save();
|
||||||
},
|
|
||||||
updateSlug: function () {
|
|
||||||
var newSlug = this.get('newSlug'),
|
|
||||||
slug = this.get('slug'),
|
|
||||||
placeholder = this.get('slugPlaceholder'),
|
|
||||||
self = this;
|
|
||||||
|
|
||||||
newSlug = (!newSlug && placeholder) ? placeholder : newSlug;
|
|
||||||
|
|
||||||
// Ignore unchanged slugs
|
|
||||||
if (slug === newSlug) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//reset to model's slug on empty string
|
|
||||||
if (!newSlug) {
|
|
||||||
this.set('newSlug', slug);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validation complete
|
|
||||||
this.set('slug', newSlug);
|
|
||||||
|
|
||||||
// If the model doesn't currently
|
|
||||||
// exist on the server
|
|
||||||
// then just update the model's value
|
|
||||||
if (!this.get('isNew')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.get('model').save().then(function () {
|
|
||||||
self.notifications.showSuccess('Permalink successfully changed to <strong>' +
|
|
||||||
self.get('slug') + '</strong>.');
|
|
||||||
}, this.notifications.showErrors);
|
|
||||||
},
|
|
||||||
|
|
||||||
updatePublishedAt: function (userInput) {
|
|
||||||
var self = this,
|
|
||||||
errMessage = '',
|
|
||||||
newPubDate = formatDate(parseDateString(userInput)),
|
|
||||||
pubDate = this.get('publishedAt'),
|
|
||||||
newPubDateMoment,
|
|
||||||
pubDateMoment;
|
|
||||||
|
|
||||||
// if there is no new pub date, mark that until the post is published,
|
|
||||||
// when we'll fill in with the current time.
|
|
||||||
if (!newPubDate) {
|
|
||||||
this.set('publishedAt', '');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for missing time stamp on new data
|
|
||||||
// If no time specified, add a 12:00
|
|
||||||
if (newPubDate && !newPubDate.slice(-5).match(/\d+:\d\d/)) {
|
|
||||||
newPubDate += ' 12:00';
|
|
||||||
}
|
|
||||||
|
|
||||||
newPubDateMoment = parseDateString(newPubDate);
|
|
||||||
|
|
||||||
// If there was a published date already set
|
|
||||||
if (pubDate) {
|
|
||||||
// Check for missing time stamp on current model
|
|
||||||
// If no time specified, add a 12:00
|
|
||||||
if (!pubDate.slice(-5).match(/\d+:\d\d/)) {
|
|
||||||
pubDate += ' 12:00';
|
|
||||||
}
|
|
||||||
|
|
||||||
pubDateMoment = parseDateString(pubDate);
|
|
||||||
|
|
||||||
// Quit if the new date is the same
|
|
||||||
if (pubDateMoment.isSame(newPubDateMoment)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate new Published date
|
|
||||||
if (!newPubDateMoment.isValid() || newPubDate.substr(0, 12) === 'Invalid date') {
|
|
||||||
errMessage = 'Published Date must be a valid date with format: ' +
|
|
||||||
'DD MMM YY @ HH:mm (e.g. 6 Dec 14 @ 15:00)';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newPubDateMoment.diff(new Date(), 'h') > 0) {
|
|
||||||
errMessage = 'Published Date cannot currently be in the future.';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errMessage) {
|
|
||||||
// Show error message
|
|
||||||
this.notifications.showError(errMessage);
|
|
||||||
//Hack to push a "change" when it's actually staying
|
|
||||||
// the same.
|
|
||||||
//This alerts the listener on post-settings-menu
|
|
||||||
this.notifyPropertyChange('publishedAt');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validation complete
|
|
||||||
this.set('published_at', newPubDateMoment.toDate());
|
|
||||||
|
|
||||||
// If the model doesn't currently
|
|
||||||
// exist on the server
|
|
||||||
// then just update the model's value
|
|
||||||
if (!this.get('isNew')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.get('model').save().then(function () {
|
|
||||||
this.notifications.showSuccess('Publish date successfully changed to <strong>' +
|
|
||||||
self.get('publishedAt') + '</strong>.');
|
|
||||||
}, this.notifications.showErrors);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
44
core/client/mixins/editor-base-controller.js
Normal file
44
core/client/mixins/editor-base-controller.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* global console */
|
||||||
|
|
||||||
|
var EditorControllerMixin = Ember.Mixin.create({
|
||||||
|
//## Computed post properties
|
||||||
|
isPublished: Ember.computed.equal('status', 'published'),
|
||||||
|
isDraft: Ember.computed.equal('status', 'draft'),
|
||||||
|
/**
|
||||||
|
* By default, a post will not change its publish state.
|
||||||
|
* Only with a user-set value (via setSaveType action)
|
||||||
|
* can the post's status change.
|
||||||
|
*/
|
||||||
|
willPublish: function (key, val) {
|
||||||
|
if (val) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
return this.get('isPublished');
|
||||||
|
}.property('isPublished'),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
save: function () {
|
||||||
|
var status = this.get('willPublish') ? 'published' : 'draft',
|
||||||
|
self = this;
|
||||||
|
|
||||||
|
this.set('status', status);
|
||||||
|
this.get('model').save().then(function () {
|
||||||
|
console.log('saved');
|
||||||
|
self.notifications.showSuccess('Post status saved as <strong>' +
|
||||||
|
self.get('status') + '</strong>.');
|
||||||
|
}, this.notifications.showErrors);
|
||||||
|
},
|
||||||
|
|
||||||
|
setSaveType: function (newType) {
|
||||||
|
if (newType === 'publish') {
|
||||||
|
this.set('willPublish', true);
|
||||||
|
} else if (newType === 'draft') {
|
||||||
|
this.set('willPublish', false);
|
||||||
|
} else {
|
||||||
|
console.warn('Received invalid save type; ignoring.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default EditorControllerMixin;
|
@ -3,7 +3,7 @@ import AuthenticatedRoute from 'ghost/routes/authenticated';
|
|||||||
|
|
||||||
var EditorRoute = AuthenticatedRoute.extend(styleBody, {
|
var EditorRoute = AuthenticatedRoute.extend(styleBody, {
|
||||||
classNames: ['editor'],
|
classNames: ['editor'],
|
||||||
controllerName: 'posts.post',
|
|
||||||
model: function (params) {
|
model: function (params) {
|
||||||
var post = this.store.getById('post', params.post_id);
|
var post = this.store.getById('post', params.post_id);
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ var EditorRoute = AuthenticatedRoute.extend(styleBody, {
|
|||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.store.filter('post', { status: 'all' }, function (post) {
|
return this.store.filter('post', { status: 'all', staticPages: 'all' }, function (post) {
|
||||||
return post.get('id') === params.post_id;
|
return post.get('id') === params.post_id;
|
||||||
}).then(function (records) {
|
}).then(function (records) {
|
||||||
return records.get('firstObject');
|
return records.get('firstObject');
|
||||||
|
@ -2,13 +2,8 @@ import AuthenticatedRoute from 'ghost/routes/authenticated';
|
|||||||
import styleBody from 'ghost/mixins/style-body';
|
import styleBody from 'ghost/mixins/style-body';
|
||||||
|
|
||||||
var NewRoute = AuthenticatedRoute.extend(styleBody, {
|
var NewRoute = AuthenticatedRoute.extend(styleBody, {
|
||||||
controllerName: 'posts.post',
|
|
||||||
classNames: ['editor'],
|
classNames: ['editor'],
|
||||||
|
|
||||||
renderTemplate: function () {
|
|
||||||
this.render('editor');
|
|
||||||
},
|
|
||||||
|
|
||||||
model: function () {
|
model: function () {
|
||||||
return this.store.createRecord('post', {
|
return this.store.createRecord('post', {
|
||||||
title: ''
|
title: ''
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<span class="hidden">Post Settings</span>
|
<span class="hidden">Post Settings</span>
|
||||||
{{/gh-popover-button}}
|
{{/gh-popover-button}}
|
||||||
{{#gh-popover name="post-settings-menu" classNames="post-settings-menu menu-drop-right"}}
|
{{#gh-popover name="post-settings-menu" classNames="post-settings-menu menu-drop-right"}}
|
||||||
{{view "post-settings-menu-view"}}
|
{{render "post-settings-menu" model}}
|
||||||
{{/gh-popover}}
|
{{/gh-popover}}
|
||||||
</section>
|
</section>
|
||||||
</header>
|
</header>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<span class="hidden">Post Settings</span>
|
<span class="hidden">Post Settings</span>
|
||||||
{{/gh-popover-button}}
|
{{/gh-popover-button}}
|
||||||
{{#gh-popover name="post-settings-menu" classNames="post-settings-menu menu-right"}}
|
{{#gh-popover name="post-settings-menu" classNames="post-settings-menu menu-right"}}
|
||||||
{{view "post-settings-menu-view"}}
|
{{render "post-settings-menu" model}}
|
||||||
{{/gh-popover}}
|
{{/gh-popover}}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
TODO
|
|
@ -57,7 +57,6 @@ var EditorTags = Ember.View.extend({
|
|||||||
|
|
||||||
this.set('overlay.left', this.$input.position().left);
|
this.set('overlay.left', this.$input.position().left);
|
||||||
this.$suggestions.html('');
|
this.$suggestions.html('');
|
||||||
window.b = matchingTags;
|
|
||||||
|
|
||||||
matchingTags = matchingTags.slice(0, maxSuggestions);
|
matchingTags = matchingTags.slice(0, maxSuggestions);
|
||||||
if (matchingTags.length > 0) {
|
if (matchingTags.length > 0) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
export default Ember.View.extend({
|
var EditorView = Ember.View.extend({
|
||||||
tagName: 'section',
|
tagName: 'section',
|
||||||
classNames: ['entry-container'],
|
classNames: ['entry-container'],
|
||||||
scrollPosition: 0 // percentage of scroll position
|
scrollPosition: 0 // percentage of scroll position
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default EditorView;
|
8
core/client/views/new.js
Normal file
8
core/client/views/new.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
var NewView = Ember.View.extend({
|
||||||
|
tagName: 'section',
|
||||||
|
templateName: 'editor',
|
||||||
|
classNames: ['entry-container'],
|
||||||
|
scrollPosition: 0 // percentage of scroll position
|
||||||
|
});
|
||||||
|
|
||||||
|
export default NewView;
|
Loading…
Reference in New Issue
Block a user