2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-29 12:22:06 +02:00
|
|
|
const misc = require('../util/misc.js');
|
2016-04-06 21:49:26 +02:00
|
|
|
const page = require('page');
|
2016-04-01 00:20:34 +02:00
|
|
|
const topNavController = require('../controllers/top_nav_controller.js');
|
2016-05-29 12:21:25 +02:00
|
|
|
const EmptyView = require('../views/empty_view.js');
|
2016-03-19 21:37:04 +01:00
|
|
|
|
2016-04-01 00:20:34 +02:00
|
|
|
class PostsController {
|
2016-04-06 21:49:26 +02:00
|
|
|
registerRoutes() {
|
2016-05-20 21:35:12 +02:00
|
|
|
page('/upload', (ctx, next) => { this._uploadPostsRoute(); });
|
2016-05-29 12:22:06 +02:00
|
|
|
page('/posts/:query?',
|
|
|
|
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
|
|
|
|
(ctx, next) => { this._listPostsRoute(); });
|
2016-04-06 21:49:26 +02:00
|
|
|
page(
|
|
|
|
'/post/:id',
|
2016-05-20 21:35:12 +02:00
|
|
|
(ctx, next) => { this._showPostRoute(ctx.params.id); });
|
2016-04-06 21:49:26 +02:00
|
|
|
page(
|
|
|
|
'/post/:id/edit',
|
2016-05-20 21:35:12 +02:00
|
|
|
(ctx, next) => { this._editPostRoute(ctx.params.id); });
|
2016-05-29 12:21:25 +02:00
|
|
|
this._emptyView = new EmptyView();
|
2016-04-06 21:49:26 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:35:12 +02:00
|
|
|
_uploadPostsRoute() {
|
2016-04-01 00:20:34 +02:00
|
|
|
topNavController.activate('upload');
|
2016-05-29 12:21:25 +02:00
|
|
|
this._emptyView.render();
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:35:12 +02:00
|
|
|
_listPostsRoute() {
|
2016-04-01 00:20:34 +02:00
|
|
|
topNavController.activate('posts');
|
2016-05-29 12:21:25 +02:00
|
|
|
this._emptyView.render();
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:35:12 +02:00
|
|
|
_showPostRoute(id) {
|
2016-04-01 00:20:34 +02:00
|
|
|
topNavController.activate('posts');
|
2016-05-29 12:21:25 +02:00
|
|
|
this._emptyView.render();
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:35:12 +02:00
|
|
|
_editPostRoute(id) {
|
2016-04-01 00:20:34 +02:00
|
|
|
topNavController.activate('posts');
|
2016-05-29 12:21:25 +02:00
|
|
|
this._emptyView.render();
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 00:20:34 +02:00
|
|
|
module.exports = new PostsController();
|