<%= render partial: 'notice_dismissal/messages/13' %>
<%= form_for @timeline, html: { class: 'autosave-form timeline-meta-form' }, remote: true do |f| %>
<%= f.text_field :name, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :name, 'Timeline name' %>
<%= link_to '#', class: 'share hoverable btn right ' + Timeline.color do %> share <% end %>
<% end %>
<% @timeline.timeline_events.includes(:timeline_event_entities).each do |event| %>
<%= form_for event, html: { class: 'autosave-form' }, remote: true do |f| %> <%= f.hidden_field :timeline_id %>
<%= f.text_area :time_label, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :time_label, 'Time label' %>
  • Move this...
  • <%= link_to '#', class: 'js-move-event-to-top' do %> arrow_upward top <% end %>
  • <%= link_to '#', class: 'js-move-event-up' do %> keyboard_arrow_up up <% end %>
  • <%= link_to '#', class: 'js-move-event-down' do %> keyboard_arrow_down down <% end %>
  • <%= link_to '#', class: 'js-move-event-to-bottom' do %> arrow_downward bottom <% end %>
<%= image_tag 'graphics/timeline-line.webp' %>
<%= f.text_field :title, class: 'materialize-textarea js-trigger-autosave-on-change', id: "timeline-event-title-#{event.id}" %> <%= f.label :title, 'Event Title', for: "timeline-event-title-#{event.id}" %>
<%= f.text_area :description, class: 'materialize-textarea js-trigger-autosave-on-change', id: "timeline-event-description-#{event.id}" %> <%= f.label :description, for: "timeline-event-description-#{event.id}" %>
<%= f.text_area :notes, class: 'materialize-textarea js-trigger-autosave-on-change', id: "timeline-event-notes-#{event.id}" %> <%= f.label :notes, for: "timeline-event-notes-#{event.id}" %>
<%= link_to timeline_event_path(event), class: 'red-text', method: :delete, data: { confirm: "Are you sure you want to delete this event? It cannot be recovered!" } do %> Delete this event <% end %>
In this event
    <% event.timeline_event_entities.order('entity_type').preload(:entity).group_by(&:entity_type).each do |entity_type, entity_list| %> <% entity_list.reject! { |te_entity| te_entity.entity.nil? } %>
  • <% klass = content_class_from_name(entity_type) %>
    <%= klass.icon %> <%= entity_type.pluralize %> <%= entity_list.count %>
    <% entity_list.each do |te_entity| %>
    <%= link_to(te_entity.entity.name.presence || "Untitled #{te_entity.entity_type}", te_entity.entity) %> <%= link_to unlink_entity_timeline_event_path(id: event.id, entity_id: te_entity.id), method: :POST, remote: true do %> close <% end %>
    <% end %>
  • <% end %>

<%= link_to 'Link a page', '#', class: 'js-link-entity' %>

<% end %>
<% end %>
<% event = TimelineEvent.new %>
<%# we have to do method: :patch in the template since event isn't persisted; we don't want it to POST instead %> <%= form_for event, html: { class: 'autosave-form' }, remote: true, method: :patch do |f| %> <%= f.hidden_field :timeline_id, value: @timeline.id %>
<%= f.text_area :time_label, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :time_label, 'Time label' %>
  • Move this...
  • <%= link_to '#', class: 'js-move-event-to-top' do %> arrow_upward top <% end %>
  • <%= link_to '#', class: 'js-move-event-up' do %> keyboard_arrow_up up <% end %>
  • <%= link_to '#', class: 'js-move-event-down' do %> keyboard_arrow_down down <% end %>
  • <%= link_to '#', class: 'js-move-event-to-bottom' do %> arrow_downward bottom <% end %>
<%= image_tag 'graphics/timeline-line.webp' %>
<%= f.text_field :title, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :title, 'Event Title', for: "timeline-event-title-[[tid]]" %>
<%= f.text_area :description, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :description %>
<%= f.text_area :notes, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :notes %>
<%= link_to timeline_event_path(id: event.id || 0), class: 'js-delete-timeline-event red-text', method: :delete, data: { confirm: "Are you sure you want to delete this event? It cannot be recovered!" } do %> Delete this event <% end %>
In this event
    <% event.timeline_event_entities.order('entity_type').preload(:entity).group_by(&:entity_type).each do |entity_type, entity_list| %>
  • <% klass = content_class_from_name(entity_type) %>
    <%= klass.icon %> <%= entity_type.pluralize %> <%= entity_list.count %>
    <% entity_list.each do |te_entity| %>
    <%= link_to("test", te_entity.entity) %> <%= link_to unlink_entity_timeline_event_path(id: event.id, entity_id: te_entity.id), method: :POST, remote: true do %> close <% end %>
    <% end %>
  • <% end %>

<%= link_to 'Link a page', '#', class: 'js-link-entity' %>

<% end %>
<%= link_to 'Add an event', '#', class: 'btn black white-text', id: 'js-create-timeline-event' %>
<%= render partial: 'content/share', locals: { shared_content: @timeline } %> <%= content_for :javascript do %> $('.js-link-entity').click(function () { // Store the linking event ID for reference var event_id = $(this).closest('.timeline-event-container').data('event-id'); $('#linking-event-id').val(event_id); // Open the modal $('#entity-link-modal').modal('open'); return false; }); $('.js-link-entity-selection').click(function () { var entity = $(this); var entity_type = entity.data('type'); var entity_id = entity.data('id'); var event_id = $('#linking-event-id').val(); $.post( "/plan/timeline_events/" + event_id + "/link", { "entity_type": entity_type, "entity_id": entity_id } ).done(function () { // todo update the UI somehow M.toast({ html: 'Your ' + entity_type + ' was added successfully and will be visible the next time you reload this page.' }); $('.modal').close(); return false; }).fail(function() { alert("Something went wrong and your change didn't save. Please try again."); }); // todo close the modal }); <% end %>