2016-06-14 10:31:48 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const api = require('../api.js');
|
|
|
|
const misc = require('../util/misc.js');
|
2016-06-19 19:16:40 +02:00
|
|
|
const UserList = require('../models/user_list.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
const topNavigation = require('../models/top_navigation.js');
|
|
|
|
const PageController = require('../controllers/page_controller.js');
|
|
|
|
const UsersHeaderView = require('../views/users_header_view.js');
|
|
|
|
const UsersPageView = require('../views/users_page_view.js');
|
2016-08-23 21:18:03 +02:00
|
|
|
const EmptyView = require('../views/empty_view.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
|
|
|
|
class UserListController {
|
|
|
|
constructor(ctx) {
|
2016-08-23 21:18:03 +02:00
|
|
|
if (!api.hasPrivilege('users:list')) {
|
|
|
|
this._view = new EmptyView();
|
|
|
|
this._view.showError('You don\'t have privileges to view users.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
topNavigation.activate('users');
|
2016-07-13 21:50:07 +02:00
|
|
|
topNavigation.setTitle('Listing users');
|
2016-06-14 10:31:48 +02:00
|
|
|
|
|
|
|
this._pageController = new PageController({
|
2016-07-07 21:18:35 +02:00
|
|
|
parameters: ctx.parameters,
|
2016-07-05 21:20:28 +02:00
|
|
|
getClientUrlForPage: page => {
|
2016-07-07 21:18:35 +02:00
|
|
|
const parameters = Object.assign(
|
|
|
|
{}, ctx.parameters, {page: page});
|
|
|
|
return '/users/' + misc.formatUrlParameters(parameters);
|
2016-07-05 21:20:28 +02:00
|
|
|
},
|
2016-06-19 19:16:40 +02:00
|
|
|
requestPage: page => {
|
2016-07-07 21:18:35 +02:00
|
|
|
return UserList.search(ctx.parameters.query, page);
|
2016-06-19 19:16:40 +02:00
|
|
|
},
|
2016-06-14 10:31:48 +02:00
|
|
|
headerRenderer: headerCtx => {
|
|
|
|
return new UsersHeaderView(headerCtx);
|
|
|
|
},
|
|
|
|
pageRenderer: pageCtx => {
|
|
|
|
Object.assign(pageCtx, {
|
|
|
|
canViewUsers: api.hasPrivilege('users:view'),
|
|
|
|
});
|
|
|
|
return new UsersPageView(pageCtx);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showSuccess(message) {
|
|
|
|
this._pageController.showSuccess(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = router => {
|
|
|
|
router.enter(
|
2016-07-07 21:18:35 +02:00
|
|
|
'/users/:parameters?',
|
|
|
|
(ctx, next) => { misc.parseUrlParametersRoute(ctx, next); },
|
2016-06-14 10:31:48 +02:00
|
|
|
(ctx, next) => { ctx.controller = new UserListController(ctx); });
|
|
|
|
};
|