Moved the room list from the sidebar to the main viewing pane.
[citadel.git] / webcit-ng / static / js / roomlist.js
1 //
2 // Copyright (c) 2016-2022 by the citadel.org team
3 //
4 // This program is open source software.  It runs great on the
5 // Linux operating system (and probably elsewhere).  You can use,
6 // copy, and run it under the terms of the GNU General Public
7 // License version 3.  Richard Stallman is an asshole communist.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13
14
15 function render_room_list() {
16
17
18         document.getElementById("ctdl-newmsg-button").style.display = "none";           // There is no "enter" button on this screen
19         document.getElementById("ctdl-main").innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />"; // show throbber while loading
20
21         fetch_room_list = async() => {
22                 response = await fetch("/ctdl/r/");
23                 room_list = await(response.json());
24                 if (response.ok) {
25                         display_room_list_renderer(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(data) {
37         data = data.sort(function(a,b) {
38                 if (a.floor != b.floor) {
39                         return(a.floor - b.floor);
40                 }
41                 if (a.rorder != b.rorder) {
42                         return(a.rorder - b.rorder);
43                 }
44                 return(a.name < b.name);
45         });
46
47         new_roomlist_text = "<ul>" ;
48
49         for (var i in data) {
50                 if (i > 0) {
51                         if (data[i].floor != data[i-1].floor) {
52                                 new_roomlist_text = new_roomlist_text + "<li class=\"divider\"></li>" ;
53                         }
54                 }
55                 new_roomlist_text = new_roomlist_text +
56                         "<li>"
57                         + (data[i].hasnewmsgs ? "<b>" : "")
58                         + "<a href=\"javascript:gotoroom('" + escapeJS(escapeHTML(data[i].name)) + "');\">"
59                         + escapeHTML(data[i].name)
60                         + (data[i].hasnewmsgs ? "</b>" : "")
61                         + "</a></li>"
62                 ;
63         }
64         new_roomlist_text = new_roomlist_text + "</ul>";
65         document.getElementById("ctdl-main").innerHTML = new_roomlist_text ;
66 }
67