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
59 changes: 17 additions & 42 deletions app/views/administrate/application/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,23 @@ and renders all form fields for a resource's editable attributes.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
%>
<%# locals: (page:) %>

<%= form_with(model: page.resource, url: [namespace, page.resource], scope: page.resource, local: true, class: "form") do |f| %>
<% if page.resource.errors.any? %>
<div id="error_explanation">
<h2>
<%= t(
"administrate.form.errors",
pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")),
resource_name: display_resource_name(page.resource_name, singular: true)
) %>
</h2>

<ul>
<% page.resource.errors.full_messages.each do |message| %>
<li class="flash-error"><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<% page.attributes(controller.action_name).each do |title, attributes| -%>
<fieldset class="<%= "field-unit--nested" if title.present? %>">
<% if title.present? %>
<legend><%= t "helpers.label.#{f.object_name}.#{title}", default: title %></legend>
<% end %>

<% attributes.each do |attribute| %>
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
<%= render_field attribute, f: f %>

<% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %>
<% if I18n.exists?(hint_key) -%>
<div class="field-unit__hint">
<%= I18n.t(hint_key) %>
</div>
<% end -%>
</div>
<% end %>
</fieldset>
<% end -%>

<div class="form-actions">
<%= f.submit %>
</div>

<%= render "form_errors", page: page, f: f %>

<%= render(
partial: "form_group",
layout: "form_group_layout",
collection: page.attributes(controller.action_name).to_a,
as: :form_group,
locals: {
page: page,
f: f,
}
) %>

<%= render "form_actions", page: page, f: f %>

<% end %>
5 changes: 5 additions & 0 deletions app/views/administrate/application/_form_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# locals: (page:, f:) %>

<div class="form-actions">
<%= f.submit %>
</div>
18 changes: 18 additions & 0 deletions app/views/administrate/application/_form_errors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%# locals: (page:, f:) %>
<% return if page.resource.errors.empty? %>

<div id="error_explanation">
<h2>
<%= t(
"administrate.form.errors",
pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")),
resource_name: display_resource_name(page.resource_name, singular: true)
) %>
</h2>

<ul>
<% page.resource.errors.full_messages.each do |message| %>
<li class="flash-error"><%= message %></li>
<% end %>
</ul>
</div>
14 changes: 14 additions & 0 deletions app/views/administrate/application/_form_group.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%# locals: (page:, f:, form_group:, form_group_counter: nil, form_group_iteration: nil) %>
<% attributes = form_group.second %>

<%= render(
partial: "form_item",
layout: "form_item_layout",
collection: attributes,
as: :attribute,
locals: {
page: page,
f: f,
form_group: form_group,
}
) %>
17 changes: 17 additions & 0 deletions app/views/administrate/application/_form_group_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# locals: (page:, f:, form_group:, form_group_counter: nil, form_group_iteration: nil) %>
<% group_title = form_group.first %>

<% if group_title.present? %>
<%# grouped attributes: { title => attributes } %>
<fieldset class="field-unit--nested">
<legend><%= t "helpers.label.#{page.resource_name}.#{group_title}", default: group_title %></legend>
<dl>
<%= yield %>
</dl>
</fieldset>
<% else %>
<%# non-grouped attributes: { "" => attributes } %>
<dl>
<%= yield %>
</dl>
<% end %>
3 changes: 3 additions & 0 deletions app/views/administrate/application/_form_item.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%# locals: (page:, f:, form_group:, attribute:, attribute_counter: nil, attribute_iteration: nil) %>

<%= render_field attribute, f: f %>
8 changes: 8 additions & 0 deletions app/views/administrate/application/_form_item_hint.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%# locals: (page:, f:, form_group:, attribute:) %>

<% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %>
<% if I18n.exists?(hint_key) -%>
<div class="field-unit__hint">
<%= I18n.t(hint_key) %>
</div>
<% end -%>
6 changes: 6 additions & 0 deletions app/views/administrate/application/_form_item_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%# locals: (page:, f:, form_group:, attribute:, attribute_counter: nil, attribute_iteration: nil) %>

<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
<%= yield %>
<%= render "form_item_hint", page: page, f: f, form_group: form_group, attribute: attribute %>
</div>
Loading