server/www/screen/login.js

43 lines
1 KiB
JavaScript
Raw Normal View History

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.join].forEach(function(button) {
button.disabled = disabled || !modules.messaging.isOn();
});
}
}