2014-06-19 23:44:44 +04:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
2014-06-05 07:18:23 +04:00
|
|
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
2014-07-20 20:42:03 +04:00
|
|
|
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
|
2014-03-02 18:30:35 +04:00
|
|
|
|
2014-05-24 07:25:20 +04:00
|
|
|
var paginationSettings = {
|
|
|
|
status: 'all',
|
|
|
|
staticPages: 'all',
|
2014-06-20 14:40:32 +04:00
|
|
|
page: 1
|
2014-05-24 07:25:20 +04:00
|
|
|
};
|
|
|
|
|
2014-07-25 17:38:13 +04:00
|
|
|
var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, ShortcutsRoute, styleBody, loadingIndicator, PaginationRouteMixin, {
|
2014-03-04 00:18:10 +04:00
|
|
|
classNames: ['manage'],
|
2014-03-02 18:30:35 +04:00
|
|
|
|
|
|
|
model: function () {
|
2014-05-24 07:25:20 +04:00
|
|
|
// using `.filter` allows the template to auto-update when new models are pulled in from the server.
|
|
|
|
// we just need to 'return true' to allow all models by default.
|
|
|
|
return this.store.filter('post', paginationSettings, function () {
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController: function (controller, model) {
|
|
|
|
this._super(controller, model);
|
2014-07-20 20:42:03 +04:00
|
|
|
this.setupPagination(paginationSettings);
|
2014-03-02 18:30:35 +04:00
|
|
|
},
|
2014-07-31 06:33:05 +04:00
|
|
|
|
|
|
|
stepThroughPosts: function (step) {
|
|
|
|
var currentPost = this.get('controller.currentPost'),
|
|
|
|
posts = this.get('controller.model'),
|
|
|
|
length = posts.get('length'),
|
|
|
|
newPosition;
|
|
|
|
|
|
|
|
newPosition = posts.indexOf(currentPost) + step;
|
|
|
|
|
|
|
|
//Make sure we're inbounds
|
|
|
|
if (newPosition >= length) {
|
|
|
|
newPosition = 0;
|
|
|
|
}
|
|
|
|
else if (newPosition < 0) {
|
|
|
|
newPosition = length - 1;
|
|
|
|
}
|
|
|
|
this.transitionTo('posts.post', posts.objectAt(newPosition));
|
|
|
|
},
|
|
|
|
|
2014-06-19 23:44:44 +04:00
|
|
|
shortcuts: {
|
|
|
|
'up': 'moveUp',
|
|
|
|
'down': 'moveDown'
|
|
|
|
},
|
2014-03-02 18:30:35 +04:00
|
|
|
actions: {
|
|
|
|
openEditor: function (post) {
|
2014-06-21 18:44:53 +04:00
|
|
|
this.transitionTo('editor.edit', post);
|
2014-06-19 23:44:44 +04:00
|
|
|
},
|
|
|
|
moveUp: function () {
|
2014-07-31 06:33:05 +04:00
|
|
|
this.stepThroughPosts(-1);
|
2014-06-19 23:44:44 +04:00
|
|
|
},
|
|
|
|
moveDown: function () {
|
2014-07-31 06:33:05 +04:00
|
|
|
this.stepThroughPosts(1);
|
2014-03-02 18:30:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-04 00:18:10 +04:00
|
|
|
|
2014-04-20 18:48:34 +04:00
|
|
|
export default PostsRoute;
|