disabled input with PJ and insert input when PJ is deleted
This commit is contained in:
parent
ceedbe9c45
commit
3e4aa0cde3
3 changed files with 20 additions and 9 deletions
|
@ -28,7 +28,6 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
# When parent form has nested attributes, pass the form builder object_name
|
# When parent form has nested attributes, pass the form builder object_name
|
||||||
# to correctly infer the input attribute name.
|
# to correctly infer the input attribute name.
|
||||||
@form_object_name = kwargs.delete(:form_object_name)
|
@form_object_name = kwargs.delete(:form_object_name)
|
||||||
|
@ -55,7 +54,7 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_attachment_path
|
def destroy_attachment_path
|
||||||
attachment_path(dossier_id: champ&.dossier_id, stable_id: champ&.stable_id, row_id: champ&.row_id)
|
attachment_path(dossier_id: champ&.dossier_id, stable_id: champ&.stable_id, row_id: champ&.row_id, auto_attach_url: @auto_attach_url, view_as: @view_as)
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachment_input_class
|
def attachment_input_class
|
||||||
|
@ -66,7 +65,7 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
track_issue_with_missing_validators if missing_validators?
|
track_issue_with_missing_validators if missing_validators?
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
class: class_names("fr-upload attachment-input": true, "#{attachment_input_class}": true, "hidden": persisted?),
|
class: class_names("fr-upload attachment-input": true, "#{attachment_input_class}": true),
|
||||||
direct_upload: @direct_upload,
|
direct_upload: @direct_upload,
|
||||||
id: input_id,
|
id: input_id,
|
||||||
aria: { describedby: champ&.describedby_id },
|
aria: { describedby: champ&.describedby_id },
|
||||||
|
@ -78,7 +77,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 @max && @index >= @max
|
options[:disabled] = true if (@max && @index >= @max) || persisted?
|
||||||
|
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,11 @@ 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 = find_champ if params[:dossier_id]
|
if params[:dossier_id]
|
||||||
|
@champ = find_champ
|
||||||
|
else
|
||||||
|
@attachment_options = attachment_options
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.turbo_stream
|
format.turbo_stream
|
||||||
|
@ -35,4 +39,12 @@ class AttachmentsController < ApplicationController
|
||||||
dossier = policy_scope(Dossier).includes(:champs).find(params[:dossier_id])
|
dossier = policy_scope(Dossier).includes(:champs).find(params[:dossier_id])
|
||||||
dossier.champs.find_by(stable_id: params[:stable_id], row_id: params[:row_id])
|
dossier.champs.find_by(stable_id: params[:stable_id], row_id: params[:row_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attachment_options
|
||||||
|
{
|
||||||
|
attached_file: @attachment.record.public_send(@attachment.name),
|
||||||
|
auto_attach_url: params[:auto_attach_url],
|
||||||
|
view_as: params[:view_as]&.to_sym
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
= turbo_stream.remove dom_id(@attachment, :persisted_row)
|
|
||||||
|
|
||||||
= 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.public_id} input"
|
= turbo_stream.focus_all "#attachment-multiple-empty-#{@champ.public_id} input"
|
||||||
|
- else
|
||||||
|
= turbo_stream.replace dom_id(@attachment, :edit) do
|
||||||
|
= render Attachment::EditComponent.new(**@attachment_options)
|
||||||
|
= turbo_stream.focus_all "##{dom_id(@attachment.record, @attachment.name)}"
|
||||||
|
|
Loading…
Reference in a new issue