mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-12-22 07:18:53 -05:00
Add search and clearSearch methods to CoffeeScript
This commit is contained in:
parent
c8090609e5
commit
aa4a51fb6d
@ -4,6 +4,14 @@ class MailCatcher
|
||||
e.preventDefault()
|
||||
@loadMessage $(e.currentTarget).attr 'data-message-id'
|
||||
|
||||
$('input[name=search]').live 'keyup', (e) =>
|
||||
e.preventDefault()
|
||||
console.log(e)
|
||||
if e.currentTarget.value == ""
|
||||
@clearSearch()
|
||||
else
|
||||
@searchMessages e.currentTarget.value
|
||||
|
||||
$('#message .views .format.tab a').live 'click', (e) =>
|
||||
e.preventDefault()
|
||||
@loadMessageBody @selectedMessage(), $($(e.currentTarget).parent('li')).data 'message-format'
|
||||
@ -74,6 +82,13 @@ class MailCatcher
|
||||
selectedMessage: ->
|
||||
$('#messages tr.selected').data 'message-id'
|
||||
|
||||
searchMessages: (term) ->
|
||||
$('#messages tbody tr:not(:contains("' + term + '"))').hide()
|
||||
$('#messages tbody tr(:contains("' + term + '"))').show()
|
||||
|
||||
clearSearch: ->
|
||||
$('#messages tbody tr').show()
|
||||
|
||||
addMessage: (message) ->
|
||||
$('#messages tbody').append \
|
||||
$('<tr />').attr('data-message-id', message.id.toString())
|
||||
|
@ -9,6 +9,15 @@
|
||||
e.preventDefault();
|
||||
return _this.loadMessage($(e.currentTarget).attr('data-message-id'));
|
||||
});
|
||||
$('input[name=search]').live('keyup', function(e) {
|
||||
e.preventDefault();
|
||||
console.log(e);
|
||||
if (e.currentTarget.value === "") {
|
||||
return _this.clearSearch();
|
||||
} else {
|
||||
return _this.searchMessages(e.currentTarget.value);
|
||||
}
|
||||
});
|
||||
$('#message .views .format.tab a').live('click', function(e) {
|
||||
e.preventDefault();
|
||||
return _this.loadMessageBody(_this.selectedMessage(), $($(e.currentTarget).parent('li')).data('message-format'));
|
||||
@ -101,6 +110,15 @@
|
||||
return $('#messages tr.selected').data('message-id');
|
||||
};
|
||||
|
||||
MailCatcher.prototype.searchMessages = function(term) {
|
||||
$('#messages tbody tr:not(:contains("' + term + '"))').hide();
|
||||
return $('#messages tbody tr(:contains("' + term + '"))').show();
|
||||
};
|
||||
|
||||
MailCatcher.prototype.clearSearch = function() {
|
||||
return $('#messages tbody tr').show();
|
||||
};
|
||||
|
||||
MailCatcher.prototype.addMessage = function(message) {
|
||||
return $('#messages tbody').append($('<tr />').attr('data-message-id', message.id.toString()).append($('<td/>').text(message.sender || "No sender").toggleClass("blank", !message.sender)).append($('<td/>').text((message.recipients || []).join(', ') || "No receipients").toggleClass("blank", !message.recipients.length)).append($('<td/>').text(message.subject || "No subject").toggleClass("blank", !message.subject)).append($('<td/>').text(this.formatDate(message.created_at))));
|
||||
};
|
||||
@ -196,8 +214,8 @@
|
||||
};
|
||||
|
||||
MailCatcher.prototype.subscribeWebSocket = function() {
|
||||
var secure;
|
||||
var _this = this;
|
||||
var secure,
|
||||
_this = this;
|
||||
secure = window.location.scheme === 'https';
|
||||
this.websocket = new WebSocket("" + (secure ? 'wss' : 'ws') + "://" + window.location.host + "/messages");
|
||||
return this.websocket.onmessage = function(event) {
|
||||
|
Loading…
Reference in New Issue
Block a user