]> code.citadel.org Git - citadel.git/blob - webcit-ng/static/js/roomlist.js
All right, this is more or less it. I had to resort to creating a function stuffbar...
[citadel.git] / webcit-ng / static / js / roomlist.js
1 // Copyright (c) 2016-2022 by the citadel.org team
2 //
3 // This program is open source software.  Use, duplication, or
4 // disclosure are subject to the GNU General Public License v3.
5
6
7 function render_room_list() {
8
9         stuffbar("none");                                                               // No stuffbar on this screen
10         document.getElementById("ctdl-newmsg-button").style.display = "none";           // There is no "enter" button on this screen
11         document.getElementById("ctdl-main").innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />"; // show throbber while loading
12
13         fetch_room_list = async() => {
14                 floor_response = await fetch("/ctdl/f/");
15                 floor_list = await(floor_response.json());
16                 room_response = await fetch("/ctdl/r/");
17                 room_list = await(room_response.json());
18                 if (response.ok) {
19                         display_room_list_renderer(floor_list, room_list);
20                 }
21                 else {
22                         document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
23                 }
24         }
25         fetch_room_list();
26 }
27
28
29 // Renderer for display_room_list()
30 function display_room_list_renderer(floor_list, room_list) {
31
32         // First sort by the room order indicated by the server
33         room_list = room_list.sort(function(a,b) {
34                 if (a.floor != b.floor) {
35                         return(a.floor - b.floor);
36                 }
37                 if (a.rorder != b.rorder) {
38                         return(a.rorder - b.rorder);
39                 }
40                 return(a.name < b.name);
41         });
42
43         // Then split the sorted list out into floors
44         output = [];
45         for (var f in floor_list) {
46                 output[floor_list[f].num] = "";
47         }
48
49         for (var i in room_list) {
50                 if (room_list[i].current_view == views.VIEW_BBS) {
51                         output[room_list[i].floor] +=
52                                 "<div class=\"w3-button ctdl-roomlist-room\" onClick=\"javascript:gotoroom('"
53                                 + escapeJS(escapeHTML(room_list[i].name)) + "');\">"
54                                 + "<i class=\"w3-badge ctdl-roomlist-roomicon w3-left "
55                                 + (room_list[i].hasnewmsgs ? "w3-blue" : "w3-gray")
56                                 + " fas fa-comments fa-fw\"></i><span class=\"ctdl-roomlist-roomname"
57                                 + (room_list[i].hasnewmsgs ? " ctdl-roomlist-roomname-hasnewmsgs" : "")
58                                 + " w3-left\">"
59                                 + escapeHTML(room_list[i].name)
60                                 + "</span><span class=\"ctdl-roomlist-mtime w3-right\">"
61                                 + convertTimestamp(room_list[i].mtime)
62                                 + "</span></div>";
63                 }
64         }
65
66         final_output = "<div class=\"ctdl-roomlist-top\">";
67         for (var f in floor_list) {
68                 final_output +=
69                         "<div class=\"ctdl-roomlist-floor\">"
70                         + "<div class=\"ctdl-roomlist-floor-label\">" + floor_list[f].name + "</div>"
71                         + "<div class=\"ctdl-roomlist-floor-rooms\">"
72                         + output[floor_list[f].num]
73                         + "</div></div>";
74         }
75         final_output += "</div>";
76         document.getElementById("ctdl-main").innerHTML = final_output;
77 }
78