diff --git a/app/controllers/administrateurs/types_de_champ_controller.rb b/app/controllers/administrateurs/types_de_champ_controller.rb index 25373dc9e..e01d17e83 100644 --- a/app/controllers/administrateurs/types_de_champ_controller.rb +++ b/app/controllers/administrateurs/types_de_champ_controller.rb @@ -31,6 +31,19 @@ module Administrateurs end end + def piece_justificative_template + type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id]) + + if type_de_champ.piece_justificative_template.attach(params[:blob_signed_id]) + @coordinate = draft.coordinate_for(type_de_champ) + @morphed = [champ_component_from(@coordinate)] + + render :create + else + render json: { errors: @champ.errors.full_messages }, status: 422 + end + end + def move flash.notice = "Formulaire enregistré" draft.move_type_de_champ(params[:stable_id], params[:position].to_i) @@ -95,7 +108,6 @@ module Administrateurs :drop_down_other, :drop_down_secondary_libelle, :drop_down_secondary_description, - :piece_justificative_template, editable_options: [ :cadastres, :unesco, diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index fbd791e45..e96fcfd8a 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -23,6 +23,8 @@ module ChampHelper def auto_attach_url(object) if object.is_a?(Champ) champs_piece_justificative_url(object.id) + elsif object.is_a?(TypeDeChamp) + piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id) end end diff --git a/app/javascript/controllers/type_de_champ_editor_controller.ts b/app/javascript/controllers/type_de_champ_editor_controller.ts index df68cd105..e4821f6e4 100644 --- a/app/javascript/controllers/type_de_champ_editor_controller.ts +++ b/app/javascript/controllers/type_de_champ_editor_controller.ts @@ -7,7 +7,7 @@ import { isTextInputElement } from '@utils'; import { useIntersection } from 'stimulus-use'; - +import { AutoUpload } from '../shared/activestorage/auto-upload'; import { ApplicationController } from './application_controller'; export class TypeDeChampEditorController extends ApplicationController { @@ -71,7 +71,7 @@ export class TypeDeChampEditorController extends ApplicationController { } private onInput(event: Event) { - const target = event.target as HTMLElement & { form?: HTMLFormElement }; + const target = event.target as HTMLInputElement; // mark input as touched so we know to not overwrite it's value with next re-render target.setAttribute('data-touched', 'true'); @@ -79,6 +79,9 @@ export class TypeDeChampEditorController extends ApplicationController { if (target.form && isTextInputElement(target)) { this.#dirtyForms.add(target.form); this.debounce(this.save, 600); + } else if (target.form && target.type == 'file' && target.files?.length) { + const autoupload = new AutoUpload(target, target.files[0]); + autoupload.start(); } } diff --git a/config/routes.rb b/config/routes.rb index 0745dc5c6..6184da693 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -484,6 +484,7 @@ Rails.application.routes.draw do patch :move patch :move_up patch :move_down + put :piece_justificative_template end end