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-06 22:34:21 +02:00
|
|
|
const BaseView = require('./base_view.js');
|
|
|
|
|
|
|
|
class UserEditView extends BaseView {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.template = this.getTemplate('user-edit-template');
|
|
|
|
}
|
|
|
|
|
2016-04-08 10:35:38 +02:00
|
|
|
render(ctx) {
|
|
|
|
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-07 22:54:45 +02:00
|
|
|
|
|
|
|
this.decorateValidator(form);
|
|
|
|
|
|
|
|
if (userNameField) {
|
|
|
|
userNameField.setAttribute(
|
|
|
|
'pattern',
|
|
|
|
config.userNameRegex + /|^$/.source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (passwordField) {
|
|
|
|
passwordField.setAttribute(
|
|
|
|
'pattern',
|
|
|
|
config.passwordRegex + /|^$/.source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rankField) {
|
2016-04-08 10:35:38 +02:00
|
|
|
rankField.value = ctx.user.rank;
|
2016-04-07 22:54:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: avatar */
|
|
|
|
|
|
|
|
form.addEventListener('submit', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.clearMessages();
|
|
|
|
this.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-08 13:17:00 +02:00
|
|
|
.always(() => { this.enableForm(form); });
|
2016-04-07 22:54:45 +02:00
|
|
|
});
|
2016-04-08 10:35:38 +02:00
|
|
|
|
|
|
|
this.showView(target, source);
|
2016-04-06 22:34:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserEditView;
|