2014-10-28 09:29:42 -05:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-06-19 14:44:44 -05:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
2014-06-04 22:18:23 -05:00
|
|
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
2014-07-20 11:42:03 -05:00
|
|
|
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
|
2014-03-02 09:30:35 -05:00
|
|
|
|
2014-10-24 16:09:50 -05:00
|
|
|
var paginationSettings,
|
|
|
|
PostsRoute;
|
|
|
|
|
|
|
|
paginationSettings = {
|
2014-05-23 22:25:20 -05:00
|
|
|
status: 'all',
|
|
|
|
staticPages: 'all',
|
2014-06-20 05:40:32 -05:00
|
|
|
page: 1
|
2014-05-23 22:25:20 -05:00
|
|
|
};
|
|
|
|
|
2014-10-28 09:29:42 -05:00
|
|
|
PostsRoute = AuthenticatedRoute.extend(ShortcutsRoute, styleBody, loadingIndicator, PaginationRouteMixin, {
|
2014-11-25 15:56:08 -05:00
|
|
|
titleToken: 'Content',
|
|
|
|
|
2014-03-03 15:18:10 -05:00
|
|
|
classNames: ['manage'],
|
2014-03-02 09:30:35 -05:00
|
|
|
|
|
|
|
model: function () {
|
2014-07-30 11:44:49 -05:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
return this.store.find('user', 'me').then(function (user) {
|
|
|
|
if (user.get('isAuthor')) {
|
|
|
|
paginationSettings.author = user.get('slug');
|
|
|
|
}
|
2014-10-24 16:09:50 -05:00
|
|
|
|
2014-07-30 11:44:49 -05: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.
|
2014-07-30 21:44:51 -05:00
|
|
|
return self.store.filter('post', paginationSettings, function (post) {
|
|
|
|
if (user.get('isAuthor')) {
|
2014-07-31 03:29:05 -05:00
|
|
|
return post.isAuthoredByUser(user);
|
2014-07-30 21:44:51 -05:00
|
|
|
}
|
|
|
|
|
2014-07-30 11:44:49 -05:00
|
|
|
return true;
|
|
|
|
});
|
2014-05-23 22:25:20 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController: function (controller, model) {
|
|
|
|
this._super(controller, model);
|
2014-07-20 11:42:03 -05:00
|
|
|
this.setupPagination(paginationSettings);
|
2014-03-02 09:30:35 -05:00
|
|
|
},
|
2014-07-31 03:29:05 -05:00
|
|
|
|
2014-07-30 21:33:05 -05:00
|
|
|
stepThroughPosts: function (step) {
|
|
|
|
var currentPost = this.get('controller.currentPost'),
|
2014-08-02 09:39:26 -05:00
|
|
|
posts = this.get('controller.arrangedContent'),
|
2014-07-30 21:33:05 -05:00
|
|
|
length = posts.get('length'),
|
|
|
|
newPosition;
|
2014-07-31 03:29:05 -05:00
|
|
|
|
2014-07-30 21:33:05 -05:00
|
|
|
newPosition = posts.indexOf(currentPost) + step;
|
2014-07-31 03:29:05 -05:00
|
|
|
|
2014-08-07 08:12:51 -05:00
|
|
|
// if we are on the first or last item
|
|
|
|
// just do nothing (desired behavior is to not
|
|
|
|
// loop around)
|
2014-07-30 21:33:05 -05:00
|
|
|
if (newPosition >= length) {
|
2014-08-07 08:12:51 -05:00
|
|
|
return;
|
|
|
|
} else if (newPosition < 0) {
|
|
|
|
return;
|
2014-07-30 21:33:05 -05:00
|
|
|
}
|
2014-10-24 16:09:50 -05:00
|
|
|
|
2014-07-30 21:33:05 -05:00
|
|
|
this.transitionTo('posts.post', posts.objectAt(newPosition));
|
|
|
|
},
|
2014-07-31 03:29:05 -05:00
|
|
|
|
2014-10-15 20:56:32 -05:00
|
|
|
scrollContent: function (amount) {
|
|
|
|
var content = Ember.$('.js-content-preview'),
|
|
|
|
scrolled = content.scrollTop();
|
|
|
|
|
|
|
|
content.scrollTop(scrolled + 50 * amount);
|
|
|
|
},
|
|
|
|
|
2014-06-19 14:44:44 -05:00
|
|
|
shortcuts: {
|
2014-09-21 11:31:40 -05:00
|
|
|
'up, k': 'moveUp',
|
|
|
|
'down, j': 'moveDown',
|
2014-10-15 20:56:32 -05:00
|
|
|
left: 'focusList',
|
|
|
|
right: 'focusContent',
|
2014-10-24 16:09:50 -05:00
|
|
|
c: 'newPost'
|
2014-06-19 14:44:44 -05:00
|
|
|
},
|
2014-10-24 16:09:50 -05:00
|
|
|
|
2014-03-02 09:30:35 -05:00
|
|
|
actions: {
|
2014-10-15 20:56:32 -05:00
|
|
|
focusList: function () {
|
|
|
|
this.controller.set('keyboardFocus', 'postList');
|
|
|
|
},
|
|
|
|
focusContent: function () {
|
|
|
|
this.controller.set('keyboardFocus', 'postContent');
|
|
|
|
},
|
2014-09-21 11:31:40 -05:00
|
|
|
newPost: function () {
|
|
|
|
this.transitionTo('editor.new');
|
|
|
|
},
|
2014-10-24 16:09:50 -05:00
|
|
|
|
2014-06-19 14:44:44 -05:00
|
|
|
moveUp: function () {
|
2014-10-15 20:56:32 -05:00
|
|
|
if (this.controller.get('postContentFocused')) {
|
|
|
|
this.scrollContent(-1);
|
|
|
|
} else {
|
|
|
|
this.stepThroughPosts(-1);
|
|
|
|
}
|
2014-06-19 14:44:44 -05:00
|
|
|
},
|
2014-10-24 16:09:50 -05:00
|
|
|
|
2014-06-19 14:44:44 -05:00
|
|
|
moveDown: function () {
|
2014-10-15 20:56:32 -05:00
|
|
|
if (this.controller.get('postContentFocused')) {
|
|
|
|
this.scrollContent(1);
|
|
|
|
} else {
|
|
|
|
this.stepThroughPosts(1);
|
|
|
|
}
|
2014-03-02 09:30:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-03 15:18:10 -05:00
|
|
|
|
2014-04-20 09:48:34 -05:00
|
|
|
export default PostsRoute;
|