2020-06-06 00:03:37 +02:00
|
|
|
"use strict";
|
2016-06-14 10:31:48 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const api = require("../api.js");
|
|
|
|
const router = require("../router.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");
|
2016-06-14 10:31:48 +02:00
|
|
|
|
|
|
|
class UserListController {
|
|
|
|
constructor(ctx) {
|
2020-05-04 09:09:33 +02:00
|
|
|
this._pageController = new PageController();
|
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
if (!api.hasPrivilege("users:list")) {
|
2016-08-23 21:18:03 +02:00
|
|
|
this._view = new EmptyView();
|
2020-06-06 00:03:37 +02:00
|
|
|
this._view.showError("You don't have privileges to view users.");
|
2016-08-23 21:18:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
topNavigation.activate("users");
|
|
|
|
topNavigation.setTitle("Listing users");
|
2016-06-14 10:31:48 +02:00
|
|
|
|
2016-08-28 18:53:06 +02:00
|
|
|
this._ctx = ctx;
|
|
|
|
|
|
|
|
this._headerView = new UsersHeaderView({
|
|
|
|
hostNode: this._pageController.view.pageHeaderHolderNode,
|
2016-07-07 21:18:35 +02:00
|
|
|
parameters: ctx.parameters,
|
2016-08-28 18:53:06 +02:00
|
|
|
});
|
2020-06-06 00:03:37 +02:00
|
|
|
this._headerView.addEventListener("navigate", (e) =>
|
|
|
|
this._evtNavigate(e)
|
|
|
|
);
|
2016-08-28 18:53:06 +02:00
|
|
|
|
|
|
|
this._syncPageController();
|
|
|
|
}
|
|
|
|
|
|
|
|
showSuccess(message) {
|
|
|
|
this._pageController.showSuccess(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
_evtNavigate(e) {
|
2017-04-24 23:02:25 +02:00
|
|
|
router.showNoDispatch(
|
2020-06-06 00:03:37 +02:00
|
|
|
uri.formatClientLink("users", e.detail.parameters)
|
|
|
|
);
|
2016-08-28 18:53:06 +02:00
|
|
|
Object.assign(this._ctx.parameters, e.detail.parameters);
|
|
|
|
this._syncPageController();
|
|
|
|
}
|
|
|
|
|
|
|
|
_syncPageController() {
|
|
|
|
this._pageController.run({
|
|
|
|
parameters: this._ctx.parameters,
|
2017-02-09 00:48:06 +01:00
|
|
|
defaultLimit: 30,
|
|
|
|
getClientUrlForPage: (offset, limit) => {
|
2020-06-06 00:03:37 +02:00
|
|
|
const parameters = Object.assign({}, this._ctx.parameters, {
|
|
|
|
offset: offset,
|
|
|
|
limit: limit,
|
|
|
|
});
|
|
|
|
return uri.formatClientLink("users", parameters);
|
2016-07-05 21:20:28 +02:00
|
|
|
},
|
2017-02-09 00:48:06 +01:00
|
|
|
requestPage: (offset, limit) => {
|
|
|
|
return UserList.search(
|
2020-06-06 00:03:37 +02:00
|
|
|
this._ctx.parameters.query,
|
|
|
|
offset,
|
|
|
|
limit
|
|
|
|
);
|
2016-06-14 10:31:48 +02:00
|
|
|
},
|
2020-06-06 00:03:37 +02:00
|
|
|
pageRenderer: (pageCtx) => {
|
2016-06-14 10:31:48 +02:00
|
|
|
Object.assign(pageCtx, {
|
2020-06-06 00:03:37 +02:00
|
|
|
canViewUsers: api.hasPrivilege("users:view"),
|
2016-06-14 10:31:48 +02:00
|
|
|
});
|
|
|
|
return new UsersPageView(pageCtx);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
module.exports = (router) => {
|
|
|
|
router.enter(["users"], (ctx, next) => {
|
|
|
|
ctx.controller = new UserListController(ctx);
|
|
|
|
});
|
2016-06-14 10:31:48 +02:00
|
|
|
};
|