<%# Card activities %>
<% if activity.trackable_type == 'Card' %>
  <%# See comment above re: activity.trackable.nil? %>
  <% if activity.action == 'destroy' || activity.trackable.nil? %>
    ActivitiesPoller.deleteCard(<%= activity.trackable_id %>)
  <% else %>
    <% card = activity.trackable %>
    <%# @board and @list must be initialized for the partial to work: %>
    <% @board = card.board; @list = card.list %>
    var template = '<%= j render(card) %>';
    var cardId   = <%= card.id %>;
    var listId   = <%= card.list.id %>;
    var boardId  = <%= card.board.id %>;
    var listName = '<%= card.list.name %>';
    var cardPath = '<%= project_board_list_card_path(current_project, card.board, card.list, card) %>';

    <% if activity.action == 'create' %>
      ActivitiesPoller.addCard(listId, boardId, template)
    <% elsif activity.action == 'update' %>
      ActivitiesPoller.updateCard(cardId, listId, boardId, template)
    <% end %>
  <% end %>
<% end # if activity.trackable_type == "Card" %>

<%# List activities %>
<% if activity.trackable_type == 'List' %>
  <%# See comment above re: activity.trackable.nil? %>
  <% if activity.action == 'destroy' || activity.trackable.nil? %>
    ActivitiesPoller.deleteList(<%= activity.trackable_id %>)
  <% elsif activity.action == 'update' %>
    <% list = activity.trackable %>
    ActivitiesPoller.updateList(<%= list.id %>, <%= list.board.id %>, '<%= list.name %>')
  <% elsif activity.action == 'create' %>
    <% list = activity.trackable %>
    ActivitiesPoller.addList(<%= list.id %>, <%= list.board.id %>)
  <% end %>
<% end # if activity.trackable_type == "List" %>

<%# Board activities %>
<% if activity.trackable_type == 'Board' %>
  <%# See comment above re: activity.trackable.nil? %>
  <% if activity.action == 'destroy' || activity.trackable.nil? %>
    ActivitiesPoller.deleteBoard(<%= activity.trackable_id %>)
  <% elsif activity.action == 'update' %>
    <% board = activity.trackable %>
    ActivitiesPoller.updateBoard(<%= board.id %>, '<%= board.name %>')
  <% elsif activity.action == 'create' %>
    <% board = activity.trackable %>
    ActivitiesPoller.addBoard(<%= board.id %>)
  <% end %>
<% end # if activity.trackable_type == "Board" %>
