<commit_before>/* global moment */
import {parseDateString, formatDate} from 'ghost/utils/date-formatting';
import SlugGenerator from 'ghost/models/slug-generator';
import boundOneWay from 'ghost/utils/bound-one-way';

var PostSettingsMenuController = Ember.ObjectController.extend({
    init: function () {
        this._super();

        // when creating a new post we want to observe the title
        // to generate the post's slug
        if (this.get('isNew')) {
            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},
    /**
     * The placeholder is the published date of the post,
     * or the current date if the pubdate has not been set.
     */
    publishedAtPlaceholder: function () {
        var pubDate = this.get('published_at');
        if (pubDate) {
            return formatDate(pubDate);
        }
        return formatDate(moment());
    }.property('publishedAtValue'),
    publishedAtValue: boundOneWay('published_at', formatDate),

    slugValue: boundOneWay('slug'),
    //Lazy load the slug generator for slugPlaceholder
    slugGenerator: Ember.computed(function () {<commit_msg>Fix for missing author when switching posts<commit_after>/* global moment */
import {parseDateString, formatDate} from 'ghost/utils/date-formatting';
import SlugGenerator from 'ghost/models/slug-generator';
import boundOneWay from 'ghost/utils/bound-one-way';

var PostSettingsMenuController = Ember.ObjectController.extend({
    init: function () {
        this._super();

        // when creating a new post we want to observe the title
        // to generate the post's slug
        if (this.get('isNew')) {
            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 = {},
            self = this;

        deferred.promise = this.store.find('user').then(function (users) {
            return users.rejectBy('id', 'me');
        }).then(function (users) {
            self.set('selectedAuthor', users.get('firstObject'));

            return users;
        });

        return Ember.ArrayProxy
            .extend(Ember.PromiseProxyMixin)
            .create(deferred);
    }.property(),
    //Changes in the PSM are too minor to warrant NProgress firing
    saveOptions: {disableNProgress: true},
    /**
     * The placeholder is the published date of the post,
     * or the current date if the pubdate has not been set.
     */
    publishedAtPlaceholder: function () {
        var pubDate = this.get('published_at');
        if (pubDate) {
            return formatDate(pubDate);
        }
        return formatDate(moment());
    }.property('publishedAtValue'),
    publishedAtValue: boundOneWay('published_at', formatDate),

    slugValue: boundOneWay('slug'),
    //Lazy load the slug generator for slugPlaceholder
    slugGenerator: Ember.computed(function () {
{'fraction_non_alphanumeric': 0.12544878563885956, 'fraction_numerical': 0.0, 'mean_word_length': 2.4797942689199117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3511411', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1255, 'n_words': 324}