config : ajout état définitif d'une sortie

This commit is contained in:
Jean-Christophe Engel 2023-10-30 16:43:15 +01:00
parent 09e42d44ac
commit 08ce30c4cf
2 changed files with 47 additions and 18 deletions

View File

@ -15,10 +15,14 @@
{{:assign var="input_fields." label=$field.label|trim owner=$field.owner|boolval}}
{{/foreach}}
{{#foreach from=$_POST.output_fields|array_transpose item="field"}}
{{:assign var="output_fields." label=$field.label|trim final=$field.final|boolval}}
{{/foreach}}
{{:save key="config"
validate_schema="./config.schema.json"
inputNature=$input_fields
outputNature=$_POST.output_fields
outputNature=$output_fields
}}
{{:redirect to="./config.html?ok=1"}}
{{/form}}
@ -31,10 +35,10 @@
{{:assign var='types_entrees.Emprunt' value=0}}
{{* types de sorties par défaut *}}
{{:assign var='types_sorties.' value='Vente'}}
{{:assign var='types_sorties.' value='Don'}}
{{:assign var='types_sorties.' value='Location'}}
{{:assign var='types_sorties.' value='Prêt'}}
{{:assign var='types_sorties.Vente' value=1}}
{{:assign var='types_sorties.Don' value=1}}
{{:assign var='types_sorties.Location' value=0}}
{{:assign var='types_sorties.Prêt' value=0}}
<form method="post" action="">
<fieldset>
@ -43,7 +47,7 @@
<thead>
<tr>
<th>Type d'entrée</th>
<th>Propriétaire ? <br/> <span class="help" style="font-weight:normal">Cocher si l'association devient propriétaire du matériel</span></th>
<th>Propriétaire ? <br/><span class="help" style="font-weight:normal">Cocher si l'association devient propriétaire du matériel</span></th>
<th>Action</th>
</tr>
</thead>
@ -94,21 +98,36 @@
<thead>
<tr>
<th>Type de sortie</th>
<th>Définitif ? <br/><span class="help" style="font-weight:normal">Cocher si la sortie est définitive</span></th>
<th>Action</th>
</tr>
</thead>
<tbody id="output_body">
{{#foreach from=$module.config.outputNature item="output_field"}}
<tr>
<td>{{:input type="text" name="output_fields[]" default=$output_field.label}}</td>
<td>{{:input type="text" name="output_fields[label][]" default=$output_field.label}}</td>
<td>
<label>
{{:input type="hidden" name="output_fields[final][]" value=0}}
{{:input type="checkbox" name="output_fields[final][]" value=1 default=$output_field.final}}
Définitif ?
</label>
</td>
<td class="action">
{{:button label="Retirer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
</td>
</tr>
{{else}}
{{#foreach from=$types_sorties item="value"}}
{{#foreach from=$types_sorties key="label" item="value"}}
<tr>
<td>{{:input type="text" name="output_fields[]" default=$value}}</td>
<td>{{:input type="text" name="output_fields[label][]" default=$label}}</td>
<td>
<label>
{{:input type="hidden" name="output_fields[final][]" value=0}}
{{:input type="checkbox" name="output_fields[final][]" value=1 default=$value}}
Définitif ?
</label>
</td>
<td class="action">
{{:button label="Retirer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
</td>
@ -131,7 +150,7 @@
label="Enregistrer"
shape="right"
class="main"
onclick="return desactiverCache('#input_body');"
onclick="return desactiverCache('#input_body', '#output_body');"
}}
</p>
</form>
@ -152,8 +171,9 @@
}
// Désactiver les champs caché des checkbox cochés
function desactiverCache(id_body) {
for (let ligne of document.querySelector(id_body).children) {
function desactiverCache(...id_body) {
for (const id of id_body) {
for (let ligne of document.querySelector(id).children) {
let idCase = ligne.querySelector("input[type=checkbox]");
let cache = ligne.querySelector("input[type=hidden]"); // le champ caché
if (idCase.checked) {
@ -161,6 +181,7 @@
}
}
}
}
</script>
{{:admin_footer}}

View File

@ -19,9 +19,17 @@
},
"outputNature": {
"description": "Nature des sorties",
"type": "array",
"type": ["array", "null"],
"items": {
"type": "string"
"type": "object",
"properties": {
"label" : {
"type" : "string"
},
"final" : {
"type" : "boolean"
}
}
}
}
}