1 // Copyright (c) 2016-2022 by the citadel.org team
3 // This program is open source software. Use, duplication, or
4 // disclosure are subject to the GNU General Public License v3.
7 function render_room_list() {
9 document.getElementById("ctdl-newmsg-button").style.display = "none"; // There is no "enter" button on this screen
10 document.getElementById("ctdl-main").innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />"; // show throbber while loading
12 fetch_room_list = async() => {
13 floor_response = await fetch("/ctdl/f/");
14 floor_list = await(floor_response.json());
15 room_response = await fetch("/ctdl/r/");
16 room_list = await(room_response.json());
18 display_room_list_renderer(floor_list, room_list);
21 document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
28 // Renderer for display_room_list()
29 function display_room_list_renderer(floor_list, room_list) {
31 // First sort by the room order indicated by the server
32 room_list = room_list.sort(function(a,b) {
33 if (a.floor != b.floor) {
34 return(a.floor - b.floor);
36 if (a.rorder != b.rorder) {
37 return(a.rorder - b.rorder);
39 return(a.name < b.name);
42 // Then split the sorted list out into floors
44 for (var f in floor_list) {
45 output[floor_list[f].num] = "";
48 for (var i in room_list) {
49 if (room_list[i].current_view == views.VIEW_BBS) {
50 output[room_list[i].floor] +=
51 "<div class=\"ctdl-roomlist-room\" onClick=\"javascript:gotoroom('"
52 + escapeJS(escapeHTML(room_list[i].name)) + "');\">"
53 + "<i class=\"ctdl-roomlist-roomicon "
54 + (room_list[i].hasnewmsgs ? "w3-blue" : "w3-gray")
55 + " fas fa-comments fa-fw\"></i><span class=\"ctdl-roomlist-roomname"
56 + (room_list[i].hasnewmsgs ? " ctdl-roomlist-roomname-hasnewmsgs" : "")
58 + escapeHTML(room_list[i].name)
59 + "</span><span class=\"ctdl-roomlist-mtime w3-right\">"
60 + string_timestamp(room_list[i].mtime)
65 final_output = "<div class=\"ctdl-roomlist-top\">";
66 for (var f in floor_list) {
68 "<div class=\"ctdl-roomlist-floor\">"
69 + "<div class=\"ctdl-roomlist-floor-label\">" + floor_list[f].name + "</div>"
70 + "<div class=\"ctdl-roomlist-floor-rooms\">"
71 + output[floor_list[f].num]
74 final_output += "</div>";
75 document.getElementById("ctdl-main").innerHTML = final_output;