2014-05-09 09:00:10 +04:00
|
|
|
var Post = DS.Model.extend({
|
|
|
|
uuid: DS.attr('string'),
|
|
|
|
title: DS.attr('string'),
|
|
|
|
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 }),
|
|
|
|
created_at: DS.attr('date'),
|
|
|
|
created_by: DS.belongsTo('user', { async: true }),
|
|
|
|
updated_at: DS.attr('date'),
|
|
|
|
updated_by: DS.belongsTo('user', { async: true }),
|
|
|
|
published_at: DS.attr('date'),
|
|
|
|
published_by: DS.belongsTo('user', { async: true }),
|
|
|
|
tags: DS.hasMany('tag', { async: true }),
|
2014-04-20 18:48:34 +04:00
|
|
|
|
|
|
|
generateSlug: function () {
|
2014-05-09 09:00:10 +04:00
|
|
|
var title = this.get('title'),
|
2014-05-29 19:14:36 +04:00
|
|
|
url;
|
|
|
|
|
|
|
|
if (!title) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = this.get('ghostPaths').apiUrl('slugs', 'post', encodeURIComponent(title));
|
2014-04-20 18:48:34 +04:00
|
|
|
|
|
|
|
return ic.ajax.request(url, {
|
2014-05-09 09:00:10 +04:00
|
|
|
type: 'GET'
|
|
|
|
});
|
2014-04-20 18:48:34 +04:00
|
|
|
},
|
2014-05-09 09:00:10 +04:00
|
|
|
|
2014-05-31 22:32:22 +04:00
|
|
|
validate: function () {
|
2014-04-20 18:48:34 +04:00
|
|
|
var validationErrors = [];
|
|
|
|
|
2014-05-09 09:00:10 +04:00
|
|
|
if (!this.get('title.length')) {
|
2014-04-20 18:48:34 +04:00
|
|
|
validationErrors.push({
|
2014-06-02 00:53:16 +04:00
|
|
|
message: 'You must specify a title for the post.'
|
2014-04-20 18:48:34 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return validationErrors;
|
2014-05-09 09:00:10 +04:00
|
|
|
}.property('title')
|
2014-03-03 00:12:06 +04:00
|
|
|
});
|
|
|
|
|
2014-05-09 09:00:10 +04:00
|
|
|
export default Post;
|