extracted unselectMessage

This commit is contained in:
Ivan Kuchin 2012-10-30 00:00:50 +01:00
parent 2e35d0cc9d
commit b3a4e86a48
2 changed files with 17 additions and 12 deletions

View File

@ -42,9 +42,7 @@ class MailCatcher
url: '/messages' url: '/messages'
type: 'DELETE' type: 'DELETE'
success: -> success: ->
$('#messages tbody, #message .metadata dd').empty() @unselectMessage()
$('#message .metadata .attachments').hide()
$('#message iframe').attr 'src', 'about:blank'
error: -> error: ->
alert 'Error while quitting.' alert 'Error while quitting.'
@ -101,9 +99,7 @@ class MailCatcher
if switchTo if switchTo
@loadMessage switchTo @loadMessage switchTo
else else
$('#message .metadata dd').empty() @unselectMessage()
$('#message .metadata .attachments').hide()
$('#message iframe').attr 'src', 'about:blank'
error: -> error: ->
alert 'Error while removing message.' alert 'Error while removing message.'
@ -193,6 +189,12 @@ class MailCatcher
if overflow > 0 if overflow > 0
$('#messages').scrollTop($('#messages').scrollTop() + overflow + 20) $('#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) -> loadMessage: (id) ->
id = id.id if id?.id? id = id.id if id?.id?
id ||= $('#messages tr.selected').attr 'data-message-id' id ||= $('#messages tr.selected').attr 'data-message-id'

View File

@ -62,9 +62,7 @@
url: '/messages', url: '/messages',
type: 'DELETE', type: 'DELETE',
success: function() { success: function() {
$('#messages tbody, #message .metadata dd').empty(); return this.unselectMessage();
$('#message .metadata .attachments').hide();
return $('#message iframe').attr('src', 'about:blank');
}, },
error: function() { error: function() {
return alert('Error while quitting.'); return alert('Error while quitting.');
@ -133,9 +131,7 @@
if (switchTo) { if (switchTo) {
return _this.loadMessage(switchTo); return _this.loadMessage(switchTo);
} else { } else {
$('#message .metadata dd').empty(); return _this.unselectMessage();
$('#message .metadata .attachments').hide();
return $('#message iframe').attr('src', 'about:blank');
} }
}, },
error: function() { 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) { MailCatcher.prototype.loadMessage = function(id) {
var messageRow, var messageRow,
_this = this; _this = this;