0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/client/models/post.js
Jacob Gable 5abeadf80d Ember Data with Posts
Ref #2699

- Introduce ember data dependency
- Add loadInitializers and refactor most initializers into one combined
- Add Post ember data model
- Refactor generateSlug to use title of post and ghostPaths
- Refactor post controller to not reference model.property everywhere
- Use RESTAdapter for posts, users and tags
- Setup author and tag relations in Post model
- Fix broken API calls by adding CSRF header
- Add initiaizer for csrf value
- Use actual User model for current user initializer
- Add action for setting featured post, test with actual api call
- Fix the sending of UUID's up to the server
- Refactor current-user to use ember-data store
- If a user is preloaded in the application, use pushPayload to put it
in the store
- Do a lookup on the store to get an actual User model for injection
- Fix posts/post controllerName in route/new.js
- Alter signup process to push user into ember data store
2014-05-29 07:42:51 -05:00

45 lines
No EOL
1.3 KiB
JavaScript

var Post = DS.Model.extend({
uuid: DS.attr('string'),
title: DS.attr('string'),
slug: DS.attr('string'),
markdown: DS.attr('string'),
html: DS.attr('string'),
image: DS.attr('string'),
featured: DS.attr('boolean'),
page: DS.attr('boolean'),
status: DS.attr('string'),
language: DS.attr('string'),
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 }),
generateSlug: function () {
var title = this.get('title'),
url = this.get('ghostPaths').apiUrl('posts', 'slug', encodeURIComponent(title));
return ic.ajax.request(url, {
type: 'GET'
});
},
validationErrors: function () {
var validationErrors = [];
if (!this.get('title.length')) {
validationErrors.push({
message: "You must specify a title for the post."
});
}
return validationErrors;
}.property('title')
});
export default Post;