2016-04-06 22:34:21 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-07 22:54:45 +02:00
|
|
|
const config = require('../config.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
const events = require('../events.js');
|
2016-04-09 18:54:23 +02:00
|
|
|
const views = require('../util/views.js');
|
2016-05-20 21:35:12 +02:00
|
|
|
const FileDropperControl = require('../controls/file_dropper_control.js');
|
2016-04-06 22:34:21 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const template = views.getTemplate('user-edit');
|
|
|
|
|
|
|
|
class UserEditView extends events.EventTarget {
|
|
|
|
constructor(ctx) {
|
|
|
|
super();
|
2016-04-06 22:34:21 +02:00
|
|
|
|
2016-04-10 10:23:27 +02:00
|
|
|
ctx.userNamePattern = config.userNameRegex + /|^$/.source;
|
|
|
|
ctx.passwordPattern = config.passwordRegex + /|^$/.source;
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._user = ctx.user;
|
|
|
|
this._hostNode = ctx.hostNode;
|
|
|
|
views.replaceContent(this._hostNode, template(ctx));
|
|
|
|
views.decorateValidator(this._formNode);
|
2016-04-07 22:54:45 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._avatarContent = null;
|
|
|
|
if (this._avatarContentFieldNode) {
|
2016-05-20 21:35:12 +02:00
|
|
|
new FileDropperControl(
|
2016-06-14 10:31:48 +02:00
|
|
|
this._avatarContentFieldNode,
|
2016-05-20 21:35:12 +02:00
|
|
|
{
|
|
|
|
lock: true,
|
|
|
|
resolve: files => {
|
2016-06-14 10:31:48 +02:00
|
|
|
this._hostNode.querySelector(
|
2016-05-20 21:35:12 +02:00
|
|
|
'[name=avatar-style][value=manual]').checked = true;
|
2016-06-14 10:31:48 +02:00
|
|
|
this._avatarContent = files[0];
|
2016-05-20 21:35:12 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2016-04-07 22:54:45 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
clearMessages() {
|
|
|
|
views.clearMessages(this._hostNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
showSuccess(message) {
|
|
|
|
views.showSuccess(this._hostNode, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
showError(message) {
|
|
|
|
views.showError(this._hostNode, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
enableForm() {
|
|
|
|
views.enableForm(this._formNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
disableForm() {
|
|
|
|
views.disableForm(this._formNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
_evtSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.dispatchEvent(new CustomEvent('submit', {
|
|
|
|
detail: {
|
2016-07-26 21:02:21 +02:00
|
|
|
user: this._user,
|
|
|
|
|
|
|
|
name: this._userNameFieldNode ?
|
|
|
|
this._userNameFieldNode.value :
|
|
|
|
undefined,
|
|
|
|
|
|
|
|
email: this._emailFieldNode ?
|
|
|
|
this._emailFieldNode.value :
|
|
|
|
undefined,
|
|
|
|
|
|
|
|
rank: this._rankFieldNode ?
|
|
|
|
this._rankFieldNode.value :
|
|
|
|
undefined,
|
|
|
|
|
|
|
|
avatarStyle: this._avatarStyleFieldNode ?
|
|
|
|
this._avatarStyleFieldNode.value :
|
|
|
|
undefined,
|
|
|
|
|
|
|
|
password: this._passwordFieldNode ?
|
|
|
|
this._passwordFieldNode.value :
|
|
|
|
undefined,
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
avatarContent: this._avatarContent,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
get _formNode() {
|
|
|
|
return this._hostNode.querySelector('form');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _rankFieldNode() {
|
|
|
|
return this._formNode.querySelector('#user-rank');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _emailFieldNode() {
|
|
|
|
return this._formNode.querySelector('#user-email');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _userNameFieldNode() {
|
|
|
|
return this._formNode.querySelector('#user-name');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _passwordFieldNode() {
|
|
|
|
return this._formNode.querySelector('#user-password');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _avatarContentFieldNode() {
|
|
|
|
return this._formNode.querySelector('#avatar-content');
|
|
|
|
}
|
|
|
|
|
|
|
|
get _avatarStyleFieldNode() {
|
|
|
|
return this._formNode.querySelector('[name=avatar-style]:checked');
|
2016-04-06 22:34:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserEditView;
|