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] +=
52 "<div class=\"ctdl-roomlist-room\" onClick=\"javascript:gotoroom('" // container
53 + escapeJS(escapeHTML(room_list[i].name)) + "');\">"
55 + "<div><i class=\"ctdl-roomlist-roomicon " // room icon
56 + (room_list[i].hasnewmsgs ? "w3-blue" : "w3-gray")
57 + " fas fa-comments fa-fw\"></i></div>"
59 + "<div class=\"ctdl-roomlist-roomname" // room name
60 + (room_list[i].hasnewmsgs ? " ctdl-roomlist-roomname-hasnewmsgs" : "")
62 + escapeHTML(room_list[i].name)
65 + "<div class=\"ctdl-roomlist-mtime\">" // date/time of last post
66 + string_timestamp(room_list[i].mtime)
69 + "</div>" // end container
73 final_output = "<div class=\"ctdl-roomlist-top\">";
74 for (var f in floor_list) {
76 "<div class=\"ctdl-roomlist-floor\">"
77 + "<div class=\"ctdl-roomlist-floor-label\">" + floor_list[f].name + "</div>"
78 + "<div class=\"ctdl-roomlist-floor-rooms\">"
79 + output[floor_list[f].num]
82 final_output += "</div>";
83 document.getElementById("ctdl-main").innerHTML = final_output;