diff --git a/ghost/admin/controllers/posts/post.js b/ghost/admin/controllers/posts/post.js index ac10e1fa5e..9070748c65 100644 --- a/ghost/admin/controllers/posts/post.js +++ b/ghost/admin/controllers/posts/post.js @@ -1,12 +1,17 @@ +/* global console */ import {parseDateString, formatDate} from 'ghost/utils/date-formatting'; var equal = Ember.computed.equal; var PostController = Ember.ObjectController.extend({ + //## Editor state properties + isEditingSettings: false, + isViewingSaveTypes: false, + //## Computed post properties isPublished: equal('status', 'published'), isDraft: equal('status', 'draft'), - isEditingSettings: false, + willPublish: Ember.computed.oneWay('isPublished'), isStaticPage: function (key, val) { if (arguments.length > 1) { this.set('model.page', val ? 1 : 0); @@ -51,11 +56,31 @@ var PostController = Ember.ObjectController.extend({ publishedAtChanged: function () { this.set('publishedAt', formatDate(this.get('model.published_at'))); }.observes('model.published_at'), - + actions: { + save: function () { + var status = this.get('willPublish') ? 'published' : 'draft', + self = this; + this.set('model.status', status); + this.get('model').save().then(function () { + self.notifications.showSuccess('Post status saved as ' + this.get('model.status') + '.'); + }, this.notifications.showErrors); + }, + viewSaveTypes: function () { + this.toggleProperty('isViewingSaveTypes'); + }, + 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.'); + } + }, editSettings: function () { - this.toggleProperty('isEditingSettings'); - if (this.get('isEditingSettings')) { + var isEditing = this.toggleProperty('isEditingSettings'); + if (isEditing) { //Stop editing if the user clicks outside the settings view Ember.run.next(this, function () { var self = this; @@ -71,9 +96,9 @@ var PostController = Ember.ObjectController.extend({ slug = this.get('model.slug'), placeholder = this.get('slugPlaceholder'), self = this; - + newSlug = (!newSlug && placeholder) ? placeholder : newSlug; - + // Ignore unchanged slugs if (slug === newSlug) { return; @@ -93,7 +118,7 @@ var PostController = Ember.ObjectController.extend({ if (!this.get('isOnServer')) { return; } - + this.get('model').save('slug').then(function () { self.notifications.showSuccess('Permalink successfully changed to ' + this.get('model.slug') + '.'); }, this.notifications.showErrors); @@ -165,7 +190,7 @@ var PostController = Ember.ObjectController.extend({ if (!this.get('isOnServer')) { return; } - + this.get('model').save('published_at').then(function () { this.notifications.showSuccess('Publish date successfully changed to ' + this.get('publishedAt') + '.'); }, this.notifications.showErrors); @@ -173,4 +198,4 @@ var PostController = Ember.ObjectController.extend({ } }); -export default PostController; +export default PostController; \ No newline at end of file diff --git a/ghost/admin/routes/new.js b/ghost/admin/routes/new.js index eaebfd91af..ea320e8fec 100644 --- a/ghost/admin/routes/new.js +++ b/ghost/admin/routes/new.js @@ -1,12 +1,18 @@ -import styleBody from 'ghost/mixins/style-body'; import AuthenticatedRoute from 'ghost/routes/authenticated'; +import styleBody from 'ghost/mixins/style-body'; +import Post from 'ghost/models/post'; var NewRoute = AuthenticatedRoute.extend(styleBody, { + controllerName: 'posts/post', classNames: ['editor'], renderTemplate: function () { this.render('editor'); + }, + + model: function () { + return Post.create(); } }); -export default NewRoute; \ No newline at end of file +export default NewRoute; diff --git a/ghost/admin/templates/-publish-bar.hbs b/ghost/admin/templates/-publish-bar.hbs index 77f77a48a1..8a79a404a5 100644 --- a/ghost/admin/templates/-publish-bar.hbs +++ b/ghost/admin/templates/-publish-bar.hbs @@ -15,15 +15,7 @@ {{view "post-settings-menu-view"}} -
- - - {{!-- @TODO: implement popover --}} - -
+ {{view "editor-save-button" id="entry-actions"}} diff --git a/ghost/admin/templates/editor-save-button.hbs b/ghost/admin/templates/editor-save-button.hbs new file mode 100644 index 0000000000..6ef77ea0e9 --- /dev/null +++ b/ghost/admin/templates/editor-save-button.hbs @@ -0,0 +1,12 @@ + + +{{!-- @TODO: implement popover --}} + \ No newline at end of file diff --git a/ghost/admin/views/editor-save-button.js b/ghost/admin/views/editor-save-button.js new file mode 100644 index 0000000000..d462bb8b3e --- /dev/null +++ b/ghost/admin/views/editor-save-button.js @@ -0,0 +1,23 @@ +export default Ember.View.extend({ + templateName: 'editor-save-button', + tagName: 'section', + classNames: ['js-publish-splitbutton'], + classNameBindings: ['isDangerous:splitbutton-delete:splitbutton-save'], + + //Tracks whether we're going to change the state of the post on save + isDangerous: function () { + return this.get('controller.isPublished') !== this.get('controller.willPublish'); + }.property('controller.isPublished', 'controller.willPublish'), + + 'save-text': function () { + return this.get('controller.willPublish') ? this.get('publish-text') : this.get('draft-text'); + }.property('controller.willPublish'), + + 'publish-text': function () { + return this.get('controller.isPublished') ? 'Update Post' : 'Publish Now'; + }.property('controller.isPublished'), + + 'draft-text': function () { + return this.get('controller.isPublished') ? 'Unpublish' : 'Save Draft'; + }.property('controller.isPublished') +}); \ No newline at end of file