Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 60 additions & 49 deletions app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,56 +102,7 @@

<div class="rounded-lg border border-gray-200 bg-gray-50 p-4 mb-4 shadow-sm">

<% org_earliest_aff = f.object.persisted? ? f.object.affiliations.minimum(:start_date) : nil %>
<% org_aff_ended = f.object.persisted? && f.object.affiliations.any? && !f.object.affiliations.active.exists? %>
<% org_latest_end = f.object.persisted? ? f.object.affiliations.maximum(:end_date) : nil %>
<% org_end_date = org_aff_ended ? org_latest_end : f.object.end_date %>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
<% if allowed_to?(:manage?, Organization) %>
<div class="">
<div class="shrink-0 relative group cursor-help">
<label class="inline-flex items-center gap-1 text-md font-medium text-gray-700 mb-1">
Affiliated since <i class="fa-solid fa-circle-info text-gray-400 text-xs"></i>
</label>
<div class="hidden group-hover:block absolute z-50 left-0 bottom-full mb-1 bg-blue-100 text-gray-700 text-xs rounded-lg shadow-lg ring-1 ring-blue-200 p-3 w-64 whitespace-normal">
<% if has_affiliations && org_earliest_aff.present? %>
<p>Auto-managed from affiliation records. Earliest affiliation start date: <%= org_earliest_aff.strftime('%b %Y') %>.</p>
<% if f.object.start_date.present? && f.object.start_date.beginning_of_month != org_earliest_aff.beginning_of_month %>
<p class="mt-2 text-gray-500"><i class="fa-solid fa-circle-info mr-1"></i>Organization start_date (<%= f.object.start_date.strftime('%b %Y') %>) differs from earliest affiliation.</p>
<% end %>
<% elsif has_affiliations %>
<p>Auto-managed from affiliation records.<br><br><span class="text-amber-700 font-medium">⚠ No affiliations have a start date. Add a start date to an affiliation record.</span></p>
<% else %>
<p>No affiliations yet. Set this date directly, or add affiliation records to auto-manage it.</p>
<% end %>
<% if org_aff_ended %>
<p class="mt-2 text-amber-700 font-medium">⚠ All affiliations have ended.</p>
<% elsif f.object.end_date.present? && !has_affiliations %>
<p class="mt-2 text-amber-700 font-medium">⚠ Organization end_date: <%= f.object.end_date.strftime('%b %Y') %>.</p>
<% end %>
</div>
<div class="pt-1">
<span class="text-gray-900 font-medium" data-affiliation-dates-target="affiliatedSince"><% if org_aff_ended || (f.object.end_date.present? && !has_affiliations) %><i class="fa-solid fa-circle-xmark text-red-400 mr-1" title="Affiliation ended"></i><% end %><%= (org_earliest_aff || f.object.start_date)&.strftime('%b %Y') || "—" %><%= " – #{org_end_date.strftime('%b %Y')}" if org_end_date.present? %></span>
<% if has_affiliations && org_earliest_aff.nil? %>
<i class="fa-solid fa-triangle-exclamation text-amber-500 ml-1"></i>
<% elsif f.object.start_date.present? && org_earliest_aff.present? && f.object.start_date.beginning_of_month != org_earliest_aff.beginning_of_month %>
<p class="text-xs text-gray-500 mt-1"><i class="fa-solid fa-circle-info mr-1"></i>Organization start_date: <%= f.object.start_date.strftime("%b %Y") %></p>
<% end %>
</div>
</div>
<% unless has_affiliations %>
<%= f.input :start_date,
label: false,
as: :string,
input_html: {
type: 'date',
value: f.object.start_date&.strftime('%Y-%m-%d'),
class: "block w-full rounded-md border-gray-300 shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-2"
} %>
<% end %>
</div>
<% end %>

<div class="flex flex-col">
<%= f.input :agency_type,
label: "Organization Type",
Expand Down Expand Up @@ -301,6 +252,66 @@
</div>

