2013-06-25 16:23:09 +04:00
|
|
|
/*global window, document, Ghost, $, _, Backbone */
|
2013-05-31 09:58:20 +04:00
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
2013-06-02 03:45:02 +04:00
|
|
|
Ghost.Models.Post = Backbone.Model.extend({
|
|
|
|
|
2013-05-31 09:58:20 +04:00
|
|
|
defaults: {
|
|
|
|
status: 'draft'
|
2013-06-02 03:45:02 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
parse: function (resp) {
|
|
|
|
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.';
|
|
|
|
}
|
2013-05-31 09:58:20 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-02 03:45:02 +04:00
|
|
|
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;
|
|
|
|
return resp.posts;
|
|
|
|
}
|
|
|
|
return resp;
|
|
|
|
}
|
2013-05-31 09:58:20 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
}());
|