2014-06-21 01:36:44 +04:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
2014-07-06 00:44:19 +04:00
|
|
|
import NProgressSaveMixin from 'ghost/mixins/nprogress-save';
|
2014-06-21 01:36:44 +04:00
|
|
|
|
2014-07-06 00:44:19 +04:00
|
|
|
var Post = DS.Model.extend(NProgressSaveMixin, ValidationEngine, {
|
2014-06-21 01:36:44 +04:00
|
|
|
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'),
|
2014-10-25 01:09:50 +04:00
|
|
|
author: DS.belongsTo('user', {async: true}),
|
2014-07-31 06:44:51 +04:00
|
|
|
author_id: DS.attr('number'),
|
2014-06-05 20:04:59 +04:00
|
|
|
updated_at: DS.attr('moment-date'),
|
|
|
|
published_at: DS.attr('moment-date'),
|
2014-10-25 01:09:50 +04:00
|
|
|
published_by: DS.belongsTo('user', {async: true}),
|
|
|
|
tags: DS.hasMany('tag', {embedded: 'always'}),
|
2014-12-15 13:11:29 +03:00
|
|
|
url: DS.attr('string'),
|
2014-10-25 01:09:50 +04:00
|
|
|
|
|
|
|
// Computed post properties
|
|
|
|
|
2014-06-09 00:48:14 +04:00
|
|
|
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'),
|
2014-10-25 01:09:50 +04:00
|
|
|
oldTags = tags.filterBy('id', null);
|
2014-06-19 22:31:56 +04:00
|
|
|
|
|
|
|
tags.removeObjects(oldTags);
|
|
|
|
oldTags.invoke('deleteRecord');
|
2014-07-31 12:29:05 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
isAuthoredByUser: function (user) {
|
|
|
|
return parseInt(user.get('id'), 10) === parseInt(this.get('author_id'), 10);
|
2014-06-19 22:31:56 +04:00
|
|
|
}
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2014-03-03 00:12:06 +04:00
|
|
|
});
|
|
|
|
|
2014-06-09 00:48:14 +04:00
|
|
|
export default Post;
|