Remove duplication in attachable fields components
These classes were almost identical.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
class Documents::FieldsComponent < ApplicationComponent
|
||||
attr_reader :f
|
||||
delegate :current_user, to: :helpers
|
||||
|
||||
def initialize(f)
|
||||
@f = f
|
||||
@@ -11,35 +10,4 @@ class Documents::FieldsComponent < ApplicationComponent
|
||||
def document
|
||||
f.object
|
||||
end
|
||||
|
||||
def file_name
|
||||
document.attachment_file_name
|
||||
end
|
||||
|
||||
def destroy_link
|
||||
if !document.persisted? && document.cached_attachment.present?
|
||||
link_to t("documents.form.delete_button"), "#", class: "delete remove-cached-attachment"
|
||||
else
|
||||
link_to_remove_association document.new_record? ? t("documents.form.cancel_button") : t("documents.form.delete_button"), f, class: "delete remove-document"
|
||||
end
|
||||
end
|
||||
|
||||
def file_field
|
||||
klass = document.persisted? || document.cached_attachment.present? ? " hide" : ""
|
||||
f.file_field :attachment,
|
||||
label_options: { class: "button hollow #{klass}" },
|
||||
accept: accepted_content_types_extensions,
|
||||
class: "js-document-attachment",
|
||||
data: { url: direct_upload_path }
|
||||
end
|
||||
|
||||
def direct_upload_path
|
||||
direct_uploads_path("direct_upload[resource_type]": document.documentable_type,
|
||||
"direct_upload[resource_id]": document.documentable_id,
|
||||
"direct_upload[resource_relation]": "documents")
|
||||
end
|
||||
|
||||
def accepted_content_types_extensions
|
||||
Setting.accepted_content_types_for("documents").map { |content_type| ".#{content_type}" }.join(",")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user