]> code.citadel.org Git - citadel.git/blob - webcit-ng/static/js/roomlist.js
room list renderer is now aware of which rooms are forum view:
[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
17         document.getElementById("ctdl-newmsg-button").style.display = "none";           // There is no "enter" button on this screen
18         document.getElementById("ctdl-main").innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />"; // show throbber while loading
19
20         fetch_room_list = async() => {
21                 response = await fetch("/ctdl/r/");
22                 room_list = await(response.json());
23                 if (response.ok) {
24                         display_room_list_renderer(room_list);
25                 }
26                 else {
27                         document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
28                 }
29         }
30         fetch_room_list();
31 }
32
33
34 // Renderer for display_room_list()
35 function display_room_list_renderer(data) {
36         data = data.sort(function(a,b) {
37                 if (a.floor != b.floor) {
38                         return(a.floor - b.floor);
39                 }
40                 if (a.rorder != b.rorder) {
41                         return(a.rorder - b.rorder);
42                 }
43                 return(a.name < b.name);
44         });
45
46         new_roomlist_text = "<ul>" ;
47
48         for (var i in data) {
49                 if (i > 0) {
50                         if (data[i].floor != data[i-1].floor) {
51                                 new_roomlist_text = new_roomlist_text + "<li class=\"divider\"></li>" ;
52                         }
53                 }
54                 new_roomlist_text = new_roomlist_text +
55                           "<li>"
56                         + (data[i].hasnewmsgs ? "<b>" : "")
57                         + "<a href=\"javascript:gotoroom('" + escapeJS(escapeHTML(data[i].name)) + "');\">"
58                         + escapeHTML(data[i].name)
59                         + (data[i].hasnewmsgs ? "</b>" : "")
60                         + "</a>"
61                 if (data[i].current_view == views.VIEW_BBS) {
62                         new_roomlist_text = new_roomlist_text + "(FORUM)";
63                 }
64                 new_roomlist_text = new_roomlist_text +
65                           "</li>"
66                 ;
67         }
68         new_roomlist_text = new_roomlist_text + "</ul>";
69         document.getElementById("ctdl-main").innerHTML = new_roomlist_text ;
70 }
71