Update type de champ serialization for editor

This commit is contained in:
Paul Chavard 2019-03-20 16:28:13 +03:00
parent 639facaf2a
commit 25c4391118
2 changed files with 66 additions and 35 deletions

View file

@ -48,38 +48,54 @@ module NewAdministrateur
def serialize_type_de_champ(type_de_champ)
{
type_de_champ: type_de_champ.as_json(
except: [:created_at, :updated_at, :stable_id, :type, :parent_id, :procedure_id, :private],
methods: [:piece_justificative_template_filename, :piece_justificative_template_url, :drop_down_list_value]
except: [
:created_at,
:options,
:order_place,
:parent_id,
:private,
:procedure_id,
:stable_id,
:type,
:updated_at
],
methods: [
:cadastres,
:drop_down_list_value,
:parcelles_agricoles,
:piece_justificative_template_filename,
:piece_justificative_template_url,
:quartiers_prioritaires
]
)
}
end
def type_de_champ_create_params
params.required(:type_de_champ).permit(:libelle,
params.required(:type_de_champ).permit(:cadastres,
:description,
:order_place,
:type_champ,
:private,
:parent_id,
:drop_down_list_value,
:libelle,
:mandatory,
:piece_justificative_template,
:quartiers_prioritaires,
:cadastres,
:order_place,
:parcelles_agricoles,
:drop_down_list_value).merge(procedure: @procedure)
:parent_id,
:piece_justificative_template,
:private,
:quartiers_prioritaires,
:type_champ).merge(procedure: @procedure)
end
def type_de_champ_update_params
params.required(:type_de_champ).permit(:libelle,
params.required(:type_de_champ).permit(:cadastres,
:description,
:order_place,
:type_champ,
:drop_down_list_value,
:libelle,
:mandatory,
:parcelles_agricoles,
:piece_justificative_template,
:quartiers_prioritaires,
:cadastres,
:parcelles_agricoles,
:drop_down_list_value)
:type_champ)
end
end
end

View file

@ -36,23 +36,21 @@ module ProcedureHelper
def types_de_champ_data(procedure)
{
type: "champ",
types_de_champ_options: types_de_champ_options.to_json,
types_de_champ: types_de_champ_as_json(procedure.types_de_champ).to_json,
save_url: procedure_types_de_champ_path(procedure),
direct_upload_url: rails_direct_uploads_url,
drag_icon_url: image_url("icons/drag.svg")
isAnnotation: false,
typeDeChampsTypes: types_de_champ_types,
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ),
baseUrl: procedure_types_de_champ_path(procedure),
directUploadUrl: rails_direct_uploads_url
}
end
def types_de_champ_private_data(procedure)
{
type: "annotation",
types_de_champ_options: types_de_champ_options.to_json,
types_de_champ: types_de_champ_as_json(procedure.types_de_champ_private).to_json,
save_url: procedure_types_de_champ_path(procedure),
direct_upload_url: rails_direct_uploads_url,
drag_icon_url: image_url("icons/drag.svg")
isAnnotation: true,
typeDeChampsTypes: types_de_champ_types,
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ_private),
baseUrl: procedure_types_de_champ_path(procedure),
directUploadUrl: rails_direct_uploads_url
}
end
@ -63,20 +61,37 @@ module ProcedureHelper
TypeDeChamp.type_champs.fetch(:repetition) => :champ_repetition?
}
def types_de_champ_options
types_de_champ = TypeDeChamp.type_de_champs_list_fr
def types_de_champ_types
types_de_champ_types = TypeDeChamp.type_de_champs_list_fr
types_de_champ.select! do |tdc|
types_de_champ_types.select! do |tdc|
toggle = TOGGLES[tdc.last]
toggle.blank? || Flipflop.send(toggle)
end
types_de_champ
types_de_champ_types
end
TYPES_DE_CHAMP_BASE = {
except: [:created_at, :updated_at, :stable_id, :type, :parent_id, :procedure_id, :private],
methods: [:piece_justificative_template_filename, :piece_justificative_template_url, :drop_down_list_value]
except: [
:created_at,
:options,
:order_place,
:parent_id,
:private,
:procedure_id,
:stable_id,
:type,
:updated_at
],
methods: [
:cadastres,
:drop_down_list_value,
:parcelles_agricoles,
:piece_justificative_template_filename,
:piece_justificative_template_url,
:quartiers_prioritaires
]
}
TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE
.merge(include: { types_de_champ: TYPES_DE_CHAMP_BASE })