]> code.citadel.org Git - citadel.git/blob - webcit-ng/static/js/roomlist.js
"Forum list" is now more or less in its final form.
[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.  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.
7 //
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.
12
13
14 function render_room_list() {
15
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
18
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());
24                 if (response.ok) {
25                         display_room_list_renderer(floor_list, room_list);
26                 }
27                 else {
28                         document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
29                 }
30         }
31         fetch_room_list();
32 }
33
34
35 // Renderer for display_room_list()
36 function display_room_list_renderer(floor_list, room_list) {
37
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);
42                 }
43                 if (a.rorder != b.rorder) {
44                         return(a.rorder - b.rorder);
45                 }
46                 return(a.name < b.name);
47         });
48
49         // Then split the sorted list out into floors
50         output = [];
51         for (var f in floor_list) {
52                 output[floor_list[f].num] = "";
53         }
54
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" : "")
64                                 + " w3-left\">"
65                                 + escapeHTML(room_list[i].name)
66                                 + "</span><span class=\"ctdl-roomlist-mtime w3-right\">"
67                                 + convertTimestamp(room_list[i].mtime)
68                                 + "</span></div>";
69                 }
70         }
71
72         final_output = "<div class=\"ctdl-roomlist-top\">";
73         for (var f in floor_list) {
74                 final_output +=
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]
79                         + "</div></div>";
80         }
81         final_output += "</div>";
82         document.getElementById("ctdl-main").innerHTML = final_output;
83 }
84