plugins/caldav: add route to delete event

This commit is contained in:
Simon Ser 2020-05-20 16:54:33 +02:00
parent 36f3fb9567
commit 7157627dcf
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 25 additions and 1 deletions

View file

@ -4,13 +4,19 @@
<p>
<a href="/calendar">Back</a>
· <a href="{{.Event.URL}}/update">Edit</a>
</p>
{{$event := index .Event.Data.Events 0}}
<h2>Event: {{$event.Props.Text "SUMMARY"}}</h2>
<p>
<a href="{{.Event.URL}}/update">Edit</a>
<form action="{{.Event.URL}}/delete" method="post">
<input type="submit" value="Delete">
</form>
</p>
<ul>
<li><strong>Start date</strong>: {{$event.DateTimeStart nil | formatdate}}</li>
<li><strong>End date</strong>: {{$event.DateTimeEnd nil | formatdate}}</li>

View file

@ -239,4 +239,22 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
p.GET("/calendar/:path/update", updateEvent)
p.POST("/calendar/:path/update", updateEvent)
p.POST("/calendar/:path/delete", func(ctx *alps.Context) error {
path, err := parseObjectPath(ctx.Param("path"))
if err != nil {
return err
}
c, _, err := getCalendar(u, ctx.Session)
if err != nil {
return err
}
if err := c.RemoveAll(path); err != nil {
return fmt.Errorf("failed to delete calendar object: %v", err)
}
return ctx.Redirect(http.StatusFound, "/calendar")
})
}