]> code.citadel.org Git - citadel.git/blob - webcit-ng/static/js/roomlist.js
Sort room list by floor but also put them in different divs
[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
21                 floor_response = await fetch("/ctdl/f/");
22                 floor_list = await(floor_response.json());
23                 room_response = await fetch("/ctdl/r/");
24                 room_list = await(room_response.json());
25                 if (response.ok) {
26                         display_room_list_renderer(floor_list, room_list);
27                 }
28                 else {
29                         document.getElementById("ctdl-main").innerHTML = "<i>error</i>";
30                 }
31         }
32         fetch_room_list();
33 }
34
35
36 // Renderer for display_room_list()
37 function display_room_list_renderer(floor_list, room_list) {
38         room_list = room_list.sort(function(a,b) {
39                 if (a.floor != b.floor) {
40                         return(a.floor - b.floor);
41                 }
42                 if (a.rorder != b.rorder) {
43                         return(a.rorder - b.rorder);
44                 }
45                 return(a.name < b.name);
46         });
47
48         output = [];
49
50         for (var f in floor_list) {
51                 output[floor_list[f].num] = "<div><b>Room list for " + floor_list[f].name + "</b><br>";
52         }
53
54         for (var i in room_list) {
55                 output[room_list[i].floor] += (room_list[i].hasnewmsgs ? "<b>" : "");
56                 output[room_list[i].floor] += "<a href=\"javascript:gotoroom('" + escapeJS(escapeHTML(room_list[i].name)) + "');\">";
57                 output[room_list[i].floor] += escapeHTML(room_list[i].name);
58                 output[room_list[i].floor] += (room_list[i].hasnewmsgs ? "</b>" : "");
59                 output[room_list[i].floor] += "</a>";
60                 if (room_list[i].current_view == views.VIEW_BBS) {
61                         output[room_list[i].floor] += "(FORUM)";
62                 }
63                 output[room_list[i].floor] += "<br>";
64         }
65
66         final_output = "";
67         for (var f in floor_list) {
68                 final_output += output[floor_list[f].num];
69                 final_output += "<br>";
70         }
71         document.getElementById("ctdl-main").innerHTML = final_output ;
72 }
73