comparison rlgterm.js @ 56:7f3ca16409fe

RLG-Web client: display a list of current games. Incorporate information from /status to create a list of ongoing games. Eventually these will be watchable.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 18 Jun 2012 14:30:05 -0700
parents 96815eae4ebe
children e7c864e80a79
comparison
equal deleted inserted replaced
55:96815eae4ebe 56:7f3ca16409fe
404 document.getElementById("input_pw").value = ""; 404 document.getElementById("input_pw").value = "";
405 } 405 }
406 }; 406 };
407 req.open('POST', '/login', true); 407 req.open('POST', '/login', true);
408 req.send(JSON.stringify(loginmsg)); 408 req.send(JSON.stringify(loginmsg));
409 return;
410 }
411
412 function getcurrent() {
413 if (termemu.sessid)
414 return;
415 var req = new XMLHttpRequest();
416 req.onreadystatechange = function () {
417 if (req.readyState != 4 || req.status != 200)
418 return;
419 var reply;
420 try {
421 reply = JSON.parse(req.responseText);
422 } catch (e) {
423 if (e instanceof SyntaxError)
424 return;
425 }
426 if (!reply.s) {
427 return;
428 }
429 var gamediv = document.getElementById("gametable");
430 while (gamediv.children.length > 2)
431 gamediv.removeChild(optdiv.children[2]);
432 for (var i = 0; i < reply.g.length; i++) {
433 var row = document.createElement("div");
434 var cell1 = document.createElement("div");
435 var cell2 = document.createElement("div");
436 cell1.appendChild(document.createTextNode(reply.g[i].p));
437 cell2.appendChild(document.createTextNode(reply.g[i].g));
438 row.appendChild(cell1);
439 row.appendChild(cell2);
440 gamediv.appendChild(row);
441 }
442 };
443 req.open('GET', '/status', true);
444 req.send();
409 return; 445 return;
410 } 446 }
411 447
412 function getchoices() { 448 function getchoices() {
413 if (termemu.sessid != null || !lcred) 449 if (termemu.sessid != null || !lcred)
585 if (mode == "play") { 621 if (mode == "play") {
586 document.getElementById("keyboard").style.display = "block"; 622 document.getElementById("keyboard").style.display = "block";
587 document.getElementById("startgame").style.display = "none"; 623 document.getElementById("startgame").style.display = "none";
588 document.getElementById("login").style.display = "none"; 624 document.getElementById("login").style.display = "none";
589 document.getElementById("register").style.display = "none"; 625 document.getElementById("register").style.display = "none";
626 document.getElementById("current").style.display = "none";
590 } 627 }
591 if (mode == "choose") { 628 if (mode == "choose") {
592 document.getElementById("keyboard").style.display = "none"; 629 document.getElementById("keyboard").style.display = "none";
593 document.getElementById("startgame").style.display = "block"; 630 document.getElementById("startgame").style.display = "block";
594 document.getElementById("login").style.display = "none"; 631 document.getElementById("login").style.display = "none";
595 document.getElementById("register").style.display = "none"; 632 document.getElementById("register").style.display = "none";
633 document.getElementById("current").style.display = "block";
596 getchoices(); 634 getchoices();
635 getcurrent();
597 } 636 }
598 else if (mode == "login") { 637 else if (mode == "login") {
599 document.getElementById("keyboard").style.display = "none"; 638 document.getElementById("keyboard").style.display = "none";
600 document.getElementById("startgame").style.display = "none"; 639 document.getElementById("startgame").style.display = "none";
601 document.getElementById("login").style.display = "block"; 640 document.getElementById("login").style.display = "block";
602 document.getElementById("register").style.display = "none"; 641 document.getElementById("register").style.display = "none";
642 document.getElementById("current").style.display = "block";
643 getcurrent();
603 } 644 }
604 else if (mode == "register") { 645 else if (mode == "register") {
605 document.getElementById("keyboard").style.display = "none"; 646 document.getElementById("keyboard").style.display = "none";
606 document.getElementById("startgame").style.display = "none"; 647 document.getElementById("startgame").style.display = "none";
607 document.getElementById("login").style.display = "none"; 648 document.getElementById("login").style.display = "none";
608 document.getElementById("register").style.display = "block"; 649 document.getElementById("register").style.display = "block";
650 document.getElementById("current").style.display = "none";
609 } 651 }
610 } 652 }
611 653
612 function debug(level, msg) { 654 function debug(level, msg) {
613 if (level < debugSuppress) 655 if (level < debugSuppress)