Mailing list header changes (fuck you Google)
[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 => document.getElementById("ctdl-main").innerHTML = escapeHTML(str))
39         .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
40         .then(xmlcal => {
41                 document.getElementById("ctdl-main").innerHTML = "calendar items:<br>";
42                 let root = xmlcal.documentElement;
43                 let children = root.childNodes;
44                 for (let i=0; i<children.length; ++i) {
45                         let child = children[i];
46                         if (child.nodeType == Node.ELEMENT_NODE) {
47                                 var getetag_e = child.getElementsByTagName("DAV:href")[0];
48                                 var getetag_s = getetag_e.textContent;
49                                 document.getElementById("ctdl-main").innerHTML += getetag_s + "<br>";
50                         }
51                 }
52
53         })
54         .catch(error => {
55                 console.log(error);
56                 document.getElementById("ctdl-main").innerHTML = `<div class="ctdl-fatal-error">${error}</div>`;
57         });
58 }