Merge pull request #3324 from novaugust/psm-authors

Add Author dropdown to PostSettingsMenu
This commit is contained in:
Hannah Wolfe 2014-07-19 01:43:43 +01:00
commit cf4dd8eaa5
3 changed files with 51 additions and 4 deletions

View File

@ -13,6 +13,33 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
this.addObserver('titleScratch', this, 'titleObserver');
}
},
selectedAuthor: Ember.computed.oneWay('author'),
changeAuthor: function () {
var author = this.get('author'),
selectedAuthor = this.get('selectedAuthor'),
model = this.get('model'),
self = this;
//return if nothing changed
if (selectedAuthor.get('id') === author.get('id')) {
return;
}
model.set('author', selectedAuthor);
model.save(this.get('saveOptions')).catch(function (errors) {
self.showErrors(errors);
self.set('selectedAuthor', author);
model.rollback();
});
}.observes('selectedAuthor'),
authors: function () {
//Loaded asynchronously, so must use promise proxies.
var deferred = {};
deferred.promise = this.store.find('user').then(function (users) {
return users.rejectBy('id', 'me');
});
return Ember.ArrayProxy
.extend(Ember.PromiseProxyMixin)
.create(deferred);
}.property(),
//Changes in the PSM are too minor to warrant NProgress firing
saveOptions: {disableNProgress: true},
/**
@ -39,7 +66,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
generateSlugPlaceholder: function () {
var self = this,
title = this.get('titleScratch');
this.get('slugGenerator').generateSlug(title).then(function (slug) {
self.set('slugPlaceholder', slug);
});
@ -97,7 +124,7 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
updateSlug: function (newSlug) {
var slug = this.get('slug'),
self = this;
newSlug = newSlug || slug;
newSlug = newSlug.trim();
@ -210,4 +237,4 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
}
});
export default PostSettingsMenuController;
export default PostSettingsMenuController;

View File

@ -4,7 +4,12 @@ var EditorNewRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin
classNames: ['editor'],
model: function () {
return this.store.createRecord('post');
var self = this;
return this.get('session.user').then(function (user) {
return self.store.createRecord('post', {
author: user
});
});
},
setupController: function (controller, model) {

View File

@ -19,6 +19,21 @@
</tr>
<tr class="post-setting">
<td class="post-setting-label">
<label for="post-setting-author">Author</label>
</td>
<td class="post-setting-field">
<span class="author-select-wrapper" {{bind-attr data-select-text=selectedAuthor.name}}>
{{view Ember.Select
name="post-setting-author"
content=authors
optionValuePath="content.id"
optionLabelPath="content.name"
selection=selectedAuthor}}
</span>
</td>
</tr>
<tr class="post-setting">
<td class="post-setting-label">
<label class="label" for="static-page">Static Page</label>
</td>
<td class="post-setting-item">