46 lines
891 B
JavaScript
46 lines
891 B
JavaScript
|
import I18n;
|
||
|
import GUI.ConnectedForm;
|
||
|
import select from GUI.Screen;
|
||
|
import Messaging;
|
||
|
import Session;
|
||
|
import Save;
|
||
|
|
||
|
var login = GUI.ConnectedForm.get('login');
|
||
|
var form = login.root;
|
||
|
|
||
|
return {
|
||
|
init: init
|
||
|
};
|
||
|
|
||
|
function init() {
|
||
|
initDOM();
|
||
|
initMessageHandlers();
|
||
|
var name = Save.get('player.name');
|
||
|
if(name != undefined && name.length > 0) {
|
||
|
form.you.value = name;
|
||
|
login.enable();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function initDOM() {
|
||
|
form.getElementsByTagName('label')[0].textContent = I18n.get('pickName');
|
||
|
form.join.value = I18n.get('join');
|
||
|
form.addEventListener('submit', function(e) {
|
||
|
e.preventDefault();
|
||
|
Session.start(form.you.value);
|
||
|
});
|
||
|
form.you.addEventListener("input", validate);
|
||
|
}
|
||
|
|
||
|
function initMessageHandlers() {
|
||
|
Messaging.addEventListener(["LogIn"], function(o) {
|
||
|
if(Session.is(o.from)) {
|
||
|
select('hall');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function validate(e) {
|
||
|
login.enable(e.target.value != "");
|
||
|
}
|