This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/client/js/views/login_view.js

81 lines
2 KiB
JavaScript
Raw Normal View History

"use strict";
2016-03-28 00:19:44 +02: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
const template = views.getTemplate("login");
class LoginView extends events.EventTarget {
constructor() {
super();
this._hostNode = document.getElementById("content-holder");
2016-03-28 00:19:44 +02: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();
views.decorateValidator(this._formNode);
this._userNameInputNode.setAttribute(
"pattern",
api.getUserNameRegex()
);
this._passwordInputNode.setAttribute(
"pattern",
api.getPasswordRegex()
);
this._formNode.addEventListener("submit", (e) => {
e.preventDefault();
this.dispatchEvent(
new CustomEvent("submit", {
detail: {
name: this._userNameInputNode.value,
password: this._passwordInputNode.value,
remember: this._rememberInputNode.checked,
},
})
);
});
}
2016-04-08 10:35:38 +02:00
get _formNode() {
return this._hostNode.querySelector("form");
}
2016-03-28 00:19:44 +02:00
2016-08-05 20:09:11 +02:00
get _userNameInputNode() {
return this._formNode.querySelector("[name=name]");
}
2016-03-28 00:19:44 +02:00
2016-08-05 20:09:11 +02:00
get _passwordInputNode() {
return this._formNode.querySelector("[name=password]");
}
2016-08-05 20:09:11 +02:00
get _rememberInputNode() {
return this._formNode.querySelector("[name=remember-user]");
}
disableForm() {
views.disableForm(this._formNode);
}
enableForm() {
views.enableForm(this._formNode);
}
clearMessages() {
views.clearMessages(this._hostNode);
}
2016-04-08 10:35:38 +02:00
showError(message) {
views.showError(this._hostNode, message);
2016-03-28 00:19:44 +02:00
}
}
module.exports = LoginView;