New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to mark a post as static page #1147

Merged
merged 1 commit into from Oct 28, 2013
Jump to file or symbol
Failed to load files and symbols.
+87 −8
Diff settings

Always

Just for now

@@ -856,7 +856,7 @@ nav {
}
.post-setting {
min-width: 260px;
min-width: 300px;
border-bottom: 1px solid #35393b;
&:first-child {
View
@@ -31,7 +31,7 @@
blog: function () {
var posts = new Ghost.Collections.Posts();
NProgress.start();
posts.fetch({ data: { status: 'all', orderBy: ['updated_at', 'DESC'] } }).then(function () {
posts.fetch({ data: { status: 'all', orderBy: ['updated_at', 'DESC'], where: { page: 'all' } } }).then(function () {
Ghost.currentView = new Ghost.Views.Blog({ el: '#main', collection: posts });
NProgress.done();
});
@@ -1,4 +1,4 @@
<a class="permalink{{#if featured}} featured{{/if}}" href="#" title="Edit this post">
<a class="permalink{{#if featured}} featured{{/if}}{{#if page}} page{{/if}}" href="#" title="Edit this post">
<h3 class="entry-title">{{{title}}}</h3>
<section class="entry-meta">
<time datetime="2013-01-04" class="date">
@@ -8,6 +8,9 @@
<span class="status-draft">Draft</span>
{{/if}}
</time>
{{#if page}}
| <span class="page">Static Page</span>
{{/if}}
{{!<span class="views">1,934</span>}}
</section>
</a>
</a>
@@ -27,6 +27,14 @@
<input class="post-setting-date" type="text" value="">
</div>
</li>
<li class="post-setting">
<div class="post-setting-label">
<label for="static-page">Static Page</label>
</div>
<div class="post-setting-field">
<input id="static-page" class="post-setting-static-page" type="checkbox" value="">
</div>
</li>
<li><a href="#" class="delete hidden">Delete This Post</a></li>
</ul>
</section>
@@ -93,6 +93,7 @@
data: {
status: 'all',
page: (self.collection.currentPage + 1),
where: { page: 'all' },
orderBy: ['updated_at', 'DESC']
}
}).then(function onSuccess(response) {
@@ -135,6 +136,7 @@
initialize: function () {
this.listenTo(Backbone, 'blog:activeItem', this.checkActive);
this.listenTo(this.model, 'change:page', this.render);
this.listenTo(this.model, 'destroy', this.removeItem);
},
@@ -11,6 +11,7 @@
'blur .post-setting-slug' : 'editSlug',
'click .post-setting-slug' : 'selectSlug',
'blur .post-setting-date' : 'editDate',
'click .post-setting-static-page' : 'toggleStaticPage',
'click .delete' : 'deletePost'
},
@@ -19,6 +20,7 @@
this.listenTo(this.model, 'change:id', this.render);
this.listenTo(this.model, 'change:status', this.render);
this.listenTo(this.model, 'change:published_at', this.render);
this.listenTo(this.model, 'change:page', this.render);
}
},
@@ -29,12 +31,18 @@
$('.post-setting-slug').val(slug);
// Update page status test if already a page.
if (this.model && this.model.get('page')) {
$('.post-setting-static-page').prop('checked', this.model.get('page'));
}
// Insert the published date, and make it editable if it exists.
if (this.model && this.model.get('published_at')) {
pubDate = moment(pubDate).format('DD MMM YY');
}
if (this.model && this.model.get('id')) {
this.$('.post-setting-page').removeClass('hidden');
this.$('.delete').removeClass('hidden');
}
@@ -141,6 +149,32 @@
},
toggleStaticPage: function (e) {
e.preventDefault();
var pageEl = $(e.currentTarget),
page = this.model ? !this.model.get('page') : false;
this.model.save({
page: page
}, {
success : function (model, response, options) {
pageEl.prop('checked', page);
Ghost.notifications.addItem({
type: 'success',
message: "Successfully converted " + (page ? "to static page" : "to post") + '.',
status: 'passive'
});
},
error : function (model, xhr) {
Ghost.notifications.addItem({
type: 'error',
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
status: 'passive'
});
}
});
},
deletePost: function (e) {
e.preventDefault();
var self = this;
@@ -219,7 +219,8 @@ coreHelpers = function (ghost) {
ghost.registerThemeHelper('body_class', function (options) {
var classes = [],
tags = this.post && this.post.tags ? this.post.tags : this.tags || [];
tags = this.post && this.post.tags ? this.post.tags : this.tags || [],
page = this.post && this.post.page ? this.post.page : this.page || false;
if (_.isString(this.path) && this.path.match(/\/page/)) {
classes.push('archive-template');
@@ -233,6 +234,10 @@ coreHelpers = function (ghost) {
classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; }));
}
if (page) {
classes.push('page');
}
return ghost.doFilter('body_class', classes, function (classes) {
var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(classString.trim());
@@ -242,7 +247,8 @@ coreHelpers = function (ghost) {
ghost.registerThemeHelper('post_class', function (options) {
var classes = ['post'],
tags = this.post && this.post.tags ? this.post.tags : this.tags || [],
featured = this.post && this.post.featured ? this.post.featured : this.featured || false;
featured = this.post && this.post.featured ? this.post.featured : this.featured || false,
page = this.post && this.post.page ? this.post.page : this.page || false;
if (tags) {
classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; }));
@@ -252,6 +258,10 @@ coreHelpers = function (ghost) {
classes.push('featured');
}
if (page) {
classes.push('page');
}
return ghost.doFilter('post_class', classes, function (classes) {
var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(classString.trim());
@@ -20,7 +20,7 @@ Post = ghostBookshelf.Model.extend({
permittedAttributes: [
'id', 'uuid', 'title', 'slug', 'markdown', 'html', 'meta_title', 'meta_description',
'featured', 'image', 'status', 'language', 'author_id', 'created_at', 'created_by', 'updated_at', 'updated_by',
'published_at', 'published_by'
'page', 'published_at', 'published_by'
],
defaults: function () {
@@ -225,13 +225,17 @@ Post = ghostBookshelf.Model.extend({
opts = _.extend({
page: 1,
limit: 15,
where: {},
where: { page: false },
status: 'published',
orderBy: ['published_at', 'DESC']
}, opts);
postCollection = Posts.forge();
if (opts.where && opts.where.page === 'all') {
delete opts.where.page;
}
// Unless `all` is passed as an option, filter on
// the status provided.
if (opts.status !== 'all') {
@@ -60,6 +60,14 @@
<input id="pub-date" class="post-setting-date" type="text" value=""><!--<span class="post-setting-calendar"></span>-->
</div>
</li>
<li class="post-setting">
<div class="post-setting-label">
<label for="static-page">Static Page</label>
</div>
<div class="post-setting-field">
<input id="static-page" class="post-setting-static-page" type="checkbox" value="">
</div>
</li>
<li><a href="#" class="delete hidden">Delete This Post</a></li>
</ul>
</section>
@@ -184,6 +184,16 @@ describe('Core Helpers', function () {
rendered2.string.should.equal('post-template');
rendered3.string.should.equal('archive-template');
});
it('can render class for static page', function () {
var rendered = handlebars.helpers.body_class.call(
{post: {page: true}},
{path: '/'}
);
should.exist(rendered);
rendered.string.should.equal('home-template page');
});
});
describe('post_class Helper', function () {
ProTip! Use n and p to navigate between commits in a pull request.