mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Message list is now loaded by AJAX and can be refreshed.
Added a message delete button.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/jhillyerd/inbucket/app/inbucket"
|
"github.com/jhillyerd/inbucket/app/inbucket"
|
||||||
"github.com/robfig/revel"
|
"github.com/robfig/revel"
|
||||||
)
|
)
|
||||||
@@ -11,12 +10,10 @@ type Mailbox struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Mailbox) Index(name string) rev.Result {
|
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 {
|
func (c Mailbox) List(name string) rev.Result {
|
||||||
title := fmt.Sprintf("Mailbox for %v", name)
|
|
||||||
|
|
||||||
ds := inbucket.NewDataStore()
|
ds := inbucket.NewDataStore()
|
||||||
mb, err := ds.MailboxFor(name)
|
mb, err := ds.MailboxFor(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -32,7 +29,7 @@ func (c Mailbox) List(name string) rev.Result {
|
|||||||
}
|
}
|
||||||
rev.INFO.Printf("Got %v messsages", len(messages))
|
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 {
|
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)
|
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")
|
||||||
|
}
|
||||||
|
|||||||
@@ -239,6 +239,15 @@ func (m *Message) Close() error {
|
|||||||
return m.createGob()
|
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,
|
// createGob reads the .raw file to grab the From and Subject header entries,
|
||||||
// then creates the .gob file.
|
// then creates the .gob file.
|
||||||
func (m *Message) createGob() error {
|
func (m *Message) createGob() error {
|
||||||
|
|||||||
72
app/views/Mailbox/Index.html
Normal file
72
app/views/Mailbox/Index.html
Normal 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" .}}
|
||||||
|
|
||||||
@@ -1,48 +1,12 @@
|
|||||||
{{template "header.html" .}}
|
|
||||||
{{$name := .name}}
|
{{$name := .name}}
|
||||||
<script>
|
{{range .messages}}
|
||||||
$(document).ready(function() {
|
<div class="box listEntry" id="{{.Id}}">
|
||||||
$('.listEntry').hover(
|
<div class="subject">{{/*<a href="/mailbox/show/{{$name}}/{{.Id}}">*/}}{{.Subject}}</div>
|
||||||
function() {
|
<div class="from">{{.From}}</div>
|
||||||
$(this).addClass("listEntryHover")
|
<div class="date">{{.Date}}</div>
|
||||||
},
|
|
||||||
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}}
|
|
||||||
</div>
|
</div>
|
||||||
|
{{else}}
|
||||||
<div id="colTwo">
|
<div class="box">
|
||||||
<div id="emailContent">
|
<p style="height: 30px; padding-left: 10px;">No messages!</p>
|
||||||
<p>Select a message at left, or enter a different username into the box on upper right.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
{{template "footer.html" .}}
|
|
||||||
|
|
||||||
|
|||||||
@@ -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">
|
<table id="emailHeader">
|
||||||
<tr>
|
<tr>
|
||||||
<th>From:</th>
|
<th>From:</th>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ GET /mailbox/{name} Mailbox.Index
|
|||||||
GET /mailbox Mailbox.Index
|
GET /mailbox Mailbox.Index
|
||||||
GET /mailbox/list/{name} Mailbox.List
|
GET /mailbox/list/{name} Mailbox.List
|
||||||
GET /mailbox/show/{name}/{id} Mailbox.Show
|
GET /mailbox/show/{name}/{id} Mailbox.Show
|
||||||
|
POST /mailbox/delete/{name}/{id} Mailbox.Delete
|
||||||
|
|
||||||
# Ignore favicon requests
|
# Ignore favicon requests
|
||||||
GET /favicon.ico 404
|
GET /favicon.ico 404
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ a:hover {
|
|||||||
|
|
||||||
#emailContent {
|
#emailContent {
|
||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
|
min-height: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#emailHeader {
|
#emailHeader {
|
||||||
@@ -285,3 +286,19 @@ a:hover {
|
|||||||
color: #000000;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user