szurubooru/client/js/views/registration_view.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
const config = require('../config.js');
const events = require('../events.js');
const views = require('../util/views.js');
const template = views.getTemplate('user-registration');
class RegistrationView extends events.EventTarget {
constructor() {
super();
this._hostNode = document.getElementById('content-holder');
views.replaceContent(this._hostNode, template({
userNamePattern: config.userNameRegex,
passwordPattern: config.passwordRegex,
}));
2016-07-13 17:18:28 +02:00
views.syncScrollPosition();
views.decorateValidator(this._formNode);
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
}
clearMessages() {
views.clearMessages(this._hostNode);
}
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: {
name: this._userNameFieldNode.value,
password: this._passwordFieldNode.value,
email: this._emailFieldNode.value,
},
}));
}
get _formNode() {
return this._hostNode.querySelector('form');
}
2016-04-07 19:03:49 +02:00
get _userNameFieldNode() {
2016-08-05 20:09:11 +02:00
return this._formNode.querySelector('[name=name]');
}
get _passwordFieldNode() {
2016-08-05 20:09:11 +02:00
return this._formNode.querySelector('[name=password]');
}
2016-04-08 10:35:38 +02:00
get _emailFieldNode() {
2016-08-05 20:09:11 +02:00
return this._formNode.querySelector('[name=email]');
}
}
module.exports = RegistrationView;