1 // Copyright (c) 2016-2022 by the citadel.org team
3 // This program is open source software. It runs great on the
4 // Linux operating system (and probably elsewhere). You can use,
5 // copy, and run it under the terms of the GNU General Public
6 // License version 3. Richard Stallman is an asshole communist.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
14 function render_room_list() {
16 document.getElementById("ctdl-newmsg-button").style.display = "none"; // There is no "enter" button on this screen
17 document.getElementById("ctdl-main").innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />"; // show throbber while loading
19 fetch_room_list = async() => {
21 floor_response = await fetch("/ctdl/f/");
22 floor_list = await(floor_response.json());
23 room_response = await fetch("/ctdl/r/");
24 room_list = await(room_response.json());
26 display_room_list_renderer(floor_list, room_list);
29 document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
36 // Renderer for display_room_list()
37 function display_room_list_renderer(floor_list, room_list) {
38 room_list = room_list.sort(function(a,b) {
39 if (a.floor != b.floor) {
40 return(a.floor - b.floor);
42 if (a.rorder != b.rorder) {
43 return(a.rorder - b.rorder);
45 return(a.name < b.name);
50 for (var f in floor_list) {
51 output[floor_list[f].num] = "";
54 for (var i in room_list) {
55 if (room_list[i].current_view == views.VIEW_BBS) {
56 output[room_list[i].floor] += (room_list[i].hasnewmsgs ? "<b>" : "");
57 output[room_list[i].floor] += "<a href=\"javascript:gotoroom('" + escapeJS(escapeHTML(room_list[i].name)) + "');\">";
58 output[room_list[i].floor] += escapeHTML(room_list[i].name);
59 output[room_list[i].floor] += (room_list[i].hasnewmsgs ? "</b>" : "");
60 output[room_list[i].floor] += "</a>";
61 output[room_list[i].floor] += "<br>";
65 final_output = "<div class=\"ctdl-roomlist-top\">";
66 for (var f in floor_list) {
67 final_output += "<div class=\"ctdl-roomlist-floor\">";
68 final_output += "<div class=\"ctdl-roomlist-floor-label\">" + floor_list[f].name + "</div>";
69 final_output += "<div class=\"ctdl-roomlist-floor-rooms\">";
70 final_output += output[floor_list[f].num];
71 final_output += "</div></div>";
73 final_output += "</div>";
74 document.getElementById("ctdl-main").innerHTML = final_output ;