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