This way we can simplify the way we generate form fields. In some cases, we also use the human attribute in table headers, which IMHO makes sense. I haven't moved all of them: for example, sometimes a label is different depending on whether it's shown to administrators, valuators, or users. And I haven't touched the ones related to devise, since I wasn't sure about possible side effects. Note I've also removed placeholders when they had the same text as their labels, since they weren't helpful. On the contrary, the added redundant text to the form, potentially distracting users.
74 lines
2.6 KiB
Ruby
74 lines
2.6 KiB
Ruby
module ImagesHelper
|
|
|
|
def image_absolute_url(image, version)
|
|
return "" unless image
|
|
if Paperclip::Attachment.default_options[:storage] == :filesystem
|
|
URI(request.url) + image.attachment.url(version)
|
|
else
|
|
investment.image_url(version)
|
|
end
|
|
end
|
|
|
|
def image_first_recommendation(image)
|
|
t "images.#{image.imageable.class.name.parameterize.underscore}.recommendation_one_html",
|
|
title: image.imageable.title
|
|
end
|
|
|
|
def image_attachment_file_name(image)
|
|
image.attachment_file_name
|
|
end
|
|
|
|
def image_errors_on_attachment(image)
|
|
image.errors[:attachment].join(", ") if image.errors.key?(:attachment)
|
|
end
|
|
|
|
def image_bytes_to_megabytes(bytes)
|
|
bytes / Numeric::MEGABYTE
|
|
end
|
|
|
|
def image_class(image)
|
|
image.persisted? ? "persisted-image" : "cached-image"
|
|
end
|
|
|
|
def render_destroy_image_link(builder, image)
|
|
if !image.persisted? && image.cached_attachment.present?
|
|
link_to t("images.form.delete_button"),
|
|
direct_upload_destroy_url("direct_upload[resource_type]": image.imageable_type,
|
|
"direct_upload[resource_id]": image.imageable_id,
|
|
"direct_upload[resource_relation]": "image",
|
|
"direct_upload[cached_attachment]": image.cached_attachment),
|
|
method: :delete,
|
|
remote: true,
|
|
class: "delete remove-cached-attachment"
|
|
else
|
|
link_to_remove_association t("images.form.delete_button"), builder, class: "delete remove-image"
|
|
end
|
|
end
|
|
|
|
def render_image_attachment(builder, imageable, image)
|
|
klass = image.persisted? || image.cached_attachment.present? ? " hide" : ""
|
|
builder.file_field :attachment,
|
|
label_options: { class: "button hollow #{klass}" },
|
|
accept: imageable_accepted_content_types_extensions,
|
|
class: "js-image-attachment",
|
|
data: {
|
|
url: image_direct_upload_url(imageable),
|
|
nested_image: true
|
|
}
|
|
end
|
|
|
|
def render_image(image, version, show_caption = true)
|
|
version = image.persisted? ? version : :original
|
|
render "images/image", image: image,
|
|
version: version,
|
|
show_caption: show_caption
|
|
end
|
|
|
|
def image_direct_upload_url(imageable)
|
|
direct_uploads_url("direct_upload[resource_type]": imageable.class.name,
|
|
"direct_upload[resource_id]": imageable.id,
|
|
"direct_upload[resource_relation]": "image")
|
|
end
|
|
|
|
end
|