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

View File

@@ -239,6 +239,15 @@ func (m *Message) Close() error {
return m.createGob()
}
// Delete this Message from disk by removing both the gob and raw files
func (m *Message) Delete() error {
err := os.Remove(m.gobPath())
if err != nil {
return err
}
return os.Remove(m.rawPath())
}
// createGob reads the .raw file to grab the From and Subject header entries,
// then creates the .gob file.
func (m *Message) createGob() error {

View File

@@ -0,0 +1,72 @@
{{$title := printf "Inbucket for %v" .name}}
{{set "title" $title .}}
{{template "header.html" .}}
{{$name := .name}}
<script>
function listLoaded() {
$('.listEntry').hover(
function() {
$(this).addClass("listEntryHover")
},
function() {
$(this).removeClass("listEntryHover")
}
).click(
function() {
$('.listEntry').removeClass("listEntrySelected")
$(this).addClass("listEntrySelected")
$('#emailContent').load('/mailbox/show/{{$name}}/' + this.id)
}
)
$("#messageList").slideDown()
}
function loadList() {
$('#messageList').load("/mailbox/list/{{$name}}", listLoaded)
}
function reloadList() {
$('#messageList').slideUp()
loadList()
}
function listInit() {
$("#messageList").hide()
loadList()
}
function deleteMessage(id) {
$('#emailContent').empty()
$.ajax({
type: 'POST',
url: '/mailbox/delete/{{$name}}/' + id,
success: reloadList
})
}
function messageSource(id) {
alert('delete')
}
$(document).ready(listInit)
</script>
<div id="colOne">
<div id="logo">
<h1><a href="#">inbucket</a></h1>
<h2>mail for {{.name}}</h2>
</div>
<div class="box" style="text-align:center; padding-bottom:10px;">
<a href="javascript:reloadList()">Refresh List</a>
</div>
<div id="messageList"></div>
</div>
<div id="colTwo">
<div id="emailContent">
<p>Select a message at left, or enter a different username into the box on upper right.</p>
</div>
</div>
{{template "footer.html" .}}

View File

@@ -1,48 +1,12 @@
{{template "header.html" .}}
{{$name := .name}}
<script>
$(document).ready(function() {
$('.listEntry').hover(
function() {
$(this).addClass("listEntryHover")
},
function() {
$(this).removeClass("listEntryHover")
}
).click(
function() {
$('.listEntry').removeClass("listEntrySelected")
$(this).addClass("listEntrySelected")
$('#emailContent').load('/mailbox/show/{{$name}}/' + this.id)
}
)
});
</script>
<div id="colOne">
<div id="logo">
<h1><a href="#">inbucket</a></h1>
<h2>mail for {{.name}}</h2>
</div>
{{range .messages}}
<div class="box listEntry" id="{{.Id}}">
<div class="subject">{{/*<a href="/mailbox/show/{{$name}}/{{.Id}}">*/}}{{.Subject}}</div>
<div class="from">{{.From}}</div>
<div class="date">{{.Date}}</div>
</div>
{{else}}
<div class="box">
<p style="height: 30px; padding-left: 10px;">No messages!</p>
</div>
{{end}}
{{range .messages}}
<div class="box listEntry" id="{{.Id}}">
<div class="subject">{{/*<a href="/mailbox/show/{{$name}}/{{.Id}}">*/}}{{.Subject}}</div>
<div class="from">{{.From}}</div>
<div class="date">{{.Date}}</div>
</div>
<div id="colTwo">
<div id="emailContent">
<p>Select a message at left, or enter a different username into the box on upper right.</p>
</div>
{{else}}
<div class="box">
<p style="height: 30px; padding-left: 10px;">No messages!</p>
</div>
{{template "footer.html" .}}
{{end}}

View File

@@ -1,3 +1,7 @@
<div id="emailActions">
<a href="javascript:deleteMessage('{{.message.Id}}');">Delete</a>
<a href="javascript:messageSource('{{.message.Id}}');">Source</a>
</div>
<table id="emailHeader">
<tr>
<th>From:</th>

View File

@@ -7,6 +7,7 @@ GET /mailbox/{name} Mailbox.Index
GET /mailbox Mailbox.Index
GET /mailbox/list/{name} Mailbox.List
GET /mailbox/show/{name}/{id} Mailbox.Show
POST /mailbox/delete/{name}/{id} Mailbox.Delete
# Ignore favicon requests
GET /favicon.ico 404

View File

@@ -266,6 +266,7 @@ a:hover {
#emailContent {
padding-bottom: 20px;
min-height: 300px;
}
#emailHeader {
@@ -285,3 +286,19 @@ a:hover {
color: #000000;
}
#emailActions {
padding: 5px 0;
margin: 0 0 10px 0;
}
#emailActions a {
background: #8ac6dc;
color: #fff;
text-decoration: none;
font-weight: bold;
padding: 5px;
}
#emailActions a:hover {
background: #becf74;
}