szurubooru/client/js/views/user_edit_view.js

63 lines
2.1 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-10 15:55:56 +02:00
const FileDropperControl = require('./file_dropper_control.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-10 15:55:56 +02:00
this.fileDropperControl = new FileDropperControl();
2016-04-06 22:34:21 +02:00
}
2016-04-08 10:35:38 +02:00
render(ctx) {
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-08 10:35:38 +02:00
const form = source.querySelector('form');
2016-04-10 15:55:56 +02:00
const avatarContentField = source.querySelector('#avatar-content');
views.decorateValidator(form);
2016-04-10 15:55:56 +02:00
let avatarContent = null;
this.fileDropperControl.render({
target: avatarContentField,
lock: true,
resolve: files => {
source.querySelector(
'[name=avatar-style][value=manual]').checked = true;
avatarContent = files[0];
},
});
form.addEventListener('submit', e => {
2016-04-10 15:55:56 +02:00
const rankField = source.querySelector('#user-rank');
const emailField = source.querySelector('#user-email');
const userNameField = source.querySelector('#user-name');
const passwordField = source.querySelector('#user-password');
const avatarStyleField = source.querySelector(
'[name=avatar-style]:checked');
e.preventDefault();
views.clearMessages(target);
views.disableForm(form);
2016-04-10 15:55:56 +02:00
ctx.edit({
name: userNameField.value,
password: passwordField.value,
email: emailField.value,
rank: rankField.value,
avatarStyle: avatarStyleField.value,
avatarContent: avatarContent})
.always(() => { views.enableForm(form); });
});
2016-04-08 10:35:38 +02:00
views.listenToMessages(source);
views.showView(target, source);
2016-04-06 22:34:21 +02:00
}
}
module.exports = UserEditView;