From 417d9bbd646248daebde2ab0ccc2fcbcb8911426 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Oct 2020 13:41:25 -0400 Subject: Implement folder creation UI --- plugins/base/routes.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ themes/alps/new-mailbox.html | 23 +++++++++++++++++++++++ themes/alps/util.html | 5 ++++- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 themes/alps/new-mailbox.html diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 7e30513..c031cb0 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -31,6 +31,9 @@ func registerRoutes(p *alps.GoPlugin) { p.GET("/mailbox/:mbox", handleGetMailbox) p.POST("/mailbox/:mbox", handleGetMailbox) + p.GET("/new-mailbox", handleNewMailbox) + p.POST("/new-mailbox", handleNewMailbox) + p.GET("/message/:mbox/:uid", func(ctx *alps.Context) error { return handleGetPart(ctx, false) }) @@ -259,6 +262,47 @@ func handleGetMailbox(ctx *alps.Context) error { }) } +type NewMailboxRenderData struct { + IMAPBaseRenderData + Error string +} + +func handleNewMailbox(ctx *alps.Context) error { + ibase, err := newIMAPBaseRenderData(ctx, alps.NewBaseRenderData(ctx)) + if err != nil { + return err + } + ibase.BaseRenderData.WithTitle("Create new folder") + + if ctx.Request().Method == http.MethodPost { + name := ctx.FormValue("name") + if name == "" { + return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{ + IMAPBaseRenderData: *ibase, + Error: "Name is required", + }) + } + + err := ctx.Session.DoIMAP(func(c *imapclient.Client) error { + return c.Create(name) + }) + + if err != nil { + return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{ + IMAPBaseRenderData: *ibase, + Error: err.Error(), + }) + } + + return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%s", url.PathEscape(name))) + } + + return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{ + IMAPBaseRenderData: *ibase, + Error: "", + }) +} + func handleLogin(ctx *alps.Context) error { username := ctx.FormValue("username") password := ctx.FormValue("password") diff --git a/themes/alps/new-mailbox.html b/themes/alps/new-mailbox.html new file mode 100644 index 0000000..d202783 --- /dev/null +++ b/themes/alps/new-mailbox.html @@ -0,0 +1,23 @@ +{{template "head.html" .}} +{{template "nav.html" .}} +{{template "util.html" .}} + +
+ {{ template "aside" . }} +
+
+
+

Create new folder

+ + + {{ if .Error }}

{{ .Error }}

{{ end }} +
+ + Cancel +
+
+
+
+
+ +{{template "foot.html"}} diff --git a/themes/alps/util.html b/themes/alps/util.html index 89e5cac..5ee456a 100644 --- a/themes/alps/util.html +++ b/themes/alps/util.html @@ -26,7 +26,7 @@ Compose Mail + ">Compose mail {{ with .CategorizedMailboxes }} {{ with .Common.Inbox }}{{ template "mbox-link" . }}{{ end}} {{ with .Common.Drafts }}{{ template "mbox-link" . }}{{ end}} @@ -42,5 +42,8 @@ {{ end }} {{ end }} {{ end }} + Create new folder {{ end }} -- cgit v1.2.3