X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit-ng%2Fstatic%2Fjs%2Fmain.js;h=8aa87112162cb612f28c5e3df060241ea969df70;hb=e560dff819d748744fb7e6ce4e20580ed1e77671;hp=cea3df2bde11240d943bb6378e203619aea66025;hpb=44bf4aea855a2526a34fbfc5f431acc748e93ee4;p=citadel.git diff --git a/webcit-ng/static/js/main.js b/webcit-ng/static/js/main.js index cea3df2bd..8aa871121 100644 --- a/webcit-ng/static/js/main.js +++ b/webcit-ng/static/js/main.js @@ -34,12 +34,11 @@ function _(x) { // function randomString(length) { var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz'.split(''); + var str = ''; - if (! length) { + if (!length) { length = Math.floor(Math.random() * chars.length); } - - var str = ''; for (var i = 0; i < length; i++) { str += chars[Math.floor(Math.random() * chars.length)]; } @@ -50,68 +49,64 @@ function randomString(length) { // string escape for html display // function escapeHTML(text) { - 'use strict'; - return text.replace(/[\"&<>]/g, function (a) { - return { - '"': '"', - '&': '&', - '<': '<', - '>': '>' - }[a]; - }); + 'use strict'; + return text.replace(/[\"&<>]/g, function (a) { + return { + '"': '"', + '&': '&', + '<': '<', + '>': '>' + }[a]; + }); } // string escape for html display // function escapeHTMLURI(text) { - 'use strict'; - return text.replace(/./g, function (a) { - return '%' + a.charCodeAt(0).toString(16); - }); + 'use strict'; + return text.replace(/./g, function (a) { + return '%' + a.charCodeAt(0).toString(16); + }); } // string escape for JavaScript string // function escapeJS(text) { - 'use strict'; - return text.replace(/[\"\']/g, function (a) { - return '\\' + a ; - }); + 'use strict'; + return text.replace(/[\"\']/g, function (a) { + return '\\' + a ; + }); } // This is called at the very beginning of the main page load. // function ctdl_startup() { - var request = new XMLHttpRequest(); - request.open("GET", "/ctdl/c/info", true); - request.onreadystatechange = function() { - if ((this.readyState === 4) && ((this.status / 100) == 2)) { - ctdl_startup_2(JSON.parse(this.responseText)); - } - }; - request.send(); - request = null; -} -// Continuation of ctdl_startup() after serv_info is retrieved -// -function ctdl_startup_2(data) { - serv_info = data; + const csa = async () => { + console.log("starting"); + const response = await fetch("/ctdl/c/info"); + const the_text = await(response.text()); - if (data.serv_rev_level < 905) { - alert("Citadel server is too old, some functions may not work"); + if (response.ok) { + serv_info = JSON.parse(the_text); + if (serv_info.serv_rev_level < 905) { + alert("Citadel server is too old, some functions may not work"); + } + + update_banner(); + + // for now, show a room list in the main div + gotoroom("_BASEROOM_"); + display_room_list(); + } } - - update_banner(); - - // for now, show a room list in the main div - gotoroom("_BASEROOM_"); - display_room_list(); + csa(); } + // Display a room list in the main div. // function display_room_list() { @@ -128,6 +123,7 @@ function display_room_list() { request = null; } + // Renderer for display_room_list() // function display_room_list_renderer(data) { @@ -151,8 +147,10 @@ function display_room_list_renderer(data) { } new_roomlist_text = new_roomlist_text + "
  • " + + (data[i].hasnewmsgs ? "" : "") + "" + escapeHTML(data[i].name) + + (data[i].hasnewmsgs ? "" : "") + "
  • " ; } @@ -160,6 +158,7 @@ function display_room_list_renderer(data) { document.getElementById("roomlist").innerHTML = new_roomlist_text ; } + // Update the "banner" div with all relevant info. // function update_banner() { @@ -207,8 +206,10 @@ function gotoroom_2(data) { // Goto next room with unread messages +// which_oper is 0=ungoto, 1=skip, 2=goto // -function gotonext() { +function gotonext(which_oper) { + if (which_oper != 2) return; // FIXME implement the other two if (march_list.length == 0) { load_new_march_list(); // we will recurse back here }