docbrown/app/views/admin/profile_fields/_grouped_profile_fields.html.erb
Ridhwana 3474ffda6d
Profile Admin updates (#10133)
* feat: cater for when there are no profile fields in a group

* feat: add a modal to create a new group

* feat: add a controller and route for the group

* refactor: add group modal

* feat: edit a group

* chore: remove an instance var

* chore: toggle the section using a toggle button

* feat: add the edit button

* chore: update the messaging

* chore: update the class name

* feat: delete the group

* chore: add some css

* chore: use group_name

* chore: rename the file and add the group select to the file

* feat: render the correct partial and add the profile_field_group_id

* feat: add a profile field

* feat: amend the styles on the card header

* feat: add a cursor pointer

* feat: get the form to redirect after an update

* chore:  remove style

* feat: order by created at so that each time we save the order doesn't change

* fix: change the form

* chore: format the options

* feat: show ungrouped fields at the bottom

* feat: add the profile fields length

* chore: remove unused action

* test: add some specs for profile group workflow

* fix: oops

* refactor: grouped profile fields

* refactor: amend the styles

* chore: rename methods

* chore: update headings

* chore: remove changes from my linter

* refactor: suggestions by Michael - upgrade ternary

* refactor: order by name and label
2020-09-02 12:32:25 +02:00

52 lines
2.6 KiB
Text

<% @grouped_profile_fields.each do |group| %>
<% group_name = group.name.gsub(/\s+/, "_") %>
<article class="row my-3">
<div class="card w-100">
<div class="card-header">
<div class="card-header__information">
<div class="fw-bold fs-l"><%= group_name %></div>
<div class="fw-bold fs-s">&nbsp;(<%= group.profile_fields.length %>)</div>
<% if group.description %>
<div class="fs-s group__description"><%= group.description %></div>
<% end %>
</div>
<div class="card-header__actions">
<%= render partial: "add_profile_field_modal", locals: { group: group, group_name: group_name } %>
<%= render partial: "edit_group_modal", locals: { group: group, group_name: group_name } %>
<div><%= link_to "Delete Group", admin_profile_field_group_path(group), data: { confirm: "Are you sure?" }, method: :delete, class: "color-accent-danger" %></div>
<div id="<%= group_name %>Header" data-toggle="collapse" class="color-base-70"
data-target="#<%= group_name %>BodyContainer" aria-expanded="false" aria-controls="<%= group_name %>BodyContainer">Toggle</div>
</div>
</div>
<div id="<%= group_name %>BodyContainer" class="collapse hide p-3" aria-labelledby="<%= group_name %>Header">
<% if group.profile_fields.empty? %>
<div> There are no profile fields configured for this group. </div>
<% else %>
<% group.profile_fields.each do |field| %>
<div class="card mt-3">
<%= render partial: "admin/configs/card_header",
locals: {
header: field.label,
state: "collapse",
target: "#{field.attribute_name}_container",
expanded: "false"
} %>
<div id="<%= field.attribute_name %>_container" class="card-body collapse hide" aria-labelledby="<%= field.attribute_name %>_container">
<div class="form-group grid p-6 mb-6 gap-1">
<%= form_for [:admin, field] do |form| %>
<%= render "profile_field_form", form: form, group: group %>
<%= form.submit class: "btn btn-primary" %>
<% end %>
<%= button_to "Delete Profile Field", admin_profile_field_path(field), data: { confirm: "Are you sure?" }, method: :delete, class: "btn btn-secondary" %>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
</article>
<% end %>