comparison rlgterm.js @ 45:1bbd0e76ba92

RLG-Web: put the game options into a table. Create a nice table of options when the player logs in.
author John "Elwin" Edwards <elwin@sdf.org>
date Sat, 09 Jun 2012 15:22:56 -0700
parents b848cb50cd69
children 59ecd99845eb
comparison
equal deleted inserted replaced
44:b848cb50cd69 45:1bbd0e76ba92
419 if (e instanceof SyntaxError) 419 if (e instanceof SyntaxError)
420 return; 420 return;
421 } 421 }
422 if (!("name" in reply) || reply["name"] != lname || !("stat" in reply)) 422 if (!("name" in reply) || reply["name"] != lname || !("stat" in reply))
423 return; 423 return;
424 var statdiv = document.createElement("div"); 424 var optdiv = document.getElementById("opttable");
425 /* Don't remove the first child, it's the header. */
426 while (optdiv.childNodes.length > 1)
427 optdiv.removeChild(optdiv.childNodes[1]);
425 for (var gname in reply.stat) { 428 for (var gname in reply.stat) {
426 if (!(gname in games)) 429 if (!(gname in games))
427 continue; 430 continue;
428 var stext; 431 var acttext;
429 if (reply.stat[gname] == "s") 432 if (reply.stat[gname] == "s")
430 stext = games[gname].name + ": Resume your game"; 433 acttext = "Resume your game";
431 else if (reply.stat[gname] == "0") 434 else if (reply.stat[gname] == "0")
432 stext = games[gname].name + ": Start a game"; 435 acttext = "Start a game";
433 else if (reply.stat[gname] == "p") 436 else if (reply.stat[gname] == "p")
434 stext = games[gname].name + ": Game in progress"; 437 acttext = "Game in progress";
435 else 438 else
436 continue; 439 continue;
437 var tnode = document.createTextNode(stext); 440 var button = document.createElement("span");
441 button.appendChild(document.createTextNode(acttext));
442 button.className = "ibutton";
443 var actdiv = document.createElement("div");
444 actdiv.appendChild(button);
438 var gamediv = document.createElement("div"); 445 var gamediv = document.createElement("div");
439 gamediv.appendChild(tnode); 446 gamediv.appendChild(document.createTextNode(games[gname].name));
440 statdiv.appendChild(gamediv); 447 var rowdiv = document.createElement("div");
441 } 448 rowdiv.appendChild(gamediv);
442 if (!statdiv.hasChildNodes()) { 449 rowdiv.appendChild(actdiv);
443 statdiv.appendChild(document.createTextNode("No known games?")); 450 optdiv.appendChild(rowdiv);
444 } 451 }
445 document.getElementById("startgame").appendChild(statdiv);
446 }; 452 };
447 req.open('GET', '/pstatus/' + lname, true); 453 req.open('GET', '/pstatus/' + lname, true);
448 req.send(); 454 req.send();
449 return; 455 return;
450 } 456 }