equipment/config.html

188 lines
6.3 KiB
HTML

{{#restrict section="config" level="admin" block=true}}{{/restrict}}
{{:admin_header title="Configuration" current="module_equipment"}}
{{* barre de navigation *}}
{{:include file="/%s/_nav.html"|args:$module.name current="config"}}
{{if $_GET.ok}}
<p class="block confirm">Configuration enregistrée.</p>
{{/if}}
{{* Traiter l'envoi du formulaire *}}
{{#form on="save"}}
{{#foreach from=$_POST.input_fields|array_transpose item="field"}}
{{: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=$output_fields
}}
{{:redirect to="./config.html?ok=1"}}
{{/form}}
{{* types d'entrées par défaut *}}
{{:assign var='types_entrees.Achat' value=1}}
{{:assign var='types_entrees.Don' value=1}}
{{:assign var='types_entrees.Récupération' value=1}}
{{:assign var='types_entrees.Location' value=0}}
{{:assign var='types_entrees.Emprunt' value=0}}
{{* types de sorties par défaut *}}
{{: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>
<legend>Entrées</legend>
<table class="list input_fields">
<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>Action</th>
</tr>
</thead>
<tbody id="input_body">
{{#foreach from=$module.config.inputNature item="input_field"}}
<tr>
<td>{{:input type="text" name="input_fields[label][]" default=$input_field.label}}</td>
<td>
<label>
{{:input type="hidden" name="input_fields[owner][]" value=0}}
{{:input type="checkbox" name="input_fields[owner][]" value=1 default=$input_field.owner}}
Proprio ?
</label>
</td>
<td class="action">
{{:button label="Retirer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
</td>
</tr>
{{else}}
{{#foreach from=$types_entrees key="label" item="value"}}
<tr>
<td>{{:input type="text" name="input_fields[label][]" default=$label}}</td>
<td>
<label>
{{:input type="hidden" name="input_fields[owner][]" value=0}}
{{:input type="checkbox" name="input_fields[owner][]" value=1 default=$value}}
Proprio ?
</label>
</td>
<td class="action">
{{:button label="Retirer" shape="minus" onclick="this.parentNode.parentNode.remove();"}}
</td>
</tr>
{{/foreach}}
{{/foreach}}
</tbody>
</table>
<p class="actions">
{{:button shape="plus"
label="Ajouter un champ"
onclick="addLine('#input_body')"}}
</p>
</fieldset>
<fieldset>
<legend>Sorties</legend>
<table class="list output_fields">
<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[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 key="label" item="value"}}
<tr>
<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>
</tr>
{{/foreach}}
{{/foreach}}
</tbody>
</table>
<p class="actions">
{{:button shape="plus"
label="Ajouter un champ"
onclick="addLine('#output_body')"}}
</p>
</fieldset>
<p class="submit">
{{:button
type="submit"
name="save"
label="Enregistrer"
shape="right"
class="main"
onclick="return desactiverCache('#input_body', '#output_body');"
}}
</p>
</form>
<script type="text/javascript">
// dupliquer la dernière ligne d'une table
function addLine(id_body) {
var ligne = document.querySelector(id_body).lastElementChild;
var nelle = ligne.cloneNode(true);
let text = nelle.querySelector('input[type="text"]');
text.value = null;
let cb = nelle.querySelector('input[type="checkbox"]')
if (cb != null) {
cb.checked = false;
}
ligne.parentNode.appendChild(nelle);
text.focus();
}
// Désactiver les champs caché des checkbox cochés
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) {
cache.disabled = true;
}
}
}
}
</script>
{{:admin_footer}}