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
11 clear_sidebar_selection();
12 document.getElementById("ctdl-sidebar-button-forums").classList.add("ctdl-sidebar-button-selected");
14 fetch_room_list = async() => {
15 floor_response = await fetch("/ctdl/f/");
16 floor_list = await(floor_response.json());
17 room_response = await fetch("/ctdl/r/");
18 room_list = await(room_response.json());
20 display_room_list_renderer(floor_list, room_list);
23 document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
30 // Renderer for display_room_list()
31 function display_room_list_renderer(floor_list, room_list) {
33 // First sort by the room order indicated by the server
34 room_list = room_list.sort(function(a,b) {
35 if (a.floor != b.floor) {
36 return(a.floor - b.floor);
38 if (a.rorder != b.rorder) {
39 return(a.rorder - b.rorder);
41 return(a.name < b.name);
44 // Then split the sorted list out into floors
46 for (var f in floor_list) {
47 output[floor_list[f].num] = "";
50 for (var i in room_list) {
51 if (room_list[i].current_view == views.VIEW_BBS) {
52 output[room_list[i].floor] +=
54 "<div class=\"ctdl-roomlist-room\" onClick=\"javascript:gotoroom('" // container
55 + escapeJS(escapeHTML(room_list[i].name)) + "');\">"
57 + "<div><i class=\"ctdl-roomlist-roomicon " // room icon
58 + (room_list[i].hasnewmsgs ? "w3-blue" : "w3-gray")
59 + " fas fa-comments fa-fw\"></i></div>"
61 + "<div class=\"ctdl-roomlist-roomname" // room name
62 + (room_list[i].hasnewmsgs ? " ctdl-roomlist-roomname-hasnewmsgs" : "")
64 + escapeHTML(room_list[i].name)
67 + "<div class=\"ctdl-roomlist-mtime\">" // date/time of last post
68 + string_timestamp(room_list[i].mtime)
71 + "</div>" // end container
75 final_output = "<div class=\"ctdl-roomlist-top\">";
76 for (var f in floor_list) {
78 "<div class=\"ctdl-roomlist-floor\">"
79 + "<div class=\"ctdl-roomlist-floor-label\">" + floor_list[f].name + "</div>"
80 + "<div class=\"ctdl-roomlist-floor-rooms\">"
81 + output[floor_list[f].num]
84 final_output += "</div>";
85 document.getElementById("ctdl-main").innerHTML = final_output;