server/www/screen/login.js
2019-12-11 22:05:17 +01:00

42 lines
1 KiB
JavaScript

Screen.Login = function(modules) {
var root = document.getElementById('login');
var submit = root.submitButton;
init();
return {};
function init() {
initDOMEvents();
initMessageHandlers();
var name = modules.save.get('player.name');
if(name != undefined && name.length > 0) {
root.you.value = name;
formDisable(false);
}
}
function initDOMEvents() {
root.addEventListener('submit', function(e) {
e.preventDefault();
modules.session.start(root.you.value);
});
}
function initMessageHandlers() {
modules.messaging.addEventListener(["LogIn"], function(o) {
if(modules.session.is(o.from)) {
modules.screen.select('hall');
}
});
modules.messaging.addEventListener('open', function() {formDisable(false);});
modules.messaging.addEventListener('close', function() {formDisable(true);});
}
function formDisable(disabled) {
[submit, root.name].forEach(function(button) {
button.disabled = disabled || !modules.messaging.isOn();
});
}
}