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

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-03-28 00:19:44 +02:00
'use strict';
const config = require('../config.js');
const events = require('../events.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: config.userNameRegex,
passwordPattern: config.passwordRegex,
canSendMails: config.canSendMails,
}));
views.decorateValidator(this._formNode);
this._userNameFieldNode.setAttribute('pattern', config.userNameRegex);
this._passwordFieldNode.setAttribute('pattern', config.passwordRegex);
this._formNode.addEventListener('submit', e => {
e.preventDefault();
this.dispatchEvent(new CustomEvent('submit', {
detail: {
name: this._userNameFieldNode.value,
password: this._passwordFieldNode.value,
remember: this._rememberFieldNode.checked,
},
}));
});
}
2016-04-08 10:35:38 +02:00
get _formNode() {
return this._hostNode.querySelector('form');
}
2016-03-28 00:19:44 +02:00
get _userNameFieldNode() {
return this._formNode.querySelector('#user-name');
}
2016-03-28 00:19:44 +02:00
get _passwordFieldNode() {
return this._formNode.querySelector('#user-password');
}
get _rememberFieldNode() {
return this._formNode.querySelector('#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;