Mercurial > hg > rlgwebd
diff 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 |
line wrap: on
line diff
--- a/rlgterm.js Mon Jun 18 13:43:51 2012 -0700 +++ b/rlgterm.js Mon Jun 18 14:30:05 2012 -0700 @@ -409,6 +409,42 @@ return; } +function getcurrent() { + if (termemu.sessid) + return; + var req = new XMLHttpRequest(); + req.onreadystatechange = function () { + if (req.readyState != 4 || req.status != 200) + return; + var reply; + try { + reply = JSON.parse(req.responseText); + } catch (e) { + if (e instanceof SyntaxError) + return; + } + if (!reply.s) { + return; + } + var gamediv = document.getElementById("gametable"); + while (gamediv.children.length > 2) + gamediv.removeChild(optdiv.children[2]); + for (var i = 0; i < reply.g.length; i++) { + var row = document.createElement("div"); + var cell1 = document.createElement("div"); + var cell2 = document.createElement("div"); + cell1.appendChild(document.createTextNode(reply.g[i].p)); + cell2.appendChild(document.createTextNode(reply.g[i].g)); + row.appendChild(cell1); + row.appendChild(cell2); + gamediv.appendChild(row); + } + }; + req.open('GET', '/status', true); + req.send(); + return; +} + function getchoices() { if (termemu.sessid != null || !lcred) return; @@ -587,25 +623,31 @@ document.getElementById("startgame").style.display = "none"; document.getElementById("login").style.display = "none"; document.getElementById("register").style.display = "none"; + document.getElementById("current").style.display = "none"; } if (mode == "choose") { document.getElementById("keyboard").style.display = "none"; document.getElementById("startgame").style.display = "block"; document.getElementById("login").style.display = "none"; document.getElementById("register").style.display = "none"; + document.getElementById("current").style.display = "block"; getchoices(); + getcurrent(); } else if (mode == "login") { document.getElementById("keyboard").style.display = "none"; document.getElementById("startgame").style.display = "none"; document.getElementById("login").style.display = "block"; document.getElementById("register").style.display = "none"; + document.getElementById("current").style.display = "block"; + getcurrent(); } else if (mode == "register") { document.getElementById("keyboard").style.display = "none"; document.getElementById("startgame").style.display = "none"; document.getElementById("login").style.display = "none"; document.getElementById("register").style.display = "block"; + document.getElementById("current").style.display = "none"; } }