f5c53fc19b4142b2341712b4e60a1b1c75beb027
[citadel.git] / webcit-ng / static / js / view_calendar.js
1 // This module handles the view for "calendar" rooms.
2 //
3 // Copyright (c) 2016-2023 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or
6 // disclosure is subject to the GNU General Public License v3.
7
8
9 // RENDERER FOR THIS VIEW
10 function view_render_calendar() {
11
12         let options = {
13                 method: "REPORT",
14                 headers: {
15                         "Content-Type" : "application/xml; charset=utf-8"
16                 },
17                 body: `
18                         <CAL:calendar-query xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav">
19                                 <allprop />
20                                 <CAL:filter>
21                                         <CAL:comp-filter name="VCALENDAR">
22                                         <CAL:comp-filter name="VEVENT" />
23                                         </CAL:comp-filter>
24                                 </CAL:filter>
25                         </CAL:calendar-query>
26                 `
27         };
28
29         fetch("/ctdl/r/" + escapeHTMLURI(current_room), options)
30         .then(response => {
31                 if (response.ok) {
32                         return(response.text());
33                 }
34                 else {
35                         throw new Error(`${response.status} ${response.statusText}`);
36                 }
37         })
38         //.then(str => new window.DOMParser().parseFromString(str, "text/xml"))
39         .then(str => document.getElementById("ctdl-main").innerHTML = escapeHTML(str))
40         .catch(error => {
41                 console.log(error);
42                 document.getElementById("ctdl-main").innerHTML = `<div class="ctdl-fatal-error">${error}</div>`;
43         });
44 }