diff --git a/lib/mail_catcher/web.rb b/lib/mail_catcher/web.rb index 26af914..6206fb4 100644 --- a/lib/mail_catcher/web.rb +++ b/lib/mail_catcher/web.rb @@ -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 "

No Dice

The message you were looking for does not exist, or doesn't have content of this type.

" end diff --git a/public/javascripts/application.coffee b/public/javascripts/application.coffee index ddcd1b8..4fd4112 100644 --- a/public/javascripts/application.coffee +++ b/public/javascripts/application.coffee @@ -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() diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 5d85dfb..a42494b 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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();