0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/client/mixins/editor-base-controller.js
Matt Enlow b1176a8a67 Refactored PostSettingsMenuController
Closes #2845.
Ref #1351.
- Refactored `PostSettingsMenuController` to appropriately set and display
  slug and publish date and their placeholders.
- Removed api spam on title change by putting `slugPlaceholder` generation
  inside of an `Ember.run.debounce` call.
- Renamed `gh-blur-text-field` to `gh-blur-input`
- Created `SlugGenerator` class to abstract slug generation.
- Added `timestampVerification` function to `utils/date-formatting`
- `utils/date-formatting` now uses `strict` parsing of dates
- Added more acceptable date formats to accommodate strict parsing
- Moved `isDraft` and `isPublished` computed properties from
  `EditorController` to `PostModel`
2014-06-13 12:14:58 -06:00

54 lines
1.7 KiB
JavaScript

/* global console */
var EditorControllerMixin = Ember.Mixin.create({
/**
* 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, value) {
if (arguments.length > 1) {
return value;
}
return this.get('isPublished');
}.property('isPublished'),
// remove client-generated tags, which have `id: null`.
// Ember Data won't recognize/update them automatically
// when returned from the server with ids.
updateTags: function () {
var tags = this.get('model.tags'),
oldTags = tags.filterBy('id', null);
tags.removeObjects(oldTags);
oldTags.invoke('deleteRecord');
},
actions: {
save: function () {
var status = this.get('willPublish') ? 'published' : 'draft',
self = this;
this.set('status', status);
return this.get('model').save().then(function (model) {
self.updateTags();
self.notifications.showSuccess('Post status saved as <strong>' +
model.get('status') + '</strong>.');
return model;
}, 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;