From ad3ff49bea81d7a9499523ea805bf0cab1a2e037 Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Wed, 16 Jul 2014 23:54:32 -0600 Subject: [PATCH] Add Author dropdown to PostSettingsMenu Ref #3084 This PR does NOT hide the dropdown as required to close 3084. - `EditorNewRoute` creates post with the author set to the current user - added `authors` ArrayPromiseProxy (whoa, what?) to PSM - added `changeAuthor` function that sets author and saves model when the user selects a new author --- core/client/controllers/post-settings-menu.js | 33 +++++++++++++++++-- core/client/routes/editor/new.js | 7 +++- core/client/templates/post-settings-menu.hbs | 15 +++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/core/client/controllers/post-settings-menu.js b/core/client/controllers/post-settings-menu.js index cba393da0c..22e318c41c 100644 --- a/core/client/controllers/post-settings-menu.js +++ b/core/client/controllers/post-settings-menu.js @@ -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; \ No newline at end of file diff --git a/core/client/routes/editor/new.js b/core/client/routes/editor/new.js index fdb26e0656..6eee9eadc9 100644 --- a/core/client/routes/editor/new.js +++ b/core/client/routes/editor/new.js @@ -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) { diff --git a/core/client/templates/post-settings-menu.hbs b/core/client/templates/post-settings-menu.hbs index e5b532924f..95f9a9953b 100644 --- a/core/client/templates/post-settings-menu.hbs +++ b/core/client/templates/post-settings-menu.hbs @@ -19,6 +19,21 @@ + + + + + {{view Ember.Select + name="post-setting-author" + content=authors + optionValuePath="content.id" + optionLabelPath="content.name" + selection=selectedAuthor}} + + + + +