feat(piece_justificative): limit to 1 upload for existing procedures
This commit is contained in:
parent
0014ce4b91
commit
1f8d28c678
2 changed files with 5 additions and 3 deletions
|
@ -7,15 +7,17 @@ class Attachment::MultipleComponent < ApplicationComponent
|
|||
attr_reader :direct_upload
|
||||
attr_reader :id
|
||||
attr_reader :user_can_destroy
|
||||
attr_reader :max
|
||||
|
||||
delegate :count, :empty?, to: :attachments, prefix: true
|
||||
|
||||
def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil)
|
||||
def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil, max: nil)
|
||||
@form = form
|
||||
@attached_file = attached_file
|
||||
@user_can_destroy = user_can_destroy
|
||||
@direct_upload = direct_upload
|
||||
@id = id
|
||||
@max = max || 10
|
||||
|
||||
@attachments = attached_file.attachments || []
|
||||
end
|
||||
|
@ -28,7 +30,7 @@ class Attachment::MultipleComponent < ApplicationComponent
|
|||
return false if @attachments.empty?
|
||||
return false if !@attachments.last.persisted?
|
||||
|
||||
true
|
||||
@attachments.count < @max
|
||||
end
|
||||
|
||||
def stimulus_controller_name
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- user_can_destroy = !@champ.mandatory? || @champ.dossier.brouillon?
|
||||
= render Attachment::MultipleComponent.new(form: @form, attached_file: @champ.piece_justificative_file, user_can_destroy: user_can_destroy) do |c|
|
||||
= render Attachment::MultipleComponent.new(form: @form, attached_file: @champ.piece_justificative_file, user_can_destroy: user_can_destroy, max: @champ.procedure&.piece_justificative_multiple == false ? 1 : nil) do |c|
|
||||
- if @champ.type_de_champ.piece_justificative_template&.attached?
|
||||
- c.with_template do
|
||||
%p
|
||||
|
|
Loading…
Add table
Reference in a new issue