suppresion de la logique hidden

This commit is contained in:
Benoit Queyron 2024-06-27 15:19:51 +02:00
parent 70c1d30fe4
commit 4bee40caa4
No known key found for this signature in database
GPG key ID: 9E723480C7317E22
4 changed files with 4 additions and 14 deletions

View file

@ -9,7 +9,6 @@ class Attachment::EditComponent < ApplicationComponent
alias as_multiple? as_multiple
EXTENSIONS_ORDER = ['jpeg', 'png', 'pdf', 'zip'].freeze
DEFAULT_MAX_ATTACHMENTS = 10
def initialize(champ: nil, auto_attach_url: nil, attached_file:, direct_upload: true, index: 0, as_multiple: false, view_as: :link, user_can_destroy: true, user_can_replace: false, attachments: [], max: nil, **kwargs)
@champ = champ
@ -25,7 +24,7 @@ class Attachment::EditComponent < ApplicationComponent
@attachments = attachments.presence || (kwargs.key?(:attachment) ? [kwargs.delete(:attachment)] : [])
@attachments << attached_file.attachment if attached_file.respond_to?(:attachment) && @attachments.empty?
@attachments.compact!
@max = max || DEFAULT_MAX_ATTACHMENTS
@max = max
# Utilisation du premier attachement comme référence pour la rétrocompatibilité
@attachment = @attachments.first
@ -56,7 +55,7 @@ class Attachment::EditComponent < ApplicationComponent
end
def destroy_attachment_path
attachment_path(champ_id: champ&.public_id, champ: @champ)
attachment_path(champ: @champ)
end
def attachment_input_class
@ -79,7 +78,7 @@ class Attachment::EditComponent < ApplicationComponent
options.merge!(has_content_type_validator? ? { accept: accept_content_type } : {})
options[:multiple] = true if as_multiple?
options[:disabled] = true if @index >= @max
options[:disabled] = true if @max && @index >= @max
options
end

View file

@ -30,10 +30,6 @@ class Attachment::MultipleComponent < ApplicationComponent
@attachments.each_with_index(&block)
end
def can_attach_next?
@attachments.count < @max
end
def empty_component_id
champ.present? ? "attachment-multiple-empty-#{champ.public_id}" : "attachment-multiple-empty-generic"
end

View file

@ -21,7 +21,6 @@ class AttachmentsController < ApplicationController
@attachment.purge_later
flash.notice = 'La pièce jointe a bien été supprimée.'
@champ_id = params[:champ_id]
@champ = Champ.find(params[:champ]) if params[:champ]
respond_to do |format|

View file

@ -1,13 +1,9 @@
= turbo_stream.remove dom_id(@attachment, :persisted_row)
- if @champ_id
= turbo_stream.show "attachment-multiple-empty-#{@champ_id}"
= turbo_stream.focus_all "#attachment-multiple-empty-#{@champ_id} input"
= turbo_stream.show_all ".attachment-input-#{@attachment.id}"
- if @champ
= fields_for @champ.input_name, @champ do |form|
= turbo_stream.replace @champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ: @champ, form: form
= turbo_stream.focus_all "#attachment-multiple-empty-#{@champ_id} input"
= turbo_stream.focus_all "#attachment-multiple-empty-#{@champ.public_id} input"