Sha256: fee94c86e9609ec6e38fc6c6345dcbd91d00d4560085117096a1c8df25b27b96
Contents?: true
Size: 1.41 KB
Versions: 41
Compression:
Stored size: 1.41 KB
Contents
$(document).ready(function() { $('.email-events').each(function() { var events_container = this; $(events_container).html('<span class="fa fa-circle-o-notch fa-spin"></span>'); var data_url = $(events_container).data('url'); $.ajax(data_url) .done(function(json) { if (!json.length) { $(events_container).html('<em>No events found.</em>'); return; } const reducer = function(accumulator, event) { const key = event.message_id; if (key in accumulator === false) { accumulator[key] = []; } accumulator[key].push(event); return accumulator; }; const groupedEvents = json.reduce(reducer, {}); const innerHtml = Object.keys(groupedEvents).map(function(key) { const group = groupedEvents[key]; const groupHtml = group.map(function(event) { const timestamp = new Date(event.timestamp); return '<br /><small>' + event.type + ' at ' + timestamp.toLocaleString() + '</small>'; }).join(''); return '<li><p><strong>' + group[0].subject + '</strong>' + groupHtml + '</li>'; }).join(''); const newHtml = '<ul>' + innerHtml + '</ul>'; $(events_container).html(newHtml); }) .fail(function() { $(events_container).html('<em>An error ocurred. Please try again later.</em>'); }); }); });
Version data entries
41 entries across 41 versions & 1 rubygems