szurubooru/client/js/controllers/user_list_controller.js

75 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
const api = require('../api.js');
const uri = require('../util/uri.js');
const UserList = require('../models/user_list.js');
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');
const EmptyView = require('../views/empty_view.js');
class UserListController {
constructor(ctx) {
if (!api.hasPrivilege('users:list')) {
this._view = new EmptyView();
this._view.showError('You don\'t have privileges to view users.');
return;
}
topNavigation.activate('users');
topNavigation.setTitle('Listing users');
this._ctx = ctx;
this._pageController = new PageController();
this._headerView = new UsersHeaderView({
hostNode: this._pageController.view.pageHeaderHolderNode,
parameters: ctx.parameters,
});
this._headerView.addEventListener(
'navigate', e => this._evtNavigate(e));
this._syncPageController();
}
showSuccess(message) {
this._pageController.showSuccess(message);
}
_evtNavigate(e) {
history.pushState(
null,
window.title,
uri.formatClientLink('users', e.detail.parameters));
Object.assign(this._ctx.parameters, e.detail.parameters);
this._syncPageController();
}
_syncPageController() {
this._pageController.run({
parameters: this._ctx.parameters,
2016-07-05 21:20:28 +02:00
getClientUrlForPage: page => {
const parameters = Object.assign(
{}, this._ctx.parameters, {page: page});
return uri.formatClientLink('users', parameters);
2016-07-05 21:20:28 +02:00
},
requestPage: page => {
return UserList.search(this._ctx.parameters.query, page);
},
pageRenderer: pageCtx => {
Object.assign(pageCtx, {
canViewUsers: api.hasPrivilege('users:view'),
});
return new UsersPageView(pageCtx);
},
});
}
}
module.exports = router => {
router.enter(
['users'],
(ctx, next) => { ctx.controller = new UserListController(ctx); });
};