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
end
delete '/' do
MailCatcher.quit!
status 204
end
get '/messages' do
if request.websocket?
request.websocket!(
@ -110,11 +115,6 @@ module MailCatcher
end
end
get '/quit' do
MailCatcher.quit!
status 204
end
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>"
end

View File

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

View File

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