Implement folder creation UI

This commit is contained in:
Drew DeVault 2020-10-30 13:41:25 -04:00
parent 2bef9425fb
commit 417d9bbd64
3 changed files with 71 additions and 1 deletions

View file

@ -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")

View file

@ -0,0 +1,23 @@
{{template "head.html" .}}
{{template "nav.html" .}}
{{template "util.html" .}}
<div class="page-wrap">
{{ template "aside" . }}
<div class="container">
<main class="create-update">
<form method="POST">
<h2>Create new folder</h2>
<label for="name">Name</label>
<input type="text" name="name" id="name" autofocus />
{{ if .Error }}<p>{{ .Error }}</p>{{ end }}
<div class="actions">
<button type="submit">Save</button>
<a class="button-link" href="/">Cancel</a>
</div>
</form>
</main>
</div>
</div>
{{template "foot.html"}}

View file

@ -26,7 +26,7 @@
<!-- the logo image, dimensions 200x32 may be present or not -->
<a href="/compose" class="new
{{ if eq $.GlobalData.URL.Path "/compose" }}active{{ end }}
">Compose&nbsp;Mail</a>
">Compose&nbsp;mail</a>
{{ with .CategorizedMailboxes }}
{{ with .Common.Inbox }}{{ template "mbox-link" . }}{{ end}}
{{ with .Common.Drafts }}{{ template "mbox-link" . }}{{ end}}
@ -42,5 +42,8 @@
{{ end }}
{{ end }}
{{ end }}
<a href="/new-mailbox" class="new
{{ if eq $.GlobalData.URL.Path "/new-mailbox" }}active{{ end }}
">Create&nbsp;new&nbsp;folder</a>
</aside>
{{ end }}