Simplify getting imageable/documentable in forms

The imageable/documentable object is always the object the form builder
is based on; since we're already passing the form builder, we don't have
to pass the object as well.

The only exception are the poll answers. In this case, we're passing a
new answer as the object. That's OK; the same hack that we're using to
send the data to the answer URL without displaying existing attachments
causes the form to keep working the same way.
This commit is contained in:
Javi Martín
2021-07-11 20:45:57 +02:00
parent ac495e7523
commit 629df5ab9b
14 changed files with 20 additions and 17 deletions

View File

@@ -57,7 +57,7 @@
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "images/nested_image", imageable: @phase, f: f %>
<%= render "images/nested_image", f: f %>
<p class="help-text"><%= t("admin.budget_phases.edit.image_description") %></p>
</div>
<% end %>

View File

@@ -41,7 +41,7 @@
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "/images/nested_image", imageable: budget, f: f %>
<%= render "/images/nested_image", f: f %>
<p class="help-text"><%= t("admin.budgets.edit.image_description") %></p>
</div>
<% end %>

View File

@@ -38,13 +38,13 @@
<% if feature?(:allow_images) %>
<div class="images">
<%= render "images/nested_image", imageable: investment, f: f %>
<%= render "images/nested_image", f: f %>
</div>
<% end %>
<% if feature?(:allow_attached_documents) %>
<div class="documents">
<%= render "documents/nested_documents", documentable: investment, f: f %>
<%= render "documents/nested_documents", f: f %>
</div>
<% end %>

View File

@@ -39,13 +39,13 @@
<% if feature?(:allow_images) %>
<div class="images">
<%= render "images/nested_image", imageable: proposal, f: f %>
<%= render "images/nested_image", f: f %>
</div>
<% end %>
<% if feature?(:allow_attached_documents) %>
<div class="documents">
<%= render "documents/nested_documents", documentable: proposal, f: f %>
<%= render "documents/nested_documents", f: f %>
</div>
<% end %>

View File

@@ -62,7 +62,7 @@
<% if feature?(:allow_attached_documents) %>
<div class="documents small-12 column">
<hr>
<%= render "documents/nested_documents", documentable: dashboard_action, f: f %>
<%= render "documents/nested_documents", f: f %>
<hr>
</div>
<% end %>

View File

@@ -110,7 +110,7 @@
<div class="row">
<div class="documents small-12 column">
<%= render "documents/nested_documents", documentable: @process, f: f %>
<%= render "documents/nested_documents", f: f %>
</div>
<div class="small-12 column">
@@ -118,7 +118,7 @@
</div>
<div class="images small-12 column">
<%= render "images/nested_image", imageable: @process, f: f %>
<%= render "images/nested_image", f: f %>
</div>
<div class="small-12 column">

View File

@@ -27,10 +27,10 @@
<div class="column">
<%= f.date_field :publication_date %>
<%= render "images/nested_image", imageable: @milestone, f: f %>
<%= render "images/nested_image", f: f %>
<div class="documents">
<%= render "documents/nested_documents", documentable: @milestone, f: f %>
<%= render "documents/nested_documents", f: f %>
</div>
<%= f.submit nil, class: "button success" %>

View File

@@ -33,7 +33,7 @@
<div class="row">
<div class="images small-12 column">
<%= render "images/nested_image", imageable: @poll, f: f %>
<%= render "images/nested_image", f: f %>
</div>
<div class="clear">

View File

@@ -15,7 +15,7 @@
<%= render "shared/errors", resource: @answer %>
<div class="documents">
<%= render "documents/nested_documents", documentable: @answer, f: f %>
<%= render "documents/nested_documents", f: f %>
</div>
<div class="small-12 medium-6 large-2">

View File

@@ -5,7 +5,7 @@
<%= render "shared/errors", resource: @answer %>
<div class="images">
<%= render "images/nested_image", imageable: @answer, f: f, image_fields: :images %>
<%= render "images/nested_image", f: f, image_fields: :images %>
</div>
<%= f.submit t("admin.questions.answers.images.save_image"), class: "button success" %>

View File

@@ -45,7 +45,7 @@
<div class="row">
<div class="image-form">
<div class="image small-12 column">
<%= render "images/nested_image", imageable: card, f: f %>
<%= render "images/nested_image", f: f %>
</div>
</div>
<div class="column">

View File

@@ -1,3 +1,5 @@
<% documentable = f.object %>
<div class="documents-list">
<%= f.label :documents, t("documents.form.title") %>
<p class="help-text"><%= documentables_note(documentable) %></p>

View File

@@ -1,4 +1,5 @@
<% image_fields ||= :image %>
<% imageable = f.object %>
<%= f.label image_fields, t("images.form.title") %>
<p class="help-text"><%= imageables_note(imageable) %></p>

View File

@@ -28,12 +28,12 @@
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "images/nested_image", imageable: @proposal, f: f %>
<%= render "images/nested_image", f: f %>
</div>
<% end %>
<div class="documents small-12 column" data-max-documents="<%= Legislation::Proposal.max_documents_allowed %>">
<%= render "documents/nested_documents", documentable: @proposal, f: f %>
<%= render "documents/nested_documents", f: f %>
</div>
<div class="small-12 medium-6 column">