szurubooru/client/js/views/user_edit_view.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-04-06 22:34:21 +02:00
'use strict';
const config = require('../config.js');
const views = require('../util/views.js');
2016-04-06 22:34:21 +02:00
class UserEditView {
2016-04-06 22:34:21 +02:00
constructor() {
this.template = views.getTemplate('user-edit');
2016-04-06 22:34:21 +02:00
}
2016-04-08 10:35:38 +02:00
render(ctx) {
const target = ctx.target;
const source = this.template(ctx);
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');
views.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;
}
/* TODO: avatar */
form.addEventListener('submit', e => {
e.preventDefault();
views.clearMessages(target);
views.disableForm(form);
2016-04-08 10:35:38 +02:00
ctx.edit(
userNameField.value,
passwordField.value,
emailField.value,
rankField.value)
.always(() => { views.enableForm(form); });
});
2016-04-08 10:35:38 +02:00
views.listenToMessages(target);
views.showView(target, source);
2016-04-06 22:34:21 +02:00
}
}
module.exports = UserEditView;