From b3a4e86a48b118a9e90811ee9be04e2aea3bb68d Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Tue, 30 Oct 2012 00:00:50 +0100 Subject: [PATCH] extracted unselectMessage --- public/javascripts/application.coffee | 14 ++++++++------ public/javascripts/application.js | 15 +++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/public/javascripts/application.coffee b/public/javascripts/application.coffee index 68297c6..0d9355d 100644 --- a/public/javascripts/application.coffee +++ b/public/javascripts/application.coffee @@ -42,9 +42,7 @@ class MailCatcher url: '/messages' type: 'DELETE' success: -> - $('#messages tbody, #message .metadata dd').empty() - $('#message .metadata .attachments').hide() - $('#message iframe').attr 'src', 'about:blank' + @unselectMessage() error: -> alert 'Error while quitting.' @@ -101,9 +99,7 @@ class MailCatcher if switchTo @loadMessage switchTo else - $('#message .metadata dd').empty() - $('#message .metadata .attachments').hide() - $('#message iframe').attr 'src', 'about:blank' + @unselectMessage() error: -> alert 'Error while removing message.' @@ -193,6 +189,12 @@ class MailCatcher if overflow > 0 $('#messages').scrollTop($('#messages').scrollTop() + overflow + 20) + unselectMessage: -> + $('#messages tbody, #message .metadata dd').empty() + $('#message .metadata .attachments').hide() + $('#message iframe').attr 'src', 'about:blank' + null + loadMessage: (id) -> id = id.id if id?.id? id ||= $('#messages tr.selected').attr 'data-message-id' diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 4678cbe..11f157a 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -62,9 +62,7 @@ url: '/messages', type: 'DELETE', success: function() { - $('#messages tbody, #message .metadata dd').empty(); - $('#message .metadata .attachments').hide(); - return $('#message iframe').attr('src', 'about:blank'); + return this.unselectMessage(); }, error: function() { return alert('Error while quitting.'); @@ -133,9 +131,7 @@ if (switchTo) { return _this.loadMessage(switchTo); } else { - $('#message .metadata dd').empty(); - $('#message .metadata .attachments').hide(); - return $('#message iframe').attr('src', 'about:blank'); + return _this.unselectMessage(); } }, error: function() { @@ -260,6 +256,13 @@ } }; + MailCatcher.prototype.unselectMessage = function() { + $('#messages tbody, #message .metadata dd').empty(); + $('#message .metadata .attachments').hide(); + $('#message iframe').attr('src', 'about:blank'); + return null; + }; + MailCatcher.prototype.loadMessage = function(id) { var messageRow, _this = this;