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-07-30 20:44:49 +04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
return this.store.find('user', 'me').then(function (user) {
|
|
|
|
if (user.get('isAuthor')) {
|
|
|
|
paginationSettings.author = user.get('slug');
|
|
|
|
}
|
|
|
|
// 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.
|
2014-07-31 06:44:51 +04:00
|
|
|
return self.store.filter('post', paginationSettings, function (post) {
|
|
|
|
if (user.get('isAuthor')) {
|
2014-07-31 12:29:05 +04:00
|
|
|
return post.isAuthoredByUser(user);
|
2014-07-31 06:44:51 +04:00
|
|
|
}
|
|
|
|
|
2014-07-30 20:44:49 +04:00
|
|
|
return true;
|
|
|
|
});
|
2014-05-24 07:25:20 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
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 12:29:05 +04:00
|
|
|
|
2014-07-31 06:33:05 +04:00
|
|
|
stepThroughPosts: function (step) {
|
|
|
|
var currentPost = this.get('controller.currentPost'),
|
2014-08-02 18:39:26 +04:00
|
|
|
posts = this.get('controller.arrangedContent'),
|
2014-07-31 06:33:05 +04:00
|
|
|
length = posts.get('length'),
|
|
|
|
newPosition;
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2014-07-31 06:33:05 +04:00
|
|
|
newPosition = posts.indexOf(currentPost) + step;
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2014-08-07 17:12:51 +04:00
|
|
|
// if we are on the first or last item
|
|
|
|
// just do nothing (desired behavior is to not
|
|
|
|
// loop around)
|
2014-07-31 06:33:05 +04:00
|
|
|
if (newPosition >= length) {
|
2014-08-07 17:12:51 +04:00
|
|
|
return;
|
|
|
|
} else if (newPosition < 0) {
|
|
|
|
return;
|
2014-07-31 06:33:05 +04:00
|
|
|
}
|
|
|
|
this.transitionTo('posts.post', posts.objectAt(newPosition));
|
|
|
|
},
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2014-06-19 23:44:44 +04:00
|
|
|
shortcuts: {
|
|
|
|
'up': 'moveUp',
|
|
|
|
'down': 'moveDown'
|
|
|
|
},
|
2014-03-02 18:30:35 +04:00
|
|
|
actions: {
|
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;
|