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"}} {{:redirect to="./config.html?ok=1"}}
{{/form}} {{/form}}
{{* config par défaut *}} {{* lecture config (défaut ou enregistrée) *}}
{{:read file="./defaut.json" assign="config_defaut"}} {{:include file="./_get_config.html" keep="config"}}
{{:assign config_defaut=$config_defaut|json_decode}}
{{* types d'entrées *}} {{* types d'entrées *}}
{{#foreach from=$config_defaut.inputs item="elem"}} {{#foreach from=$config.input_nature key="label" item="type"}}
{{#foreach from=$elem key=label item=value}} {{:assign var='input_types.%s'|args:$type value=$type}}
{{:assign var='input_types.%s'|args:$value value=$value}}
{{/foreach}}
{{/foreach}} {{/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 *}} {{* types de sorties *}}
{{#foreach from=$config_defaut.outputs item="elem"}} {{#foreach from=$config.output_nature key="label" item="type"}}
{{#foreach from=$elem key=label item=value}} {{:assign var='output_types.%s'|args:$type value=$type}}
{{:assign var='output_typess.%s'|args:$value value=$value}}
{{/foreach}}
{{/foreach}} {{/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=""> <form method="post" action="">
<fieldset> <fieldset>
<legend>Entrées</legend> <legend>Entrées</legend>
@ -49,62 +54,23 @@
</tr> </tr>
</thead> </thead>
<tbody id="input_body"> <tbody id="input_body">
{{#foreach from=$module.config.input_nature item="input_field"}} {{#foreach from=$config.input_nature key="label" item="type"}}
{{* 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}}
<tr> <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" <td>{{:input type="select"
name="input_fields[type][]" name="input_fields[type][]"
options=$input_types options=$input_types
default=$input_field.type default=$type
required=true required=true
default_empty="— Choisir un type —"}} default_empty="— Choisir un type —"}}
</td> </td>
<td class="action"> <td class="action">
{{if $suppr}} {{:button
{{:button label="Supprimer" shape="minus" onclick="this.parentNode.parentNode.remove();"}} label="Supprimer" shape="minus"
{{else}} disabled=$locked_inputs|has:$label
{{:button label="Supprimer" shape="minus" disabled=true}} onclick="this.parentNode.parentNode.remove();"}}
{{/if}}
</td> </td>
</tr> </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}} {{/foreach}}
</tbody> </tbody>
</table> </table>
@ -132,63 +98,24 @@
</tr> </tr>
</thead> </thead>
<tbody id="output_body"> <tbody id="output_body">
{{#foreach from=$module.config.output_nature item="output_field"}} {{#foreach from=$config.output_nature key="label" item="type"}}
{{* 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}}
<tr> <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 <td>{{:input
type="select" type="select"
name="output_fields[type][]" name="output_fields[type][]"
options=$output_typess options=$output_types
default=$output_field.type default=$type
required=true required=true
default_empty="— Choisir un type —"}} default_empty="— Choisir un type —"}}
</td> </td>
<td class="action"> <td class="action">
{{if $suppr}} {{:button
{{:button label="Supprimer" shape="minus" onclick="this.parentNode.parentNode.remove();"}} label="Supprimer" shape="minus"
{{else}} disabled=$locked_outputs|has:$label
{{:button label="Supprimer" shape="minus" disabled=true}} onclick="this.parentNode.parentNode.remove();"}}
{{/if}}
</td> </td>
</tr> </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}} {{/foreach}}
</tbody> </tbody>
</table> </table>