mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
30b4eb07f7
- This is a first pass at getting a more logical structure. The focus is on moving from admin/frontend to client/server. - The location of the databases is highly important, this isn't expected to change again In the future - client/assets should probably become public/ - more stuff should be shared (helpers etc) - cleanup some confusion around tpl and views
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/*global window, document, Ghost, $, _, Backbone */
|
|
(function () {
|
|
"use strict";
|
|
|
|
Ghost.Models.Post = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
status: 'draft'
|
|
},
|
|
|
|
blacklist: ['published', '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;
|
|
}
|
|
});
|
|
|
|
}()); |