mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
À propos: contacts flexibles, liens sidebar éditables, grille contacts admin, et bouton supprimer
- Contacts: on peut laisser vide le nom OU le rôle (plus besoin des deux) - Sidebar: les liens « site de l'erg » et « code source » sont éditables depuis /admin/contenus-edit.php?slug=about - Admin: les champs Nom/Email/Lien des contacts s'affichent en grille 3 colonnes - Admin: icône corbeille (admin-icon-btn--delete) pour supprimer un contact, avec réindexation automatique - Database::getAproposContent() gère maintenant les valeurs string (URLs) en plus des arrays - Database::saveAproposContent() accepte array|string
This commit is contained in:
@@ -21,24 +21,34 @@
|
||||
<?php $entries = is_array($group['entries'] ?? null) ? $group['entries'] : []; ?>
|
||||
<?php foreach ($entries as $ei => $entry): ?>
|
||||
<div class="apropos-entry">
|
||||
<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'] ?? '') ?>">
|
||||
<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'] ?? '') ?>">
|
||||
<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>
|
||||
<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">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256"><path d="M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM112,168V104a8,8,0,0,1,16,0v64a8,8,0,0,1-16,0Zm48,0V104a8,8,0,0,1,16,0v64a8,8,0,0,1-16,0Z"></path></svg>
|
||||
</button>
|
||||
</fieldset>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -52,12 +62,18 @@
|
||||
|
||||
<template id="entry-template-f-<?= $aproposKey ?>">
|
||||
<div class="apropos-entry">
|
||||
<label>Entrée :</label>
|
||||
<input type="text" name="groups[{{gi}}][entries][{{ei}}][text]">
|
||||
<label>Email :</label>
|
||||
<input type="email" name="groups[{{gi}}][entries][{{ei}}][email]">
|
||||
<label>Lien (optionnel) :</label>
|
||||
<input type="url" name="groups[{{gi}}][entries][{{ei}}][url]">
|
||||
<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>
|
||||
|
||||
@@ -69,6 +85,10 @@
|
||||
<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">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256"><path d="M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM112,168V104a8,8,0,0,1,16,0v64a8,8,0,0,1-16,0Zm48,0V104a8,8,0,0,1,16,0v64a8,8,0,0,1-16,0Z"></path></svg>
|
||||
</button>
|
||||
</fieldset>
|
||||
</template>
|
||||
</form>
|
||||
@@ -81,7 +101,36 @@
|
||||
var entryTpl = document.getElementById('entry-template-f-' + key).innerHTML;
|
||||
var groupTpl = document.getElementById('group-template-f-' + key).innerHTML;
|
||||
|
||||
form.querySelectorAll('.add-entry-btn-f').forEach(function(btn) {
|
||||
function reindexGroups() {
|
||||
var fieldsets = form.querySelectorAll('fieldset.apropos-group');
|
||||
groupCount = fieldsets.length;
|
||||
fieldsets.forEach(function(fs, i) {
|
||||
var newIdx = i;
|
||||
var legend = fs.querySelector('legend');
|
||||
if (legend) legend.textContent = 'Contact ' + (newIdx + 1);
|
||||
|
||||
// Update name attributes on all inputs
|
||||
fs.querySelectorAll('input').forEach(function(inp) {
|
||||
if (inp.name) {
|
||||
inp.name = inp.name.replace(/groups\[\d+\]/, 'groups[' + newIdx + ']');
|
||||
}
|
||||
if (inp.id) {
|
||||
inp.id = inp.id.replace(/(group_f_contacts_|entry_f_contacts_)\d+/, '$1' + newIdx);
|
||||
}
|
||||
});
|
||||
|
||||
// Update for attributes on labels
|
||||
fs.querySelectorAll('label[for]').forEach(function(lbl) {
|
||||
lbl.setAttribute('for', lbl.getAttribute('for').replace(/(group_f_contacts_|entry_f_contacts_)\d+/, '$1' + newIdx));
|
||||
});
|
||||
|
||||
// Update data-group on add-entry button
|
||||
var addBtn = fs.querySelector('.add-entry-btn-f');
|
||||
if (addBtn) addBtn.dataset.group = newIdx;
|
||||
});
|
||||
}
|
||||
|
||||
function bindAddEntry(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
var gi = parseInt(this.dataset.group);
|
||||
var fieldset = this.closest('fieldset');
|
||||
@@ -89,7 +138,21 @@
|
||||
var html = entryTpl.replaceAll('{{gi}}', gi).replaceAll('{{ei}}', entryCount);
|
||||
this.insertAdjacentHTML('beforebegin', html);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindDeleteGroup(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
var fieldset = this.closest('fieldset');
|
||||
if (fieldset) {
|
||||
fieldset.remove();
|
||||
reindexGroups();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Bind existing buttons
|
||||
form.querySelectorAll('.add-entry-btn-f').forEach(bindAddEntry);
|
||||
form.querySelectorAll('.delete-group-btn-f').forEach(bindDeleteGroup);
|
||||
|
||||
form.querySelector('.add-group-btn-f').addEventListener('click', function() {
|
||||
groupCount++;
|
||||
@@ -98,17 +161,13 @@
|
||||
|
||||
var newGroup = this.previousElementSibling;
|
||||
if (newGroup && newGroup.classList.contains('apropos-group')) {
|
||||
var btn = newGroup.querySelector('.add-entry-btn-f');
|
||||
if (btn) {
|
||||
btn.dataset.group = groupCount;
|
||||
btn.addEventListener('click', function() {
|
||||
var gi = parseInt(this.dataset.group);
|
||||
var fieldset = this.closest('fieldset');
|
||||
var entryCount = fieldset.querySelectorAll('.apropos-entry').length;
|
||||
var html = entryTpl.replaceAll('{{gi}}', gi).replaceAll('{{ei}}', entryCount);
|
||||
this.insertAdjacentHTML('beforebegin', html);
|
||||
});
|
||||
var addBtn = newGroup.querySelector('.add-entry-btn-f');
|
||||
if (addBtn) {
|
||||
addBtn.dataset.group = groupCount;
|
||||
bindAddEntry(addBtn);
|
||||
}
|
||||
var delBtn = newGroup.querySelector('.delete-group-btn-f');
|
||||
if (delBtn) bindDeleteGroup(delBtn);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -28,6 +28,32 @@
|
||||
include APP_ROOT . '/templates/admin/apropos-groups-form.php';
|
||||
?>
|
||||
|
||||
<!-- ── Sidebar links ─────────────────────────────────────────────────── -->
|
||||
<h2 style="margin-top:3rem;">Liens de la barre latérale</h2>
|
||||
<form action="/admin/actions/apropos.php" method="post" class="admin-form">
|
||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
||||
<input type="hidden" name="apropos_key" value="erg_site_url">
|
||||
<label for="apropos-erg-site-url">Site de l'erg :</label>
|
||||
<input type="url" id="apropos-erg-site-url" name="url"
|
||||
value="<?= htmlspecialchars($ergSiteUrl ?? '') ?>"
|
||||
placeholder="https://erg.be">
|
||||
<div class="admin-form-footer">
|
||||
<button type="submit" class="btn btn--primary">Enregistrer</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form action="/admin/actions/apropos.php" method="post" class="admin-form" style="margin-top:var(--space-m)">
|
||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
||||
<input type="hidden" name="apropos_key" value="source_code_url">
|
||||
<label for="apropos-source-code-url">Code source :</label>
|
||||
<input type="url" id="apropos-source-code-url" name="url"
|
||||
value="<?= htmlspecialchars($sourceCodeUrl ?? '') ?>"
|
||||
placeholder="https://git.erg.school/PostERG/xamxam">
|
||||
<div class="admin-form-footer">
|
||||
<button type="submit" class="btn btn--primary">Enregistrer</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php elseif ($editType === 'page' && $pageSlug !== 'about'): ?>
|
||||
<form action="/admin/actions/page.php" method="post" class="admin-form">
|
||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION["csrf_token"]) ?>">
|
||||
|
||||
@@ -45,12 +45,12 @@ function renderEntries(array $entries): string
|
||||
<li><a href="#apropos-credits">Crédits</a></li>
|
||||
</ul>
|
||||
<div class="apropos-toc-erg">
|
||||
<a href="https://erg.be" target="_blank" rel="noopener">
|
||||
<a href="<?= htmlspecialchars($ergSiteUrl ?: 'https://erg.be') ?>" target="_blank" rel="noopener">
|
||||
Site de l'erg ↗
|
||||
</a>
|
||||
</div>
|
||||
<div class="apropos-toc-source">
|
||||
<a href="https://git.erg.school/PostERG/xamxam" target="_blank" rel="noopener">
|
||||
<a href="<?= htmlspecialchars($sourceCodeUrl ?: 'https://git.erg.school/PostERG/xamxam') ?>" target="_blank" rel="noopener">
|
||||
Code source ↗
|
||||
</a>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user