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