aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-07-12 23:28:51 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-07-12 23:28:51 +0200
commit8ee9a7311ce7ddab3c8be062fc536766ab77345f (patch)
treee65adcef04081f1b96f0a49e43d78a69a1b7607e
parentSXML Namespace mappings. (diff)
downloadcalp-8ee9a7311ce7ddab3c8be062fc536766ab77345f.tar.gz
calp-8ee9a7311ce7ddab3c8be062fc536766ab77345f.tar.xz
Event creation from HTML works again.
-rw-r--r--module/entry-points/server.scm32
-rw-r--r--static/script.js35
2 files changed, 32 insertions, 35 deletions
diff --git a/module/entry-points/server.scm b/module/entry-points/server.scm
index 6e038526..fc832c13 100644
--- a/module/entry-points/server.scm
+++ b/module/entry-points/server.scm
@@ -23,6 +23,8 @@
:use-module (web http)
:use-module (sxml simple)
+ :use-module (sxml xpath)
+ :use-module (sxml namespace)
:use-module (server util)
:use-module (server macro)
@@ -136,15 +138,31 @@
(return (build-response code: 400)
(format #f "No calendar with name [~a]\r\n" cal)))
+ ;; Expected form of data (but in XML) is:
+ ;; @example
+ ;; (*TOP*
+ ;; (*PI* ...)
+ ;; (icalendar (@ (xmlns "..."))
+ ;; (vcalendar
+ ;; (vevent ...))))
+ ;; @end example
+ ;; However, *PI* will probably be omited, and currently events
+ ;; are sent without the vcalendar part. Earlier versions
+ ;; Also omitted the icalendar part. And I'm not sure if the
+ ;; *TOP* node is a required part of the sxml.
+
(let ((event
((@ (vcomponent parse xcal) sxcal->vcomponent)
- ;; TODO different forms?
- (cadr ; removes *TOP*
- (catch 'parser-error
- (lambda () (xml->sxml data))
- (lambda (err port . args)
- (return (build-response code: 400)
- (format #f "XML parse error ~{~a~}\r\n" args))))))))
+ (catch 'parser-error
+ (lambda ()
+ (move-to-namespace
+ ;; TODO Multiple event components
+ (car ((sxpath '(// IC:vevent))
+ (xml->sxml data namespaces: '((IC . "urn:ietf:params:xml:ns:icalendar-2.0")))))
+ #f))
+ (lambda (err port . args)
+ (return (build-response code: 400)
+ (format #f "XML parse error ~{~a~}\r\n" args)))))))
(unless (eq? 'VEVENT (type event))
(return (build-response code: 400)
diff --git a/static/script.js b/static/script.js
index dd86154b..de73ba05 100644
--- a/static/script.js
+++ b/static/script.js
@@ -221,37 +221,12 @@ function close_all_popups () {
}
}
-function sxml_to_xml(doc, tree) {
+async function create_event (event) {
- if (typeof(tree) == 'string') return tree;
-
- let [tag, ...body] = tree;
- let node = doc.createElement(tag);
- for (const child of body) {
- node.append(sxml_to_xml(doc, child));
- }
- return node;
-}
-
-// FormData
-async function create_event (date, fd) {
-
- let tree = ['vevent',
- ['properties',
- ['dtstart', ['date-time', date + "T" + fd.get("dtstart") + ":00"]],
- ['dtend', ['date-time', date + "T" + fd.get("dtend") + ":00"]],
- ['summary', ['text', fd.get("summary")]]]]
-
- if (fd.get("description")) {
- tree[1].push(['description', ['text', fd.get("description")]])
- }
-
- let xmldoc = document.implementation.createDocument("", "", null)
- xml = sxml_to_xml(xmldoc, tree).outerHTML;
+ let xml = event.getElementsByTagName("icalendar")[0].outerHTML
console.log(xml);
-
let data = new URLSearchParams();
data.append("cal", "Calendar");
data.append("data", xml);
@@ -325,7 +300,11 @@ function place_in_edit_mode (event) {
article.appendChild(submit);
- let wrappingForm = makeElement('form');
+ let wrappingForm = makeElement('form', {
+ onsubmit: function (e) {
+ create_event(event);
+ return false;
+ }});
article.replaceWith(wrappingForm);
wrappingForm.appendChild(article);