]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/view_calendar.js
Calendar view: initial call of REPORT method.
[citadel.git] / webcit-ng / static / js / view_calendar.js
index 17a1a4ea5c62c8a5b56d15d76617ea6486532031..f5c53fc19b4142b2341712b4e60a1b1c75beb027 100644 (file)
@@ -3,25 +3,42 @@
 // Copyright (c) 2016-2023 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
-// disclosure are subject to the GNU General Public License v3.
+// disclosure is subject to the GNU General Public License v3.
 
 
 // RENDERER FOR THIS VIEW
 function view_render_calendar() {
-       document.getElementById("ctdl-main").innerHTML = `STUB RENDERER FOR CALENDAR ROOM`;
 
-       fetch(
-               "/ctdl/r/" + escapeHTMLURI(current_room) + "/calendar::"
-       )
-       .then((response) => {
+       let options = {
+               method: "REPORT",
+               headers: {
+                       "Content-Type" : "application/xml; charset=utf-8"
+               },
+               body: `
+                       <CAL:calendar-query xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav">
+                               <allprop />
+                               <CAL:filter>
+                                       <CAL:comp-filter name="VCALENDAR">
+                                       <CAL:comp-filter name="VEVENT" />
+                                       </CAL:comp-filter>
+                               </CAL:filter>
+                       </CAL:calendar-query>
+               `
+       };
+
+       fetch("/ctdl/r/" + escapeHTMLURI(current_room), options)
+       .then(response => {
                if (response.ok) {
-                       return(response.json());
+                       return(response.text());
+               }
+               else {
+                       throw new Error(`${response.status} ${response.statusText}`);
                }
        })
-       .then((j) => {
-               console.log("Something");
-       })
-       .catch((error) => {
-               console.log("Error: " + error);
+       //.then(str => new window.DOMParser().parseFromString(str, "text/xml"))
+       .then(str => document.getElementById("ctdl-main").innerHTML = escapeHTML(str))
+       .catch(error => {
+               console.log(error);
+               document.getElementById("ctdl-main").innerHTML = `<div class="ctdl-fatal-error">${error}</div>`;
        });
 }