- Controller lifetime is bound to route lifetime - View lifetime is bound to controller lifetime - Control lifetime is bound to view lifetime - Enhanced event dispatching - Enhanced responsiveness in some places - Views communicate user input to controllers via new event system
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const config = require('../config.js');
|
|
const events = require('../events.js');
|
|
const views = require('../util/views.js');
|
|
|
|
const template = views.getTemplate('login');
|
|
|
|
class LoginView extends events.EventTarget {
|
|
constructor() {
|
|
super();
|
|
this._hostNode = document.getElementById('content-holder');
|
|
|
|
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,
|
|
},
|
|
}));
|
|
});
|
|
}
|
|
|
|
get _formNode() {
|
|
return this._hostNode.querySelector('form');
|
|
}
|
|
|
|
get _userNameFieldNode() {
|
|
return this._formNode.querySelector('#user-name');
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
showError(message) {
|
|
views.showError(this._hostNode, message);
|
|
}
|
|
}
|
|
|
|
module.exports = LoginView;
|