2014-06-20 16:36:44 -05:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
2014-07-03 12:09:05 -05:00
|
|
|
import boundOneWay from 'ghost/utils/bound-one-way';
|
2014-06-20 16:36:44 -05:00
|
|
|
|
|
|
|
var Post = DS.Model.extend(ValidationEngine, {
|
|
|
|
validationType: 'post',
|
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
uuid: DS.attr('string'),
|
2014-06-23 12:50:28 -05:00
|
|
|
title: DS.attr('string', {defaultValue: ''}),
|
2014-05-09 00:00:10 -05:00
|
|
|
slug: DS.attr('string'),
|
2014-05-31 13:32:22 -05:00
|
|
|
markdown: DS.attr('string', {defaultValue: ''}),
|
2014-05-09 00:00:10 -05:00
|
|
|
html: DS.attr('string'),
|
|
|
|
image: DS.attr('string'),
|
2014-05-31 13:32:22 -05:00
|
|
|
featured: DS.attr('boolean', {defaultValue: false}),
|
|
|
|
page: DS.attr('boolean', {defaultValue: false}),
|
|
|
|
status: DS.attr('string', {defaultValue: 'draft'}),
|
|
|
|
language: DS.attr('string', {defaultValue: 'en_US'}),
|
2014-05-09 00:00:10 -05:00
|
|
|
meta_title: DS.attr('string'),
|
|
|
|
meta_description: DS.attr('string'),
|
|
|
|
author: DS.belongsTo('user', { async: true }),
|
2014-06-05 11:04:59 -05:00
|
|
|
created_at: DS.attr('moment-date'),
|
2014-05-09 00:00:10 -05:00
|
|
|
created_by: DS.belongsTo('user', { async: true }),
|
2014-06-05 11:04:59 -05:00
|
|
|
updated_at: DS.attr('moment-date'),
|
2014-05-09 00:00:10 -05:00
|
|
|
updated_by: DS.belongsTo('user', { async: true }),
|
2014-06-05 11:04:59 -05:00
|
|
|
published_at: DS.attr('moment-date'),
|
2014-05-09 00:00:10 -05:00
|
|
|
published_by: DS.belongsTo('user', { async: true }),
|
2014-06-26 21:35:25 -05:00
|
|
|
tags: DS.hasMany('tag', { embedded: 'always' }),
|
2014-07-03 12:09:05 -05:00
|
|
|
titleScratch: boundOneWay('title'),
|
2014-06-08 15:48:14 -05:00
|
|
|
//## Computed post properties
|
|
|
|
isPublished: Ember.computed.equal('status', 'published'),
|
|
|
|
isDraft: Ember.computed.equal('status', 'draft'),
|
2014-05-09 00:00:10 -05:00
|
|
|
|
2014-06-19 13:31:56 -05:00
|
|
|
// 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('tags'),
|
|
|
|
oldTags = tags.filterBy('id', null);
|
|
|
|
|
|
|
|
tags.removeObjects(oldTags);
|
|
|
|
oldTags.invoke('deleteRecord');
|
|
|
|
}
|
2014-03-02 15:12:06 -05:00
|
|
|
});
|
|
|
|
|
2014-06-08 15:48:14 -05:00
|
|
|
export default Post;
|