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

View file

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

View file

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

View file

@ -1,13 +1,9 @@
= turbo_stream.remove dom_id(@attachment, :persisted_row) = 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}" = turbo_stream.show_all ".attachment-input-#{@attachment.id}"
- if @champ - if @champ
= fields_for @champ.input_name, @champ do |form| = fields_for @champ.input_name, @champ do |form|
= turbo_stream.replace @champ.input_group_id do = turbo_stream.replace @champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ: @champ, form: form = 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"