server/www/screen/login.js

38 lines
976 B
JavaScript

Screen.Login = function(modules) {
var form = modules.ui.connectedForm('login');
init();
return {};
function init() {
initDOM();
initMessageHandlers();
var name = modules.save.get('player.name');
if(name != undefined && name.length > 0) {
form.you.value = name;
modules.ui.enableForm('login', true);
}
}
function initDOM() {
form.getElementsByTagName('label')[0].textContent = modules.i18n.get('pickName');
form.join.value = modules.i18n.get('join');
form.addEventListener('submit', function(e) {
e.preventDefault();
modules.session.start(form.you.value);
});
form.you.addEventListener("input", validate);
}
function initMessageHandlers() {
modules.messaging.addEventListener(["LogIn"], function(o) {
if(modules.session.is(o.from)) {
modules.screen.select('hall');
}
});
}
function validate(e) {
modules.ui.enableForm('login', e.target.value != "")
}
}