Allow user to mark a post as static page

- Increased post-settings width to properly display "Static Page"
- Changed templates to display "Static Page" if set
- Added unit test for body_class helper

fixes #969
This commit is contained in:
Fabian Becker 2013-10-17 05:21:56 +00:00
parent ca224ecda4
commit 83595b9ca8
6 changed files with 51 additions and 4 deletions

View File

@ -856,7 +856,7 @@ nav {
}
.post-setting {
min-width: 260px;
min-width: 300px;
border-bottom: 1px solid #35393b;
&:first-child {

View File

@ -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();
});

View File

@ -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>

View File

@ -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>

View File

@ -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);
},

View File

@ -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;