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

Version Path
hackathon_manager-0.14.1 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.14.0 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.12 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.11 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.10 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.9 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.8 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.7 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.6 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.5 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.4 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.3 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.2 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.1 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.13.0 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.12.2 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.12.1 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.12.0 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.11.2 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js
hackathon_manager-0.11.1 app/assets/javascripts/hackathon_manager/manage/lib/emailEvents.js