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');
|
|
|
|
}
|
|
|
|
|
|
|
|
render(options) {
|
2016-04-07 22:54:45 +02:00
|
|
|
options.target.innerHTML = this.template(options);
|
|
|
|
|
|
|
|
const form = options.target.querySelector('form');
|
|
|
|
const rankField = options.target.querySelector('#user-rank');
|
|
|
|
const emailField = options.target.querySelector('#user-email');
|
|
|
|
const userNameField = options.target.querySelector('#user-name');
|
|
|
|
const passwordField = options.target.querySelector('#user-password');
|
|
|
|
|
|
|
|
this.decorateValidator(form);
|
|
|
|
|
|
|
|
if (userNameField) {
|
|
|
|
userNameField.setAttribute(
|
|
|
|
'pattern',
|
|
|
|
config.userNameRegex + /|^$/.source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (passwordField) {
|
|
|
|
passwordField.setAttribute(
|
|
|
|
'pattern',
|
|
|
|
config.passwordRegex + /|^$/.source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rankField) {
|
|
|
|
rankField.value = options.user.rank;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: avatar */
|
|
|
|
|
|
|
|
form.addEventListener('submit', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.clearMessages();
|
|
|
|
this.disableForm(form);
|
|
|
|
options
|
|
|
|
.edit(
|
|
|
|
userNameField.value,
|
|
|
|
passwordField.value,
|
|
|
|
emailField.value,
|
|
|
|
rankField.value)
|
|
|
|
.then(user => { this.enableForm(form); })
|
|
|
|
.catch(() => { this.enableForm(form); });
|
|
|
|
});
|
2016-04-06 22:34:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserEditView;
|