mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Merge pull request #2948 from appleYaks/tags-fix
Fix serializing/deserializing Tags on save from the Editor
This commit is contained in:
commit
17812ceb61
2 changed files with 30 additions and 0 deletions
|
@ -16,6 +16,17 @@ var EditorControllerMixin = Ember.Mixin.create({
|
|||
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',
|
||||
|
@ -23,6 +34,8 @@ var EditorControllerMixin = Ember.Mixin.create({
|
|||
|
||||
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;
|
||||
|
|
17
core/client/serializers/post.js
Normal file
17
core/client/serializers/post.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import ApplicationSerializer from 'ghost/serializers/application';
|
||||
|
||||
var PostSerializer = ApplicationSerializer.extend({
|
||||
serializeHasMany: function (record, json, relationship) {
|
||||
var key = relationship.key;
|
||||
|
||||
if (key === 'tags') {
|
||||
json[key] = Ember.get(record, key).map(function (tag) {
|
||||
return tag.serialize({ includeId: true });
|
||||
});
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default PostSerializer;
|
Loading…
Add table
Reference in a new issue