comparison rlgterm.js @ 96:7bb634f6995c

RLG-Web client: improvements to UI messages. Improve the appearance of the message area, make warnings a different color from other messages, and make some message texts more helpful.
author John "Elwin" Edwards <elwin@sdf.org>
date Wed, 11 Jul 2012 11:10:50 -0700
parents 597e9477b8ae
children 8a748eac7c11
comparison
equal deleted inserted replaced
95:e84a99712c62 96:7bb634f6995c
260 } 260 }
261 } 261 }
262 262
263 function errHandler() { 263 function errHandler() {
264 //debug(1, "Server unavailable?"); 264 //debug(1, "Server unavailable?");
265 message("Unable to connect to the server."); 265 message("Unable to connect to the server.", "warn");
266 } 266 }
267 267
268 function sendback(str) { 268 function sendback(str) {
269 /* For responding to terminal queries. */ 269 /* For responding to terminal queries. */
270 var msgDict = {"id": session.id, "t": "d", "n": nsend++, "d": str}; 270 var msgDict = {"id": session.id, "t": "d", "n": nsend++, "d": str};
448 message("You are now logged in as " + reply.u + "."); 448 message("You are now logged in as " + reply.u + ".");
449 setmode("choose"); 449 setmode("choose");
450 } 450 }
451 else if (reply.t == 'E') { 451 else if (reply.t == 'E') {
452 debug(0, "Could not log in: " + reply.s); 452 debug(0, "Could not log in: " + reply.s);
453 message("Logging in failed: " + reply.s); 453 var failmsg = "Logging in failed. ";
454 if (reply.c == 2)
455 failmsg += reply.s.match(/Invalid data: (.*)/)[1];
456 else if (reply.c == 3)
457 failmsg += "The username or password was incorrect.";
458 else if (reply.c == 6)
459 failmsg += "The server is shutting down.";
460 message(failmsg, "warn");
454 document.getElementById("input_name").value = ""; 461 document.getElementById("input_name").value = "";
455 document.getElementById("input_pw").value = ""; 462 document.getElementById("input_pw").value = "";
456 } 463 }
457 }; 464 };
458 req.open('POST', '/login', true); 465 req.open('POST', '/login', true);
628 } 635 }
629 else if (reply.t == 'E') { 636 else if (reply.t == 'E') {
630 debug(1, "Could not start game: " + reply.s); 637 debug(1, "Could not start game: " + reply.s);
631 if (reply.c == 1) { 638 if (reply.c == 1) {
632 logout(); 639 logout();
633 message("The server forgot about you, please log in again."); 640 message("The server forgot about you, please log in again.", "warn");
634 } 641 }
635 else if (reply.c == 4) { 642 else if (reply.c == 4) {
636 message("You can't play that game because it is currently being " + 643 message("You can't play that game because it is currently being " +
637 "played over SSH."); 644 "played over SSH.", "warn");
638 } 645 }
639 else if (reply.c == 7) { 646 else if (reply.c == 7) {
640 message("The game is being saved, try again in a few seconds."); 647 message("The game is being saved, try again in a few seconds.");
641 } 648 }
642 else { 649 else {
643 message("The server says it can't start your game because \"" + 650 message("The server says it can't start your game because \"" +
644 reply.s + "\". This is probably a bug."); 651 reply.s + "\". This is probably a bug.", "warn");
645 } 652 }
646 } 653 }
647 }; 654 };
648 req.open('POST', '/play', true); 655 req.open('POST', '/play', true);
649 req.send(JSON.stringify(smsg)); 656 req.send(JSON.stringify(smsg));
674 setmode("watch"); 681 setmode("watch");
675 getData(); 682 getData();
676 } 683 }
677 else if (reply.t == 'E') { 684 else if (reply.t == 'E') {
678 debug(1, "Could not watch game " + gamenumber + ": " + reply.s); 685 debug(1, "Could not watch game " + gamenumber + ": " + reply.s);
679 message("The game could not be watched: " + reply.s); 686 message("The game could not be watched: " + reply.s, "warn");
680 getcurrent(); 687 getcurrent();
681 } 688 }
682 }; 689 };
683 req.open('POST', '/watch', true); 690 req.open('POST', '/watch', true);
684 req.send(JSON.stringify(wmsg)); 691 req.send(JSON.stringify(wmsg));
734 else 741 else
735 failmsg += " This is probably a bug."; 742 failmsg += " This is probably a bug.";
736 } 743 }
737 else 744 else
738 failmsg += " This is probably a bug."; 745 failmsg += " This is probably a bug.";
739 message(failmsg); 746 message(failmsg, "warn");
740 document.getElementById("regin_name").value = ""; 747 document.getElementById("regin_name").value = "";
741 document.getElementById("regin_pw").value = ""; 748 document.getElementById("regin_pw").value = "";
742 document.getElementById("regin_email").value = ""; 749 document.getElementById("regin_email").value = "";
743 } 750 }
744 }; 751 };
846 element.style.display = "block"; 853 element.style.display = "block";
847 else 854 else
848 element.style.display = "none"; 855 element.style.display = "none";
849 } 856 }
850 857
851 function message(msg, type) { 858 function message(msg, mtype) {
852 var msgdiv = document.createElement("div"); 859 var msgdiv = document.createElement("div");
853 var msgtext = document.createTextNode(msg); 860 var msgtext = document.createTextNode(msg);
854 msgdiv.appendChild(msgtext); 861 msgdiv.appendChild(msgtext);
862 if (mtype) {
863 msgdiv.className = mtype;
864 }
855 var msgcontainer = document.getElementById("messages"); 865 var msgcontainer = document.getElementById("messages");
856 msgcontainer.insertBefore(msgdiv, msgcontainer.firstChild); 866 msgcontainer.insertBefore(msgdiv, msgcontainer.firstChild);
857 } 867 }
858 868
859 function debug(level, msg) { 869 function debug(level, msg) {