Quit via "DELETE /" - this seems more elegant, somehow.

This commit is contained in:
Samuel Cochran 2011-06-01 01:14:56 +08:00
parent 803a569ac8
commit 06f2238ef3
3 changed files with 24 additions and 13 deletions

View File

@ -17,6 +17,11 @@ module MailCatcher
haml :index haml :index
end end
delete '/' do
MailCatcher.quit!
status 204
end
get '/messages' do get '/messages' do
if request.websocket? if request.websocket?
request.websocket!( request.websocket!(
@ -110,11 +115,6 @@ module MailCatcher
end end
end end
get '/quit' do
MailCatcher.quit!
status 204
end
not_found do not_found do
"<html><body><h1>No Dice</h1><p>The message you were looking for does not exist, or doesn't have content of this type.</p></body></html>" "<html><body><h1>No Dice</h1><p>The message you were looking for does not exist, or doesn't have content of this type.</p></body></html>"
end end

View File

@ -7,9 +7,13 @@ class MailCatcher
@loadMessageBody $('#messages tr.selected').attr('data-message-id'), $(e.currentTarget).attr 'data-message-format' @loadMessageBody $('#messages tr.selected').attr('data-message-id'), $(e.currentTarget).attr 'data-message-format'
$('nav.app .quit a').live 'click', (e) => $('nav.app .quit a').live 'click', (e) =>
if confirm "You will lose all your received messages.\n\nAre you sure you want to click?" if confirm "You will lose all your received messages.\n\nAre you sure you want to quit?"
$.get '/quit' $.ajax
type: 'DELETE'
success: ->
location.replace $('body > header h1 a').attr('href') location.replace $('body > header h1 a').attr('href')
error: ->
alert 'Error while quitting.'
@refresh() @refresh()
@subscribe() @subscribe()

View File

@ -10,9 +10,16 @@
return this.loadMessageBody($('#messages tr.selected').attr('data-message-id'), $(e.currentTarget).attr('data-message-format')); return this.loadMessageBody($('#messages tr.selected').attr('data-message-id'), $(e.currentTarget).attr('data-message-format'));
}, this)); }, this));
$('nav.app .quit a').live('click', __bind(function(e) { $('nav.app .quit a').live('click', __bind(function(e) {
if (confirm("You will lose all your received messages.\n\nAre you sure you want to click?")) { if (confirm("You will lose all your received messages.\n\nAre you sure you want to quit?")) {
$.get('/quit'); return $.ajax({
type: 'DELETE',
success: function() {
return location.replace($('body > header h1 a').attr('href')); return location.replace($('body > header h1 a').attr('href'));
},
error: function() {
return alert('Error while quitting.');
}
});
} }
}, this)); }, this));
this.refresh(); this.refresh();