diff --git a/app/controllers/new_administrateur/types_de_champ_controller.rb b/app/controllers/new_administrateur/types_de_champ_controller.rb index 4d4e1685c..f81298751 100644 --- a/app/controllers/new_administrateur/types_de_champ_controller.rb +++ b/app/controllers/new_administrateur/types_de_champ_controller.rb @@ -57,6 +57,8 @@ module NewAdministrateur ], methods: [ :drop_down_list_value, + :drop_down_secondary_libelle, + :drop_down_secondary_description, :piece_justificative_template_filename, :piece_justificative_template_url, :editable_options @@ -73,6 +75,8 @@ module NewAdministrateur :parent_id, :private, :drop_down_list_value, + :drop_down_secondary_libelle, + :drop_down_secondary_description, :piece_justificative_template, editable_options: [ :cadastres, @@ -94,6 +98,8 @@ module NewAdministrateur :description, :mandatory, :drop_down_list_value, + :drop_down_secondary_libelle, + :drop_down_secondary_description, :piece_justificative_template, editable_options: [ :cadastres, diff --git a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.jsx b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.jsx index 00ce93494..5679ebedf 100644 --- a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.jsx +++ b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.jsx @@ -14,6 +14,7 @@ import TypeDeChampDropDownOptions from './TypeDeChampDropDownOptions'; import TypeDeChampPieceJustificative from './TypeDeChampPieceJustificative'; import TypeDeChampRepetitionOptions from './TypeDeChampRepetitionOptions'; import TypeDeChampTypesSelect from './TypeDeChampTypesSelect'; +import TypeDeChampDropDownSecondary from './TypeDeChampDropDownSecondary'; const TypeDeChamp = sortableElement( ({ typeDeChamp, dispatch, idx: index, isFirstItem, isLastItem, state }) => { @@ -22,6 +23,7 @@ const TypeDeChamp = sortableElement( 'multiple_drop_down_list', 'linked_drop_down_list' ].includes(typeDeChamp.type_champ); + const isLinkedDropDown = typeDeChamp.type_champ === 'linked_drop_down_list'; const isFile = typeDeChamp.type_champ === 'piece_justificative'; const isCarte = typeDeChamp.type_champ === 'carte'; const isExplication = typeDeChamp.type_champ === 'explication'; @@ -130,6 +132,11 @@ const TypeDeChamp = sortableElement( isVisible={isDropDown} handler={updateHandlers.drop_down_list_value} /> + <TypeDeChampDropDownSecondary + isVisible={isLinkedDropDown} + libelleHandler={updateHandlers.drop_down_secondary_libelle} + descriptionHandler={updateHandlers.drop_down_secondary_description} + /> <TypeDeChampPieceJustificative isVisible={isFile} directUploadUrl={state.directUploadUrl} @@ -240,6 +247,8 @@ export const FIELDS = [ 'piece_justificative_template', 'private', 'type_champ', + 'drop_down_secondary_libelle', + 'drop_down_secondary_description', ...Object.keys(OPTIONS_FIELDS) ]; diff --git a/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownSecondary.jsx b/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownSecondary.jsx new file mode 100644 index 000000000..6f1ee62f8 --- /dev/null +++ b/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownSecondary.jsx @@ -0,0 +1,41 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +export default function TypeDeChampDropDownSecondary({ + isVisible, + libelleHandler, + descriptionHandler +}) { + if (isVisible) { + return ( + <div className="cell"> + <label htmlFor={libelleHandler.id}>Libellé secondaire</label> + <input + type="text" + id={libelleHandler.id} + name={libelleHandler.name} + value={libelleHandler.value ?? ''} + onChange={libelleHandler.onChange} + className="small-margin small" + /> + <label htmlFor={descriptionHandler.id}>Description secondaire</label> + <textarea + id={descriptionHandler.id} + name={descriptionHandler.name} + value={descriptionHandler.value ?? ''} + onChange={descriptionHandler.onChange} + rows={3} + cols={40} + className="small-margin small" + /> + </div> + ); + } + return null; +} + +TypeDeChampDropDownSecondary.propTypes = { + isVisible: PropTypes.bool, + libelleHandler: PropTypes.object, + descriptionHandler: PropTypes.object +}; diff --git a/app/models/champ.rb b/app/models/champ.rb index 5f7f66e44..131cbe976 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -41,6 +41,8 @@ class Champ < ApplicationRecord :drop_down_list_options?, :drop_down_list_disabled_options, :drop_down_list_enabled_non_empty_options, + :drop_down_secondary_libelle, + :drop_down_secondary_description, :exclude_from_export?, :exclude_from_view?, :repetition?, diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 3660203cd..e3856f4f6 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -221,6 +221,28 @@ class ProcedureRevision < ApplicationRecord stable_id: from_type_de_champ.stable_id } end + if to_type_de_champ.linked_drop_down_list? + if from_type_de_champ.drop_down_secondary_libelle != to_type_de_champ.drop_down_secondary_libelle + changes << { + op: :update, + attribute: :drop_down_secondary_libelle, + label: from_type_de_champ.libelle, + private: from_type_de_champ.private?, + from: from_type_de_champ.drop_down_secondary_libelle, + to: to_type_de_champ.drop_down_secondary_libelle + } + end + if from_type_de_champ.drop_down_secondary_description != to_type_de_champ.drop_down_secondary_description + changes << { + op: :update, + attribute: :drop_down_secondary_description, + label: from_type_de_champ.libelle, + private: from_type_de_champ.private?, + from: from_type_de_champ.drop_down_secondary_description, + to: to_type_de_champ.drop_down_secondary_description + } + end + end elsif to_type_de_champ.carte? if from_type_de_champ.carte_optional_layers != to_type_de_champ.carte_optional_layers changes << { diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index dcf5b096d..97b329b7b 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -58,7 +58,7 @@ class TypeDeChamp < ApplicationRecord belongs_to :parent, class_name: 'TypeDeChamp', optional: true has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy - store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation + store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation, :drop_down_secondary_libelle, :drop_down_secondary_description has_many :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ has_many :revisions, through: :revision_types_de_champ @@ -333,7 +333,9 @@ class TypeDeChamp < ApplicationRecord :drop_down_list_value, :piece_justificative_template_filename, :piece_justificative_template_url, - :editable_options + :editable_options, + :drop_down_secondary_libelle, + :drop_down_secondary_description ] } TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE diff --git a/app/views/new_administrateur/procedures/_revision_changes.html.haml b/app/views/new_administrateur/procedures/_revision_changes.html.haml index 2769bbd7c..cf0ead74f 100644 --- a/app/views/new_administrateur/procedures/_revision_changes.html.haml +++ b/app/views/new_administrateur/procedures/_revision_changes.html.haml @@ -14,6 +14,10 @@ %li.mb-1= t("update_type_champ#{postfix}", label: change[:label], to: t("activerecord.attributes.type_de_champ.type_champs.#{change[:to]}"), scope: [:new_administrateur, :revision_changes]) - when :description %li.mb-1= t("update_description#{postfix}", label: change[:label], to: change[:to], scope: [:new_administrateur, :revision_changes]) + - when :drop_down_secondary_libelle + %li.mb-1= t("update_drop_down_secondary_libelle#{postfix}", label: change[:label], to: change[:to], scope: [:new_administrateur, :revision_changes]) + - when :drop_down_secondary_description + %li.mb-1= t("update_drop_down_secondary_description#{postfix}", label: change[:label], to: change[:to], scope: [:new_administrateur, :revision_changes]) - when :mandatory - if change[:from] == false -# i18n-tasks-use t('new_administrateur.revision_changes.update_mandatory.enabled') diff --git a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml index 8f1a154e4..0f88b773e 100644 --- a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml @@ -4,10 +4,12 @@ { required: champ.mandatory? }, { data: { secondary_options: champ.secondary_options } } %span - = form.label :secondary_value, class: 'hidden' do - Valeur secondaire dépendant de la première + = form.label :secondary_value do + = champ.drop_down_secondary_libelle.presence || "Valeur secondaire dépendant de la première" - if champ.mandatory? %span.mandatory * + - if champ.drop_down_secondary_description.present? + .notice= string_to_html(champ.drop_down_secondary_description) = form.select :secondary_value, champ.secondary_options[champ.primary_value], { required: champ.mandatory? }, diff --git a/config/locales/views/new_administrateur/revision_changes/fr.yml b/config/locales/views/new_administrateur/revision_changes/fr.yml index 6c15a1ecd..b86ff6619 100644 --- a/config/locales/views/new_administrateur/revision_changes/fr.yml +++ b/config/locales/views/new_administrateur/revision_changes/fr.yml @@ -9,6 +9,8 @@ fr: other: Les positions de %{count} champs ont été modifiées update_libelle: Le libellé du champ « %{label} » a été modifié. Le nouveau libellé est « %{to} » update_description: La description du champ « %{label} » a été modifiée. La nouvelle description est « %{to} » + update_drop_down_secondary_libelle: Le libellé secondaire du champ « %{label} » a été modifié. Le nouveau libellé est « %{to} » + update_drop_down_secondary_description: La description secondaire du champ « %{label} » a été modifiée. La nouvelle description est « %{to} » update_type_champ: Le type du champ « %{label} » a été modifié. Il est maintenant de type « %{to} » update_mandatory: enabled: Le champ « %{label} » est maintenant obligatoire @@ -23,6 +25,8 @@ fr: other: Les positions de %{count} annotations privées ont été modifiées update_libelle_private: Le libellé de l’annotation privée « %{label} » a été modifié. Le nouveau libellé est « %{to} » update_description_private: La description de l’annotation privée « %{label} » a été modifiée. La nouvelle description est « %{to} » + update_drop_down_secondary_libelle_private: Le libellé secondaire de l’annotation « %{label} » a été modifié. Le nouveau libellé est « %{to} » + update_drop_down_secondary_description_private: La description secondaire de l’annotation « %{label} » a été modifiée. La nouvelle description est « %{to} » update_type_champ_private: Le type de l’annotation privée « %{label} » a été modifié. Elle est maintenant de type « %{to} » update_mandatory_private: enabled: L’annotation privée « %{label} » est maintenant obligatoire