OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

categories.php

7 KB
<?php $this->layout('layouts/admin', [
    'page_title'         => 'Lager-Kategorien',
    'current_admin_page' => 'stock-categories',
]); ?>

<div class="settings-page">
    <div style="display:grid;grid-template-columns:1fr 1fr;gap:1.5rem;align-items:start">

        <!-- Neue Kategorie -->
        <div class="settings-card">
            <div class="settings-card-header">
                <span class="settings-card-icon">&#43;</span>
                <div><h2><?= $this->te('Neue Kategorie') ?></h2></div>
            </div>
            <div class="settings-card-body">
                <form method="POST" action="/admin/stock/categories" class="form">
                    <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
                    <div class="form-group">
                        <label for="cat_icon"><?= $this->te('Icon (Emoji)') ?></label>
                        <input type="text" id="cat_icon" name="icon" class="form-control"
                               value="📦" maxlength="10" style="max-width:80px">
                    </div>
                    <div class="form-group">
                        <label for="cat_name"><?= $this->te('Name') ?> <span style="color:var(--red-600)">*</span></label>
                        <input type="text" id="cat_name" name="name" class="form-control"
                               required maxlength="100" placeholder="<?= $this->te('z. B. Monitor') ?>">
                    </div>
                    <div class="form-group">
                        <label for="cat_sort"><?= $this->te('Sortierung') ?></label>
                        <input type="number" id="cat_sort" name="sort_order" class="form-control"
                               value="0" min="0" max="9999" style="max-width:100px">
                    </div>
                    <button type="submit" class="btn btn-primary btn-sm"><?= $this->te('Anlegen') ?></button>
                </form>
            </div>
        </div>

        <!-- Kategorienliste -->
        <div class="settings-card">
            <div class="settings-card-header">
                <span class="settings-card-icon">&#128467;</span>
                <div><h2><?= $this->te('Vorhandene Kategorien') ?></h2></div>
            </div>
            <div class="settings-card-body" style="padding:0">
                <?php if (empty($categories)): ?>
                <p style="padding:1rem;color:var(--gray-500);font-size:.875rem"><?= $this->te('Noch keine Kategorien vorhanden.') ?></p>
                <?php else: ?>
                <table style="width:100%;border-collapse:collapse;font-size:.875rem">
                    <thead>
                        <tr style="background:var(--gray-50)">
                            <th scope="col" style="padding:.5rem .75rem;text-align:left;border-bottom:1px solid var(--gray-200)"><?= $this->te('Icon') ?></th>
                            <th scope="col" style="padding:.5rem .75rem;text-align:left;border-bottom:1px solid var(--gray-200)"><?= $this->te('Name') ?></th>
                            <th scope="col" style="padding:.5rem .75rem;text-align:center;border-bottom:1px solid var(--gray-200)"><?= $this->te('Artikel') ?></th>
                            <th scope="col" style="padding:.5rem .75rem;border-bottom:1px solid var(--gray-200)"></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($categories as $cat): ?>
                    <tr id="cat-row-<?= $cat['id'] ?>">
                        <td style="padding:.45rem .75rem;border-bottom:1px solid var(--gray-100);font-size:1.2rem">
                            <?= $this->e($cat['icon']) ?>
                        </td>
                        <td style="padding:.45rem .75rem;border-bottom:1px solid var(--gray-100);font-weight:500">
                            <span class="cat-label"><?= $this->e($cat['name']) ?></span>
                            <div class="cat-edit-form" style="display:none">
                                <form method="POST" action="/admin/stock/categories/<?= $cat['id'] ?>/update" style="display:flex;gap:.35rem;align-items:center">
                                    <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
                                    <input type="text" name="icon" value="<?= $this->e($cat['icon']) ?>" style="width:50px;padding:.25rem;border:1px solid var(--gray-300);border-radius:.3rem">
                                    <input type="text" name="name" value="<?= $this->e($cat['name']) ?>" required style="padding:.25rem .5rem;border:1px solid var(--gray-300);border-radius:.3rem">
                                    <input type="hidden" name="sort_order" value="<?= (int)$cat['sort_order'] ?>">
                                    <button aria-label="<?= $this->te('Speichern') ?>" type="submit" class="btn btn-primary btn-sm" style="padding:.2rem .6rem">&#10003;</button>
                                    <button aria-label="<?= $this->te('Schließen') ?>" type="button" class="btn btn-secondary btn-sm" style="padding:.2rem .6rem" onclick="cancelEdit(<?= $cat['id'] ?>)">&#215;</button>
                                </form>
                            </div>
                        </td>
                        <td style="padding:.45rem .75rem;border-bottom:1px solid var(--gray-100);text-align:center;color:var(--gray-500)">
                            <?= (int)$cat['item_count'] ?>
                        </td>
                        <td style="padding:.45rem .75rem;border-bottom:1px solid var(--gray-100);text-align:right;white-space:nowrap">
                            <button aria-label="<?= $this->te('Bearbeiten') ?>" class="btn btn-secondary btn-sm" style="padding:.2rem .5rem"
                                    onclick="startEdit(<?= $cat['id'] ?>)">&#9998;</button>
                            <?php if ((int)$cat['item_count'] === 0): ?>
                            <form method="POST" action="/admin/stock/categories/<?= $cat['id'] ?>/delete" style="display:inline"
                                  onsubmit="return confirm('Kategorie «<?= $this->e(addslashes($cat['name'])) ?>» wirklich löschen?')">
                                <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
                                <button type="submit" class="btn btn-sm" aria-label="<?= $this->te('Löschen') ?>" style="background:var(--red-100);color:var(--red-800);border:1px solid var(--red-300);padding:.2rem .5rem">&#128465;</button>
                            </form>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<script>
function startEdit(id) {
    document.querySelector('#cat-row-' + id + ' .cat-label').style.display = 'none';
    document.querySelector('#cat-row-' + id + ' .cat-edit-form').style.display = 'block';
}
function cancelEdit(id) {
    document.querySelector('#cat-row-' + id + ' .cat-label').style.display = '';
    document.querySelector('#cat-row-' + id + ' .cat-edit-form').style.display = 'none';
}
</script>