2020-06-05 18:03:37 -04:00
|
|
|
"use strict";
|
2016-03-28 00:19:44 +02:00
|
|
|
|
2020-06-05 18:03:37 -04:00
|
|
|
const events = require("../events.js");
|
|
|
|
const api = require("../api.js");
|
|
|
|
const views = require("../util/views.js");
|
2016-03-28 00:19:44 +02:00
|
|
|
|
2020-06-05 18:03:37 -04:00
|
|
|
const template = views.getTemplate("login");
|
2016-06-14 10:31:48 +02:00
|
|
|
|
|
|
|
class LoginView extends events.EventTarget {
|
2016-03-29 12:32:51 +02:00
|
|
|
constructor() {
|
2016-06-14 10:31:48 +02:00
|
|
|
super();
|
2020-06-05 18:03:37 -04:00
|
|
|
this._hostNode = document.getElementById("content-holder");
|
2016-03-28 00:19:44 +02:00
|
|
|
|
2020-06-05 18:03:37 -04:00
|
|
|
views.replaceContent(
|
|
|
|
this._hostNode,
|
|
|
|
template({
|
|
|
|
userNamePattern: api.getUserNameRegex(),
|
|
|
|
passwordPattern: api.getPasswordRegex(),
|
|
|
|
canSendMails: api.canSendMails(),
|
|
|
|
})
|
|
|
|
);
|
2016-07-13 17:18:28 +02:00
|
|
|
views.syncScrollPosition();
|
2016-06-14 10:31:48 +02:00
|
|
|
|
|
|
|
views.decorateValidator(this._formNode);
|
2020-06-05 18:03:37 -04:00
|
|
|
this._userNameInputNode.setAttribute(
|
|
|
|
"pattern",
|
|
|
|
api.getUserNameRegex()
|
|
|
|
);
|
|
|
|
this._passwordInputNode.setAttribute(
|
|
|
|
"pattern",
|
|
|
|
api.getPasswordRegex()
|
|
|
|
);
|
|
|
|
this._formNode.addEventListener("submit", (e) => {
|
2016-06-14 10:31:48 +02:00
|
|
|
e.preventDefault();
|
2020-06-05 18:03:37 -04:00
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent("submit", {
|
|
|
|
detail: {
|
|
|
|
name: this._userNameInputNode.value,
|
|
|
|
password: this._passwordInputNode.value,
|
|
|
|
remember: this._rememberInputNode.checked,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2016-05-09 20:07:54 +02:00
|
|
|
});
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
get _formNode() {
|
2020-06-05 18:03:37 -04:00
|
|
|
return this._hostNode.querySelector("form");
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
2016-03-28 00:19:44 +02:00
|
|
|
|
2016-08-05 20:09:11 +02:00
|
|
|
get _userNameInputNode() {
|
2020-06-05 18:03:37 -04:00
|
|
|
return this._formNode.querySelector("[name=name]");
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
2016-03-28 00:19:44 +02:00
|
|
|
|
2016-08-05 20:09:11 +02:00
|
|
|
get _passwordInputNode() {
|
2020-06-05 18:03:37 -04:00
|
|
|
return this._formNode.querySelector("[name=password]");
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
2016-08-05 20:09:11 +02:00
|
|
|
get _rememberInputNode() {
|
2020-06-05 18:03:37 -04:00
|
|
|
return this._formNode.querySelector("[name=remember-user]");
|
2016-06-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
disableForm() {
|
|
|
|
views.disableForm(this._formNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
enableForm() {
|
|
|
|
views.enableForm(this._formNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
clearMessages() {
|
|
|
|
views.clearMessages(this._hostNode);
|
|
|
|
}
|
2016-04-08 10:35:38 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
showError(message) {
|
|
|
|
views.showError(this._hostNode, message);
|
2016-03-28 00:19:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = LoginView;
|