Simplify method names in image/document fields
We were using long, unique names because these methods used to be helper methods. Helper methods should have unique names because otherwise one method would overwrite the other. Now that we're using components, we can omit the `image_` and `document_` prefixes.
This commit is contained in:
@@ -9,15 +9,15 @@
|
|||||||
|
|
||||||
<div class="small-12 column attachment-actions">
|
<div class="small-12 column attachment-actions">
|
||||||
<div class="small-9 column action-add attachment-errors document-attachment">
|
<div class="small-9 column action-add attachment-errors document-attachment">
|
||||||
<%= render_attachment %>
|
<%= file_field %>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 column action-remove text-right">
|
<div class="small-3 column action-remove text-right">
|
||||||
<%= render_destroy_document_link %>
|
<%= destroy_link %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-6 column">
|
<div class="small-6 column">
|
||||||
<p class="file-name"><%= document_attachment_file_name %></p>
|
<p class="file-name"><%= file_name %></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ class Documents::FieldsComponent < ApplicationComponent
|
|||||||
f.object
|
f.object
|
||||||
end
|
end
|
||||||
|
|
||||||
def document_attachment_file_name
|
def file_name
|
||||||
document.attachment_file_name
|
document.attachment_file_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_destroy_document_link
|
def destroy_link
|
||||||
if !document.persisted? && document.cached_attachment.present?
|
if !document.persisted? && document.cached_attachment.present?
|
||||||
link_to t("documents.form.delete_button"),
|
link_to t("documents.form.delete_button"),
|
||||||
direct_upload_destroy_path(
|
direct_upload_destroy_path(
|
||||||
@@ -33,19 +33,19 @@ class Documents::FieldsComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_attachment
|
def file_field
|
||||||
klass = document.persisted? || document.cached_attachment.present? ? " hide" : ""
|
klass = document.persisted? || document.cached_attachment.present? ? " hide" : ""
|
||||||
f.file_field :attachment,
|
f.file_field :attachment,
|
||||||
label_options: { class: "button hollow #{klass}" },
|
label_options: { class: "button hollow #{klass}" },
|
||||||
accept: accepted_content_types_extensions,
|
accept: accepted_content_types_extensions,
|
||||||
class: "js-document-attachment",
|
class: "js-document-attachment",
|
||||||
data: {
|
data: {
|
||||||
url: document_direct_upload_path,
|
url: direct_upload_path,
|
||||||
nested_document: true
|
nested_document: true
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def document_direct_upload_path
|
def direct_upload_path
|
||||||
direct_uploads_path("direct_upload[resource_type]": document.documentable_type,
|
direct_uploads_path("direct_upload[resource_type]": document.documentable_type,
|
||||||
"direct_upload[resource_id]": document.documentable_id,
|
"direct_upload[resource_id]": document.documentable_id,
|
||||||
"direct_upload[resource_relation]": "documents")
|
"direct_upload[resource_relation]": "documents")
|
||||||
|
|||||||
@@ -11,15 +11,15 @@
|
|||||||
|
|
||||||
<div class="small-12 column attachment-actions">
|
<div class="small-12 column attachment-actions">
|
||||||
<div class="small-9 column action-add attachment-errors image-attachment">
|
<div class="small-9 column action-add attachment-errors image-attachment">
|
||||||
<%= render_image_attachment %>
|
<%= file_field %>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 column action-remove text-right">
|
<div class="small-3 column action-remove text-right">
|
||||||
<%= render_destroy_image_link %>
|
<%= destroy_link %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-6 column">
|
<div class="small-6 column">
|
||||||
<p class="file-name"><%= image_attachment_file_name %></p>
|
<p class="file-name"><%= file_name %></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ class Images::FieldsComponent < ApplicationComponent
|
|||||||
f.object
|
f.object
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_attachment_file_name
|
def file_name
|
||||||
image.attachment_file_name
|
image.attachment_file_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_destroy_image_link
|
def destroy_link
|
||||||
if !image.persisted? && image.cached_attachment.present?
|
if !image.persisted? && image.cached_attachment.present?
|
||||||
link_to t("images.form.delete_button"),
|
link_to t("images.form.delete_button"),
|
||||||
direct_upload_destroy_path(
|
direct_upload_destroy_path(
|
||||||
@@ -34,25 +34,25 @@ class Images::FieldsComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_image_attachment
|
def file_field
|
||||||
klass = image.persisted? || image.cached_attachment.present? ? " hide" : ""
|
klass = image.persisted? || image.cached_attachment.present? ? " hide" : ""
|
||||||
f.file_field :attachment,
|
f.file_field :attachment,
|
||||||
label_options: { class: "button hollow #{klass}" },
|
label_options: { class: "button hollow #{klass}" },
|
||||||
accept: imageable_accepted_content_types_extensions,
|
accept: accepted_content_types_extensions,
|
||||||
class: "js-image-attachment",
|
class: "js-image-attachment",
|
||||||
data: {
|
data: {
|
||||||
url: image_direct_upload_path,
|
url: direct_upload_path,
|
||||||
nested_image: true
|
nested_image: true
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_direct_upload_path
|
def direct_upload_path
|
||||||
direct_uploads_path("direct_upload[resource_type]": imageable.class.name,
|
direct_uploads_path("direct_upload[resource_type]": imageable.class.name,
|
||||||
"direct_upload[resource_id]": imageable.id,
|
"direct_upload[resource_id]": imageable.id,
|
||||||
"direct_upload[resource_relation]": "image")
|
"direct_upload[resource_relation]": "image")
|
||||||
end
|
end
|
||||||
|
|
||||||
def imageable_accepted_content_types_extensions
|
def accepted_content_types_extensions
|
||||||
Setting.accepted_content_types_for("images").map do |content_type|
|
Setting.accepted_content_types_for("images").map do |content_type|
|
||||||
if content_type == "jpg"
|
if content_type == "jpg"
|
||||||
".jpg,.jpeg"
|
".jpg,.jpeg"
|
||||||
|
|||||||
Reference in New Issue
Block a user