2014-06-20 23:36:44 +02:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
|
|
|
|
|
|
|
var Post = DS.Model.extend(ValidationEngine, {
|
|
|
|
validationType: 'post',
|
|
|
|
|
2014-05-09 07:00:10 +02:00
|
|
|
uuid: DS.attr('string'),
|
|
|
|
title: DS.attr('string'),
|
|
|
|
slug: DS.attr('string'),
|
2014-05-31 20:32:22 +02:00
|
|
|
markdown: DS.attr('string', {defaultValue: ''}),
|
2014-05-09 07:00:10 +02:00
|
|
|
html: DS.attr('string'),
|
|
|
|
image: DS.attr('string'),
|
2014-05-31 20:32:22 +02: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 07:00:10 +02:00
|
|
|
meta_title: DS.attr('string'),
|
|
|
|
meta_description: DS.attr('string'),
|
|
|
|
author: DS.belongsTo('user', { async: true }),
|
2014-06-05 18:04:59 +02:00
|
|
|
created_at: DS.attr('moment-date'),
|
2014-05-09 07:00:10 +02:00
|
|
|
created_by: DS.belongsTo('user', { async: true }),
|
2014-06-05 18:04:59 +02:00
|
|
|
updated_at: DS.attr('moment-date'),
|
2014-05-09 07:00:10 +02:00
|
|
|
updated_by: DS.belongsTo('user', { async: true }),
|
2014-06-05 18:04:59 +02:00
|
|
|
published_at: DS.attr('moment-date'),
|
2014-05-09 07:00:10 +02:00
|
|
|
published_by: DS.belongsTo('user', { async: true }),
|
|
|
|
tags: DS.hasMany('tag', { async: true }),
|
2014-06-17 21:17:08 +02:00
|
|
|
|
2014-06-08 22:48:14 +02:00
|
|
|
//## Computed post properties
|
|
|
|
isPublished: Ember.computed.equal('status', 'published'),
|
|
|
|
isDraft: Ember.computed.equal('status', 'draft'),
|
2014-05-09 07:00:10 +02:00
|
|
|
|
2014-06-19 20:31:56 +02: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 21:12:06 +01:00
|
|
|
});
|
|
|
|
|
2014-06-08 22:48:14 +02:00
|
|
|
export default Post;
|