Files
xamxam/app/templates/admin/apropos-groups-form.php

99 lines
4.5 KiB
PHP

<?php
/**
* Reusable partial for apropos contacts groups form.
* Expected variables:
* $aproposKey string 'contacts'
* $groups array Existing groups data
*/
?>
<form action="/admin/actions/apropos.php" method="post" class="admin-form" id="apropos-form-<?= $aproposKey ?>"
hx-post="/admin/actions/apropos.php"
hx-trigger="change delay:1500ms, input delay:1500ms"
hx-swap="none"
hx-on::after-request="handleAutosaveResponse(event)"
data-apropos-key="<?= $aproposKey ?>"
data-apropos-group-count="<?= count($groups) ?>">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<input type="hidden" name="apropos_key" value="<?= htmlspecialchars($aproposKey) ?>">
<?php foreach ($groups as $gi => $group): ?>
<fieldset class="apropos-group">
<legend>Contact <?= $gi + 1 ?></legend>
<label for="group_f_<?= $aproposKey ?>_<?= $gi ?>_role">Rôle :</label>
<input type="text" id="group_f_<?= $aproposKey ?>_<?= $gi ?>_role"
name="groups[<?= $gi ?>][role]"
value="<?= htmlspecialchars($group['role'] ?? '') ?>">
<?php $entries = is_array($group['entries'] ?? null) ? $group['entries'] : []; ?>
<?php foreach ($entries as $ei => $entry): ?>
<div class="apropos-entry">
<div>
<label for="entry_f_<?= $aproposKey ?>_<?= $gi ?>_<?= $ei ?>_text">Nom :</label>
<input type="text" id="entry_f_<?= $aproposKey ?>_<?= $gi ?>_<?= $ei ?>_text"
name="groups[<?= $gi ?>][entries][<?= $ei ?>][text]"
value="<?= htmlspecialchars($entry['text'] ?? '') ?>">
</div>
<div>
<label for="entry_f_<?= $aproposKey ?>_<?= $gi ?>_<?= $ei ?>_email">Email :</label>
<input type="email" id="entry_f_<?= $aproposKey ?>_<?= $gi ?>_<?= $ei ?>_email"
name="groups[<?= $gi ?>][entries][<?= $ei ?>][email]"
value="<?= htmlspecialchars($entry['email'] ?? '') ?>">
</div>
<div>
<label for="entry_f_<?= $aproposKey ?>_<?= $gi ?>_<?= $ei ?>_url">Lien (optionnel) :</label>
<input type="url" id="entry_f_<?= $aproposKey ?>_<?= $gi ?>_<?= $ei ?>_url"
name="groups[<?= $gi ?>][entries][<?= $ei ?>][url]"
value="<?= htmlspecialchars($entry['url'] ?? '') ?>">
</div>
</div>
<?php endforeach; ?>
<button type="button" class="btn btn--primary btn--sm add-entry-btn-f"
data-group="<?= $gi ?>"
data-key="<?= $aproposKey ?>">+ Ajouter une entrée</button>
<button type="button" class="admin-icon-btn admin-icon-btn--delete delete-group-btn-f"
data-key="<?= $aproposKey ?>" title="Supprimer ce contact">
<?= icon('trash-slash') ?>
</button>
</fieldset>
<?php endforeach; ?>
<button type="button" class="btn btn--primary add-group-btn-f"
data-key="<?= $aproposKey ?>">+ Ajouter un contact</button>
<div class="autosave-status" data-autosave-status></div>
<template id="entry-template-f-<?= $aproposKey ?>">
<div class="apropos-entry">
<div>
<label>Nom :</label>
<input type="text" name="groups[{{gi}}][entries][{{ei}}][text]">
</div>
<div>
<label>Email :</label>
<input type="email" name="groups[{{gi}}][entries][{{ei}}][email]">
</div>
<div>
<label>Lien (optionnel) :</label>
<input type="url" name="groups[{{gi}}][entries][{{ei}}][url]">
</div>
</div>
</template>
<template id="group-template-f-<?= $aproposKey ?>">
<fieldset class="apropos-group">
<legend>Contact {{gi}}</legend>
<label>Rôle :</label>
<input type="text" name="groups[{{gi}}][role]">
<button type="button" class="btn btn--primary btn--sm add-entry-btn-f"
data-group="{{gi}}"
data-key="<?= $aproposKey ?>">+ Ajouter une entrée</button>
<button type="button" class="admin-icon-btn admin-icon-btn--delete delete-group-btn-f"
data-key="<?= $aproposKey ?>" title="Supprimer ce contact">
<?= icon('trash-slash') ?>
</button>
</fieldset>
</template>
</form>
<script src="<?= App::assetV('/assets/js/app/admin-contacts-form.js') ?>"></script>