fix(editeur_de_champ): can join an pj template

This commit is contained in:
simon lehericey 2022-08-11 14:01:26 +02:00
parent 6b5f38ce74
commit adf194cc08
4 changed files with 21 additions and 3 deletions

View file

@ -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,

View file

@ -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

View file

@ -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();
}
}

View file

@ -484,6 +484,7 @@ Rails.application.routes.draw do
patch :move
patch :move_up
patch :move_down
put :piece_justificative_template
end
end