szurubooru/client/js/views/registration_view.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

"use strict";
const events = require("../events.js");
const api = require("../api.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: api.getUserNameRegex(),
passwordPattern: api.getPasswordRegex(),
})
);
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() {
return this._formNode.querySelector("[name=name]");
}
get _passwordFieldNode() {
return this._formNode.querySelector("[name=password]");
}
2016-04-08 10:35:38 +02:00
get _emailFieldNode() {
return this._formNode.querySelector("[name=email]");
}
}
module.exports = RegistrationView;