mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
31f41822e0
Conflicts: .gitignore Gruntfile.js bower.json core/client/assets/lib/showdown/extensions/ghostdown.js core/client/assets/vendor/showdown/extensions/ghostdown.js core/client/router.js core/clientold/assets/vendor/chart.min.js core/clientold/assets/vendor/codemirror/addon/mode/overlay.js core/clientold/assets/vendor/codemirror/codemirror.js core/clientold/assets/vendor/codemirror/mode/gfm/gfm.js core/clientold/assets/vendor/codemirror/mode/gfm/index.html core/clientold/assets/vendor/codemirror/mode/gfm/test.js core/clientold/assets/vendor/codemirror/mode/markdown/index.html core/clientold/assets/vendor/codemirror/mode/markdown/markdown.js core/clientold/assets/vendor/codemirror/mode/markdown/test.js core/clientold/assets/vendor/countable.js core/clientold/assets/vendor/fastclick.js core/clientold/assets/vendor/icheck/jquery.icheck.min.js core/clientold/assets/vendor/jquery.hammer.min.js core/clientold/assets/vendor/nprogress.js core/clientold/assets/vendor/packery.pkgd.min.js core/clientold/assets/vendor/showdown/extensions/ghostdown.js core/clientold/assets/vendor/showdown/showdown.js core/clientold/assets/vendor/validator-client.js core/test/unit/client_ghostdown_spec.js core/test/unit/client_showdown_int_spec.js
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
/*global Ghost, _, Backbone */
|
|
(function () {
|
|
'use strict';
|
|
|
|
Ghost.Models.Post = Ghost.ProgressModel.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) {
|
|
return resp;
|
|
}
|
|
return resp;
|
|
},
|
|
|
|
validate: function (attrs) {
|
|
if (_.isEmpty(attrs.title)) {
|
|
return 'You must specify a title for the post.';
|
|
}
|
|
},
|
|
|
|
addTag: function (tagToAdd) {
|
|
var tags = this.get('tags') || [];
|
|
tags.push(tagToAdd);
|
|
this.set('tags', tags);
|
|
},
|
|
|
|
removeTag: function (tagToRemove) {
|
|
var tags = this.get('tags') || [];
|
|
tags = _.reject(tags, function (tag) {
|
|
return tag.id === tagToRemove.id || tag.name === tagToRemove.name;
|
|
});
|
|
this.set('tags', tags);
|
|
}
|
|
});
|
|
|
|
Ghost.Collections.Posts = Backbone.Collection.extend({
|
|
currentPage: 1,
|
|
totalPages: 0,
|
|
totalPosts: 0,
|
|
nextPage: 0,
|
|
prevPage: 0,
|
|
|
|
url: Ghost.paths.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;
|
|
}
|
|
});
|
|
|
|
}());
|