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() => {
20 floor_response = await fetch("/ctdl/f/");
21 floor_list = await(floor_response.json());
22 room_response = await fetch("/ctdl/r/");
23 room_list = await(room_response.json());
25 display_room_list_renderer(floor_list, room_list);
28 document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
35 // Renderer for display_room_list()
36 function display_room_list_renderer(floor_list, room_list) {
38 // First sort by the room order indicated by the server
39 room_list = room_list.sort(function(a,b) {
40 if (a.floor != b.floor) {
41 return(a.floor - b.floor);
43 if (a.rorder != b.rorder) {
44 return(a.rorder - b.rorder);
46 return(a.name < b.name);
49 // Then split the sorted list out into floors
51 for (var f in floor_list) {
52 output[floor_list[f].num] = "";
55 for (var i in room_list) {
56 if (room_list[i].current_view == views.VIEW_BBS) {
57 output[room_list[i].floor] +=
58 "<div class=\"w3-button ctdl-roomlist-room\" onClick=\"javascript:gotoroom('"
59 + escapeJS(escapeHTML(room_list[i].name)) + "');\">"
60 + "<i class=\"ctdl-roomlist-roomicon w3-left "
61 + (room_list[i].hasnewmsgs ? " ctdl-roomlist-roomicon-hasnewmsgs" : "")
62 + " fas fa-comments fa-fw\"></i><span class=\"ctdl-roomlist-roomname"
63 + (room_list[i].hasnewmsgs ? " ctdl-roomlist-roomname-hasnewmsgs" : "")
65 + escapeHTML(room_list[i].name)
66 + "</span><span class=\"ctdl-roomlist-mtime w3-right\">"
67 + convertTimestamp(room_list[i].mtime)
72 final_output = "<div class=\"ctdl-roomlist-top\">";
73 for (var f in floor_list) {
75 "<div class=\"ctdl-roomlist-floor\">"
76 + "<div class=\"ctdl-roomlist-floor-label\">" + floor_list[f].name + "</div>"
77 + "<div class=\"ctdl-roomlist-floor-rooms\">"
78 + output[floor_list[f].num]
81 final_output += "</div>";
82 document.getElementById("ctdl-main").innerHTML = final_output;