0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/admin/assets/js/models/post.js
cobbspur 8bbacd9ec9 closes #195 posts date on content page
- adds dateFormat handlebars helper for client side with extra option to format in time since style
- adds this extra dateFormat option to existing server side helper.
- adds scss for draft and scheduled status
- adds true/false values to post for draft  and published to validate in handlebars
- changes admin>content post collection query to order posts by updated_at values in router.js
- adds minified moment.js and links to moment.js and helper.js for clientside
2013-07-04 19:42:49 +01:00

47 lines
No EOL
1.3 KiB
JavaScript

/*global window, document, Ghost, $, _, Backbone */
(function () {
"use strict";
Ghost.Models.Post = Backbone.Model.extend({
defaults: {
status: 'draft'
},
parse: function (resp) {
if (resp.status) {
resp.published = !!(resp.status === "published");
resp.draft = !!(resp.status === "draft");
}
if (resp.tags) {
// TODO: parse tags into it's own collection on the model (this.tags)
return resp;
}
return resp;
},
validate: function (attrs) {
if (_.isEmpty(attrs.title)) {
return 'You must specify a title for the post.';
}
}
});
Ghost.Collections.Posts = Backbone.Collection.extend({
url: Ghost.settings.apiRoot + '/posts',
model: Ghost.Models.Post,
parse: function (resp) {
if (_.isArray(resp.posts)) {
this.limit = resp.limit;
this.currentPage = resp.page;
this.totalPages = resp.pages;
this.totalPosts = resp.total;
this.nextPage = resp.next;
this.prevPage = resp.prev;
return resp.posts;
}
return resp;
}
});
}());