Simplification gestion configuration

This commit is contained in:
Jean-Christophe Engel 2023-12-08 17:34:18 +01:00
parent 99b775bf9c
commit c5c9372d1b
1 changed files with 31 additions and 104 deletions

View File

@ -19,24 +19,29 @@
{{:redirect to="./config.html?ok=1"}}
{{/form}}
{{* config par défaut *}}
{{:read file="./defaut.json" assign="config_defaut"}}
{{:assign config_defaut=$config_defaut|json_decode}}
{{* lecture config (défaut ou enregistrée) *}}
{{:include file="./_get_config.html" keep="config"}}
{{* types d'entrées *}}
{{#foreach from=$config_defaut.inputs item="elem"}}
{{#foreach from=$elem key=label item=value}}
{{:assign var='input_types.%s'|args:$value value=$value}}
{{/foreach}}
{{#foreach from=$config.input_nature key="label" item="type"}}
{{:assign var='input_types.%s'|args:$type value=$type}}
{{/foreach}}
{{* Natures d'entrées qui ne peuvent être supprimées *}}
{{#load type="movement" where="$$.direction='input'" group="$$.input_nature"}}
{{:assign var="locked_inputs." value=$input_nature}}
{{/load}}
{{* types de sorties *}}
{{#foreach from=$config_defaut.outputs item="elem"}}
{{#foreach from=$elem key=label item=value}}
{{:assign var='output_typess.%s'|args:$value value=$value}}
{{/foreach}}
{{#foreach from=$config.output_nature key="label" item="type"}}
{{:assign var='output_types.%s'|args:$type value=$type}}
{{/foreach}}
{{* Natures de sorties qui ne peuvent être supprimées *}}
{{#load type="movement" where="$$.direction='output'" group="$$.output_nature"}}
{{:assign var="locked_outputs." value=$output_nature}}
{{/load}}
<form method="post" action="">
<fieldset>
<legend>Entrées</legend>
@ -49,62 +54,23 @@
</tr>
</thead>
<tbody id="input_body">
{{#foreach from=$module.config.input_nature item="input_field"}}
{{* Vérifier si la suppression de ce type d'entrée est possible *}}
{{:assign suppr=true}}
{{#load type="movement" where="$$.input_nature = :libelle" :libelle=$input_field.label}}
{{:assign suppr=false}}
{{/load}}
{{#foreach from=$config.input_nature key="label" item="type"}}
<tr>
<td>{{:input type="text" name="input_fields[label][]" default=$input_field.label}}</td>
<td>{{:input type="text" name="input_fields[label][]" default=$label}}</td>
<td>{{:input type="select"
name="input_fields[type][]"
options=$input_types
default=$input_field.type
default=$type
required=true
default_empty="— Choisir un type —"}}
</td>
<td class="action">
{{if $suppr}}
{{:button label="Supprimer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
{{else}}
{{:button label="Supprimer" shape="minus" disabled=true}}
{{/if}}
{{:button
label="Supprimer" shape="minus"
disabled=$locked_inputs|has:$label
onclick="this.parentNode.parentNode.remove();"}}
</td>
</tr>
{{else}}
{{* pas de config enregistrée : utiliser les valeurs par défaut *}}
{{#foreach from=$config_defaut.inputs item="elem"}}
{{#foreach from=$elem key=label item=value}}
{{* Vérifier si la suppression de ce type d'entrée est possible *}}
{{:assign suppr=true}}
{{#load type="movement" where="$$.input_nature = :libelle" :libelle=$label}}
{{:assign suppr=false}}
{{/load}}
<tr>
<td>{{:input type="text" name="input_fields[label][]" default=$label}}</td>
<td>{{:input
type="select"
name="input_fields[type][]"
options=$input_types
required=true
default=$value
default_empty="— Choisir un type —"}}
</td>
<td class="action">
{{if $suppr}}
{{:button label="Supprimer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
{{else}}
{{:button label="Supprimer" shape="minus" disabled=true}}
{{/if}}
</td>
</tr>
{{/foreach}}
{{/foreach}}
{{/foreach}}
</tbody>
</table>
@ -132,63 +98,24 @@
</tr>
</thead>
<tbody id="output_body">
{{#foreach from=$module.config.output_nature item="output_field"}}
{{* Vérifier si la suppression de ce type de sortie est possible *}}
{{:assign suppr=true}}
{{#load type="movement" where="$$.output_nature = :libelle" :libelle=$output_field.label}}
{{:assign suppr=false}}
{{/load}}
{{#foreach from=$config.output_nature key="label" item="type"}}
<tr>
<td>{{:input type="text" name="output_fields[label][]" default=$output_field.label}}</td>
<td>{{:input type="text" name="output_fields[label][]" default=$label}}</td>
<td>{{:input
type="select"
name="output_fields[type][]"
options=$output_typess
default=$output_field.type
options=$output_types
default=$type
required=true
default_empty="— Choisir un type —"}}
</td>
<td class="action">
{{if $suppr}}
{{:button label="Supprimer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
{{else}}
{{:button label="Supprimer" shape="minus" disabled=true}}
{{/if}}
{{:button
label="Supprimer" shape="minus"
disabled=$locked_outputs|has:$label
onclick="this.parentNode.parentNode.remove();"}}
</td>
</tr>
{{else}}
{{* pas de config enregistrée : utiliser les valeurs par défaut *}}
{{#foreach from=$config_defaut.outputs item="elem"}}
{{#foreach from=$elem key=label item=value}}
{{* Vérifier si la suppression de ce type de sortie est possible *}}
{{:assign suppr=true}}
{{#load type="movement" where="$$.input_nature = :libelle" :libelle=$label}}
{{:assign suppr=false}}
{{/load}}
<tr>
<td>{{:input type="text" name="output_fields[label][]" default=$label}}</td>
<td>{{:input
type="select"
name="output_fields[type][]"
options=$output_typess
required=true
default=$value
default_empty="— Choisir un type —"}}
</td>
<td class="action">
{{if $suppr}}
{{:button label="Supprimer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
{{else}}
{{:button label="Supprimer" shape="minus" disabled=true}}
{{/if}}
</td>
</tr>
{{/foreach}}
{{/foreach}}
{{/foreach}}
</tbody>
</table>