mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-12-22 15:28:52 -05:00
Fix download button
This commit is contained in:
parent
559452ecc1
commit
e22d6766e3
@ -5,10 +5,10 @@ class MailCatcher
|
||||
|
||||
$('#message .views .tab').live 'click', (e) =>
|
||||
@loadMessageBody $('#messages tr.selected').attr('data-message-id'), $(e.currentTarget).attr 'data-message-format'
|
||||
|
||||
|
||||
$('nav.app .clear a').live 'click', (e) =>
|
||||
if confirm "You will lose all your received messages.\n\nAre you sure you want to clear all messages?"
|
||||
$.ajax
|
||||
$.ajax
|
||||
url: '/messages'
|
||||
type: 'DELETE'
|
||||
success: ->
|
||||
@ -26,17 +26,17 @@ class MailCatcher
|
||||
location.replace $('body > header h1 a').attr('href')
|
||||
error: ->
|
||||
alert 'Error while quitting.'
|
||||
|
||||
|
||||
@refresh()
|
||||
@subscribe()
|
||||
|
||||
|
||||
# Only here because Safari's Date parsing *sucks*
|
||||
# We throw away the timezone, but you could use it for something...
|
||||
parseDateRegexp: /^(\d{4})[-\/\\](\d{2})[-\/\\](\d{2})(?:\s+|T)(\d{2})[:-](\d{2})[:-](\d{2})(?:([ +-]\d{2}:\d{2}|\s*\S+|Z?))?$/
|
||||
parseDate: (date) ->
|
||||
if match = @parseDateRegexp.exec(date)
|
||||
new Date match[1], match[2], match[3], match[4], match[5], match[6], 0
|
||||
|
||||
|
||||
formatDate: (date) ->
|
||||
date &&= @parseDate(date) if typeof(date) == "string"
|
||||
date &&= date.toString("dddd, d MMM yyyy h:mm:ss tt")
|
||||
@ -44,7 +44,7 @@ class MailCatcher
|
||||
haveMessage: (message) ->
|
||||
message = message.id if message.id?
|
||||
$("#messages tbody tr[data-message-id=\"#{message}\"]").length > 0
|
||||
|
||||
|
||||
addMessage: (message) ->
|
||||
$('#messages tbody').append \
|
||||
$('<tr />').attr('data-message-id', message.id.toString())
|
||||
@ -52,15 +52,15 @@ class MailCatcher
|
||||
.append($('<td/>').text((message.recipients || []).join(', ')))
|
||||
.append($('<td/>').text(message.subject))
|
||||
.append($('<td/>').text @formatDate message.created_at)
|
||||
|
||||
|
||||
loadMessage: (id) ->
|
||||
id = id.id if id?.id?
|
||||
id ||= $('#messages tr.selected').attr 'data-message-id'
|
||||
|
||||
|
||||
if id?
|
||||
$('#messages tbody tr:not([data-message-id="'+id+'"])').removeClass 'selected'
|
||||
$('#messages tbody tr[data-message-id="'+id+'"]').addClass 'selected'
|
||||
|
||||
|
||||
$.getJSON '/messages/' + id + '.json', (message) =>
|
||||
$('#message .metadata dd.created_at').text @formatDate message.created_at
|
||||
$('#message .metadata dd.from').text message.sender
|
||||
@ -73,11 +73,11 @@ class MailCatcher
|
||||
$el.show()
|
||||
else
|
||||
$el.hide()
|
||||
|
||||
|
||||
if $("#message .views .tab.selected:not(:visible)").length
|
||||
$("#message .views .tab.selected").removeClass "selected"
|
||||
$("#message .views .tab:visible:first").addClass "selected"
|
||||
|
||||
|
||||
if message.attachments.length
|
||||
$('#message .metadata dd.attachments ul').empty()
|
||||
$.each message.attachments, (i, attachment) ->
|
||||
@ -85,22 +85,22 @@ class MailCatcher
|
||||
$('#message .metadata .attachments').show()
|
||||
else
|
||||
$('#message .metadata .attachments').hide()
|
||||
|
||||
$('#message .actions .download a').attr 'href', "/messages/#{id}.eml"
|
||||
|
||||
|
||||
$('#message .views .download a').attr 'href', "/messages/#{id}.eml"
|
||||
|
||||
@loadMessageBody()
|
||||
|
||||
loadMessageBody: (id, format) ->
|
||||
id ||= $('#messages tr.selected').attr 'data-message-id'
|
||||
format ||= $('#message .views .tab.format.selected').attr 'data-message-format'
|
||||
format ||= 'html'
|
||||
|
||||
|
||||
$("#message .views .tab[data-message-format=\"#{format}\"]:not(.selected)").addClass 'selected'
|
||||
$("#message .views .tab:not([data-message-format=\"#{format}\"]).selected").removeClass 'selected'
|
||||
|
||||
|
||||
if id?
|
||||
$('#message iframe').attr "src", "/messages/#{id}.#{format}"
|
||||
|
||||
|
||||
refresh: ->
|
||||
$.getJSON '/messages', (messages) =>
|
||||
$.each messages, (i, message) =>
|
||||
@ -124,4 +124,4 @@ class MailCatcher
|
||||
@refreshInterval = setInterval (=> @refresh()), 1000
|
||||
|
||||
|
||||
$ -> window.MailCatcher = new MailCatcher
|
||||
$ -> window.MailCatcher = new MailCatcher
|
||||
|
@ -99,7 +99,7 @@
|
||||
} else {
|
||||
$('#message .metadata .attachments').hide();
|
||||
}
|
||||
$('#message .actions .download a').attr('href', "/messages/" + id + ".eml");
|
||||
$('#message .views .download a').attr('href', "/messages/" + id + ".eml");
|
||||
return this.loadMessageBody();
|
||||
}, this));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user