2016-04-06 22:34:21 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-07 22:54:45 +02:00
|
|
|
const config = require('../config.js');
|
2016-04-09 18:54:23 +02:00
|
|
|
const views = require('../util/views.js');
|
2016-04-06 22:34:21 +02:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
class UserEditView {
|
2016-04-06 22:34:21 +02:00
|
|
|
constructor() {
|
2016-04-09 18:54:23 +02:00
|
|
|
this.template = views.getTemplate('user-edit');
|
2016-04-06 22:34:21 +02:00
|
|
|
}
|
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
render(ctx) {
|
2016-04-10 10:23:27 +02:00
|
|
|
ctx.userNamePattern = config.userNameRegex + /|^$/.source;
|
|
|
|
ctx.passwordPattern = config.passwordRegex + /|^$/.source;
|
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
const target = ctx.target;
|
|
|
|
const source = this.template(ctx);
|
2016-04-07 22:54:45 +02:00
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
const form = source.querySelector('form');
|
|
|
|
const rankField = source.querySelector('#user-rank');
|
|
|
|
const emailField = source.querySelector('#user-email');
|
|
|
|
const userNameField = source.querySelector('#user-name');
|
|
|
|
const passwordField = source.querySelector('#user-password');
|
2016-04-10 10:23:27 +02:00
|
|
|
const avatarStyleField = source.querySelector('#avatar-style');
|
2016-04-07 22:54:45 +02:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
views.decorateValidator(form);
|
2016-04-07 22:54:45 +02:00
|
|
|
|
|
|
|
/* TODO: avatar */
|
|
|
|
|
|
|
|
form.addEventListener('submit', e => {
|
|
|
|
e.preventDefault();
|
2016-04-09 18:54:23 +02:00
|
|
|
views.clearMessages(target);
|
|
|
|
views.disableForm(form);
|
2016-04-08 10:35:38 +02:00
|
|
|
ctx.edit(
|
2016-04-07 22:54:45 +02:00
|
|
|
userNameField.value,
|
|
|
|
passwordField.value,
|
|
|
|
emailField.value,
|
|
|
|
rankField.value)
|
2016-04-09 18:54:23 +02:00
|
|
|
.always(() => { views.enableForm(form); });
|
2016-04-07 22:54:45 +02:00
|
|
|
});
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2016-04-09 18:54:23 +02:00
|
|
|
views.listenToMessages(target);
|
|
|
|
views.showView(target, source);
|
2016-04-06 22:34:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserEditView;
|