client/users: add user view prototype

This commit is contained in:
rr-
2016-04-06 22:34:21 +02:00
parent c46dc08c1b
commit 8be93f6c70
14 changed files with 225 additions and 21 deletions

View File

@ -18,10 +18,13 @@ class UsersController {
page('/users', () => { this.listUsersRoute(); });
page(
'/user/:name',
(ctx, next) => { this.showUserRoute(ctx.params.name); });
(ctx, next) => { this.loadUserRoute(ctx, next); },
(ctx, next) => { this.showUserRoute(ctx, next); });
page(
'/user/:name/edit',
(ctx, next) => { this.editUserRoute(ctx.params.name); });
(ctx, next) => { this.loadUserRoute(ctx, next); },
(ctx, next) => { this.editUserRoute(ctx, next); });
page.exit('/user/', (ctx, next) => { this.user = null; });
}
listUsersRoute() {
@ -57,22 +60,42 @@ class UsersController {
});
}
showUserRoute(name) {
if (api.isLoggedIn() && name == api.userName) {
loadUserRoute(ctx, next) {
if (ctx.state.user) {
next();
} else if (this.user && this.user.name == ctx.params.name) {
ctx.state.user = this.user;
next();
} else {
api.get('/user/' + ctx.params.name).then(response => {
ctx.state.user = response.user;
ctx.save();
this.user = response.user;
next();
}).catch(response => {
this.userView.empty();
this.userView.notifyError(response.description);
});
}
}
_show(user, section) {
const isPrivate = api.isLoggedIn() && user.name == api.userName;
if (isPrivate) {
topNavController.activate('account');
} else {
topNavController.activate('users');
}
this.userView.empty();
api.get('/user/' + name).then(response => {
this.userView.render({user: response.user});
}).catch(response => {
this.userView.notifyError(response.description);
});
this.userView.render({
user: user, section: section, isPrivate: isPrivate});
}
editUserRoute(user) {
topNavController.activate('users');
showUserRoute(ctx, next) {
this._show(ctx.state.user, 'summary');
}
editUserRoute(ctx, next) {
this._show(ctx.state.user, 'edit');
}
}