1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17:03 +00:00

Message list is now loaded by AJAX and can be refreshed.

Added a message delete button.
This commit is contained in:
James Hillyerd
2012-10-13 14:11:12 -07:00
parent 301c3efa63
commit a0ab84abb5
7 changed files with 137 additions and 50 deletions

View File

@@ -1,7 +1,6 @@
package controllers
import (
"fmt"
"github.com/jhillyerd/inbucket/app/inbucket"
"github.com/robfig/revel"
)
@@ -11,12 +10,10 @@ type Mailbox struct {
}
func (c Mailbox) Index(name string) rev.Result {
return c.Redirect("/mailbox/list/%v", name)
return c.Render(name)
}
func (c Mailbox) List(name string) rev.Result {
title := fmt.Sprintf("Mailbox for %v", name)
ds := inbucket.NewDataStore()
mb, err := ds.MailboxFor(name)
if err != nil {
@@ -32,7 +29,7 @@ func (c Mailbox) List(name string) rev.Result {
}
rev.INFO.Printf("Got %v messsages", len(messages))
return c.Render(title, name, messages)
return c.Render(name, messages)
}
func (c Mailbox) Show(name string, id string) rev.Result {
@@ -58,3 +55,26 @@ func (c Mailbox) Show(name string, id string) rev.Result {
return c.Render(name, message, body)
}
func (c Mailbox) Delete(name string, id string) rev.Result {
ds := inbucket.NewDataStore()
mb, err := ds.MailboxFor(name)
if err != nil {
rev.ERROR.Printf(err.Error())
c.Flash.Error(err.Error())
return c.Redirect(Application.Index)
}
message, err := mb.GetMessage(id)
if err != nil {
rev.ERROR.Printf(err.Error())
c.Flash.Error(err.Error())
return c.Redirect(Application.Index)
}
err = message.Delete()
if err != nil {
rev.ERROR.Printf(err.Error())
c.Flash.Error(err.Error())
return c.Redirect(Application.Index)
}
return c.RenderText("OK")
}