<div class="rounded-lg border border-gray-200 <%= DomainTheme.bg_class_for(:people) %> p-4 mb-4 shadow-sm">
<% org_earliest_aff = f.object.persisted? ? f.object.affiliations.minimum(:start_date) : nil %>
<% org_aff_ended = f.object.persisted? && f.object.affiliations.any? && !f.object.affiliations.active.exists? %>
<% org_latest_end = f.object.persisted? ? f.object.affiliations.maximum(:end_date) : nil %>
<% org_end_date = org_aff_ended ? org_latest_end : f.object.end_date %>
<% org_decorated = f.object.decorate %>
<% org_fac_start = org_decorated.facilitator_since_date %>
<% org_fac_ended = org_decorated.facilitation_end_date %>
<div class="flex flex-col md:flex-row gap-6 mb-4">
<div class="shrink-0 relative group cursor-help">
<label class="inline-flex items-center gap-1 text-md font-medium text-gray-700 mb-1">
Affiliated since <i class="fa-solid fa-circle-info text-gray-400 text-xs"></i>
</label>
<div class="hidden group-hover:block absolute z-50 left-0 bottom-full mb-1 bg-blue-100 text-gray-700 text-xs rounded-lg shadow-lg ring-1 ring-blue-200 p-3 w-64 whitespace-normal">
<% if has_affiliations && org_earliest_aff.present? %>
<p>Auto-managed from affiliation records. Earliest affiliation start date: <%= org_earliest_aff.strftime('%b %Y') %>.</p>
<% if f.object.start_date.present? && f.object.start_date.beginning_of_month != org_earliest_aff.beginning_of_month %>
<p class="mt-2 text-gray-500"><i class="fa-solid fa-circle-info mr-1"></i>Organization start_date (<%= f.object.start_date.strftime('%b %Y') %>) differs from earliest affiliation.</p>
<% end %>
<% elsif has_affiliations %>
<p>Auto-managed from affiliation records.<br><br><span class="text-amber-700 font-medium">⚠ No affiliations have a start date. Add a start date to an affiliation record.</span></p>
<% else %>
<p>No affiliations yet. Set this date directly, or add affiliation records to auto-manage it.</p>
<% end %>
<% if org_aff_ended %>
<p class="mt-2 text-amber-700 font-medium">⚠ All affiliations have ended.</p>
<% elsif f.object.end_date.present? && !has_affiliations %>
<p class="mt-2 text-amber-700 font-medium">⚠ Organization end_date: <%= f.object.end_date.strftime('%b %Y') %>.</p>
<% end %>
</div>
<div class="pt-1">
<span class="text-gray-900 font-medium" data-affiliation-dates-target="affiliatedSince"><% if org_aff_ended || (f.object.end_date.present? && !has_affiliations) %><i class="fa-solid fa-circle-xmark text-red-400 mr-1" title="Affiliation ended"></i><% end %><%= (org_earliest_aff || f.object.start_date)&.strftime('%b %Y') || "—" %><%= " – #{org_end_date.strftime('%b %Y')}" if org_end_date.present? %></span>
<% if has_affiliations && org_earliest_aff.nil? %>
<i class="fa-solid fa-triangle-exclamation text-amber-500 ml-1"></i>
<% elsif f.object.start_date.present? && org_earliest_aff.present? && f.object.start_date.beginning_of_month != org_earliest_aff.beginning_of_month %>
<p class="text-xs text-gray-500 mt-1"><i class="fa-solid fa-circle-info mr-1"></i>Organization start_date: <%= f.object.start_date.strftime("%b %Y") %></p>
<% end %>
</div>
<% unless has_affiliations %>
<%= f.input :start_date,
label: false,
as: :string,
input_html: {
type: 'date',
value: f.object.start_date&.strftime('%Y-%m-%d'),
class: "block w-full rounded-md border-gray-300 shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-2"
} %>
<% end %>
</div>
<div class="shrink-0 relative group cursor-help">
<label class="inline-flex items-center gap-1 text-md font-medium text-gray-700 mb-1">
Facilitator since <i class="fa-solid fa-circle-info text-gray-400 text-xs"></i>
</label>
<div class="hidden group-hover:block absolute z-50 left-0 bottom-full mb-1 bg-blue-100 text-gray-700 text-xs rounded-lg shadow-lg ring-1 ring-blue-200 p-3 w-64 whitespace-normal">
<p>Earliest start date from affiliations with 'Facilitator' in the title. Edit affiliation records to change this date.</p>
</div>
<div class="pt-1">
<span class="text-gray-900 font-medium" data-affiliation-dates-target="facilitatorSince"><% if org_fac_ended %><i class="fa-solid fa-circle-xmark text-red-400 mr-1" title="No active facilitator affiliations"></i><% end %><%= org_fac_start&.strftime("%b %Y") || "—" %><%= " – #{org_fac_ended.strftime('%b %Y')}" if org_fac_ended %></span>
</div>
</div>
</div>
<% if allowed_to?(:manage?, Organization) %>
<div class="admin-only bg-blue-100 p-3" data-controller="paginated-fields" data-paginated-fields-per-page-value="10" data-affiliation-dates-target="affiliationsContainer">
<%= f.fields_for :affiliations do |affiliation_form| %>
Expand Down
Loading