evol: champs optionnels profil et nettoyage templates

This commit is contained in:
Arnaud Delcasse
2026-02-25 17:16:29 +01:00
parent 10b2599f91
commit 67d38ede79
7 changed files with 92 additions and 91 deletions

View File

@@ -0,0 +1,64 @@
{{define "profile_optional_fields_display"}}
{{if .other_properties}}
{{range .fields}}
{{$fieldName := .name}}
{{$fieldLabel := .label}}
{{if eq .type "multicheckbox"}}
{{$hasValues := false}}
{{range .options}}
{{$optionKey := printf "%s___%s" $fieldName .value}}
{{if index $.other_properties $optionKey}}{{$hasValues = true}}{{end}}
{{end}}
{{if $hasValues}}
<div class="sm:col-span-2">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">
<div class="flex flex-wrap gap-2">
{{range .options}}
{{$optionKey := printf "%s___%s" $fieldName .value}}
{{if index $.other_properties $optionKey}}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-200 text-gray-800">
{{.label}}
</span>
{{end}}
{{end}}
</div>
</dd>
</div>
{{end}}
{{else if eq .type "select"}}
{{$fieldValue := index $.other_properties $fieldName}}
{{if and $fieldValue (ne $fieldValue "0") (ne $fieldValue "")}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">
{{if eq $fieldName "gender"}}
{{genderISO5218 $fieldValue}}
{{else}}
{{range .options}}
{{if eq .value $fieldValue}}{{.label}}{{end}}
{{end}}
{{end}}
</dd>
</div>
{{end}}
{{else if eq .type "date"}}
{{$fieldValue := index $.other_properties $fieldName}}
{{if $fieldValue}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">{{ (timeFrom $fieldValue).Format "02/01/2006" }}</dd>
</div>
{{end}}
{{else}}
{{$fieldValue := index $.other_properties $fieldName}}
{{if $fieldValue}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">{{$fieldValue}}</dd>
</div>
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}

View File

@@ -89,36 +89,7 @@
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.beneficiary.Data.file_number}}</dd>
</div>
{{end}}
{{if and .ViewState.beneficiary.Data.other_properties .ViewState.beneficiary.Data.other_properties.status}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Statut</dt>
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.beneficiary.Data.other_properties.status}}</dd>
</div>
{{end}}
{{if and .ViewState.beneficiary.Data.other_properties .ViewState.beneficiary.Data.other_properties.situation}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Situation sociale</dt>
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.beneficiary.Data.other_properties.situation}}</dd>
</div>
{{end}}
{{if and .ViewState.beneficiary.Data.other_properties .ViewState.beneficiary.Data.other_properties.subscription_reason}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Motif d'inscription</dt>
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.beneficiary.Data.other_properties.subscription_reason}}</dd>
</div>
{{end}}
{{if and .ViewState.beneficiary.Data.other_properties .ViewState.beneficiary.Data.other_properties.last_subscription_date}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Dernière adhésion</dt>
<dd class="mt-1 text-sm text-gray-900">{{ (timeFrom .ViewState.beneficiary.Data.other_properties.last_subscription_date).Format "02/01/2006" }}</dd>
</div>
{{end}}
{{if and .ViewState.beneficiary.Data.other_properties .ViewState.beneficiary.Data.other_properties.comment}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Commentaire</dt>
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.beneficiary.Data.other_properties.comment}}</dd>
</div>
{{end}}
{{ template "profile_optional_fields_display" dict "other_properties" .ViewState.beneficiary.Data.other_properties "fields" $.ViewState.profile_optional_fields }}
</dl>
</div>
</div>

View File

@@ -7,15 +7,15 @@
<div class="max-w-7xl mx-auto px-4 sm:px-6 md:px-8 mt-8"
x-data="{
fields: {
first_name: '{{ .ViewState.beneficiary.Data.first_name }}',
last_name: '{{ .ViewState.beneficiary.Data.last_name }}',
email: '{{ .ViewState.beneficiary.Data.email }}',
phone_number: '{{ .ViewState.beneficiary.Data.phone_number }}',
birthdate: {{if .ViewState.beneficiary.Data.birthdate}}'{{ (timeFrom .ViewState.beneficiary.Data.birthdate).Format "2006-01-02" }}'{{else}}null{{end}},
file_number: '{{ .ViewState.beneficiary.Data.file_number }}',
gender: {{.ViewState.beneficiary.Data.gender}}
first_name: null,
last_name: null,
email: null,
phone_number: null,
birthdate: null,
file_number: null,
gender: 0
},
other_properties: {{if .ViewState.beneficiary.Data.other_properties}}{{ json .ViewState.beneficiary.Data.other_properties }}{{else}}{}{{end}},
other_properties: {},
other_properties_serialized: null,
rules: {
first_name: ['required'],
@@ -37,6 +37,19 @@
}
},
isFormValid: true,
init() {
const data = window.__PARCOURSMOB_DATA__ || {};
this.fields.first_name = data.first_name || '';
this.fields.last_name = data.last_name || '';
this.fields.email = data.email || '';
this.fields.phone_number = data.phone_number || '';
this.fields.file_number = data.file_number || '';
this.fields.gender = data.gender || 0;
if (data.birthdate) {
this.fields.birthdate = String(data.birthdate).substring(0, 10);
}
this.other_properties = data.other_properties || {};
},
validate() {
this.formValidation = Iodine.assert(this.fields, this.rules)
},

View File

@@ -173,6 +173,7 @@
</div>
</div>
{{if .DynamicData}}<script id="dynamic-data">window.__PARCOURSMOB_DATA__ = {{ json .DynamicData }};</script>{{end}}
<main>
<div class="py-6">
{{ template "content" . }}

View File

@@ -91,6 +91,7 @@
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.driver.Data.address_destination.properties.label}}</dd>
</div>
{{end}}
{{ template "profile_optional_fields_display" dict "other_properties" .ViewState.driver.Data.other_properties "fields" $.ViewState.profile_optional_fields }}
</dl>
</div>
</div>

View File

@@ -89,59 +89,7 @@
<dd class="mt-1 text-sm text-gray-900">{{.ViewState.driver.Data.file_number}}</dd>
</div>
{{end}}
{{range .ViewState.profile_optional_fields}}
{{$fieldName := .name}}
{{$fieldLabel := .label}}
{{$fieldType := .type}}
{{if eq .type "multicheckbox"}}
{{$hasValues := false}}
{{range .options}}
{{$optionKey := printf "%s___%s" $fieldName .value}}
{{if index $.ViewState.driver.Data.other_properties $optionKey}}{{$hasValues = true}}{{end}}
{{end}}
{{if $hasValues}}
<div class="sm:col-span-2">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">
<div class="flex flex-wrap gap-2">
{{range .options}}
{{$optionKey := printf "%s___%s" $fieldName .value}}
{{if index $.ViewState.driver.Data.other_properties $optionKey}}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-200 text-gray-800">
{{.label}}
</span>
{{end}}
{{end}}
</div>
</dd>
</div>
{{end}}
{{else if eq .type "select"}}
{{$fieldValue := index $.ViewState.driver.Data.other_properties $fieldName}}
{{if and $fieldValue (ne $fieldValue "0") (ne $fieldValue "")}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">
{{if eq $fieldName "gender"}}
{{genderISO5218 $fieldValue}}
{{else}}
{{range .options}}
{{if eq .value $fieldValue}}{{.label}}{{end}}
{{end}}
{{end}}
</dd>
</div>
{{end}}
{{else}}
{{$fieldValue := index $.ViewState.driver.Data.other_properties $fieldName}}
{{if $fieldValue}}
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">{{$fieldLabel}}</dt>
<dd class="mt-1 text-sm text-gray-900">{{$fieldValue}}</dd>
</div>
{{end}}
{{end}}
{{end}}
{{ template "profile_optional_fields_display" dict "other_properties" .ViewState.driver.Data.other_properties "fields" $.ViewState.profile_optional_fields }}
</dl>
</div>
</div>