OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

edit.php

9 KB
<?php $this->layout('layouts/admin', [
    'page_title' => 'Vorlage bearbeiten',
    'current_admin_page' => 'page-templates',
]); ?>

<?php $template = $template ?? []; ?>

<div class="settings-page">

    <div class="page-back-nav">
        <a href="/admin/page-templates" class="btn btn-sm btn-secondary"><?= $this->te('&larr; Zurรผck zu Vorlagen') ?></a>
    </div>

    <form action="/admin/page-templates/<?= $template['id'] ?>" method="POST">
        <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
        <input type="hidden" name="_method" value="PUT">

        <!-- Vorlagen-Einstellungen -->
        <section class="settings-card">
            <div class="settings-card-header">
                <span class="settings-card-icon"><?= $template['icon'] ?></span>
                <div>
                    <h2><?= $this->e($template['name']) ?></h2>
                    <p class="settings-card-desc"><?= $this->te('Vorlagen-Einstellungen und Metadaten bearbeiten.') ?></p>
                </div>
            </div>
            <div class="settings-card-body">
                <div class="form-row-2">
                    <div class="form-group">
                        <label for="tpl-name"><?= $this->te('Name') ?></label>
                        <input type="text" id="tpl-name" name="name" class="form-control" value="<?= $this->e($template['name']) ?>" required maxlength="255">
                    </div>
                    <div class="form-group">
                        <label for="tpl-category"><?= $this->te('Kategorie') ?></label>
                        <input type="text" id="tpl-category" name="category" class="form-control" value="<?= $this->e($template['category']) ?>">
                    </div>
                </div>
                <div class="form-row-2">
                    <div class="form-group" style="max-width:220px;">
                        <label for="tpl-icon"><?= $this->te('Icon') ?></label>
                        <select id="tpl-icon" name="icon" class="form-control icon-select">
                            <?php
                            $icons = [
                                '๐Ÿ“„' => 'Dokument', '๐Ÿ–ฅ' => 'Server', '๐Ÿ’ป' => 'Laptop', '๐Ÿ–จ' => 'PC',
                                '๐ŸŒ' => 'Netzwerk', '๐Ÿ”’' => 'Sicherheit', '๐Ÿ”' => 'Schlรผssel', '๐Ÿ”ง' => 'Werkzeug',
                                'โš™' => 'Zahnrad', '๐Ÿ”Œ' => 'Stecker', '๐Ÿ“ก' => 'Fax/Drucker', 'โœ‰' => 'E-Mail',
                                '๐Ÿ“ž' => 'Telefon', '๐Ÿ“ฑ' => 'Smartphone', 'โ˜' => 'Cloud', '๐Ÿ“Š' => 'Diagramm',
                                '๐Ÿ“ˆ' => 'Statistik', '๐Ÿ“‹' => 'Checkliste', '๐Ÿ“' => 'Notiz', '๐Ÿ“š' => 'Buecher',
                                '๐Ÿ”' => 'Suche', '๐Ÿ”—' => 'Link', '๐ŸŽฎ' => 'Steuerung', '๐Ÿ› ' => 'Wartung',
                                '๐Ÿš€' => 'Rakete', 'โš ' => 'Warnung', '๐Ÿšจ' => 'Alarm', 'โœ…' => 'Erledigt',
                                'โŒ' => 'Fehler', '๐Ÿ‘ค' => 'Person', '๐Ÿ‘ฅ' => 'Team', '๐Ÿข' => 'Firma',
                                '๐Ÿ’ฐ' => 'Finanzen', '๐Ÿ“…' => 'Kalender', '๐Ÿ•' => 'Uhr', '๐Ÿ’พ' => 'Datenbank',
                                '๐Ÿ“ฆ' => 'Paket', '๐Ÿ“‘' => 'Formular', '๐Ÿ’ก' => 'Idee', '๐ŸŽฏ' => 'Ziel',
                            ];
                            $currentIcon = $template['icon'] ?? '๐Ÿ“„';
                            $found = false;
                            foreach ($icons as $emoji => $label):
                                $sel = ($emoji === $currentIcon) ? 'selected' : '';
                                if ($sel) $found = true;
                            ?>
                            <option value="<?= $emoji ?>" <?= $sel ?>><?= $emoji ?> <?= $label ?></option>
                            <?php endforeach; ?>
                            <?php if (!$found): ?>
                            <option value="<?= $this->e($currentIcon) ?>" selected><?= $this->te('{icon} (Aktuell)', ['icon' => $currentIcon]) ?></option>
                            <?php endif; ?>
                        </select>
                    </div>
                    <div class="form-group" style="max-width:120px;">
                        <label for="tpl-sort"><?= $this->te('Reihenfolge') ?></label>
                        <input type="number" id="tpl-sort" name="sort_order" class="form-control" value="<?= $template['sort_order'] ?>" min="0">
                    </div>
                </div>
                <div class="form-group">
                    <label for="tpl-desc"><?= $this->te('Beschreibung') ?></label>
                    <input type="text" id="tpl-desc" name="description" class="form-control" value="<?= $this->e($template['description'] ?? '') ?>" maxlength="500" placeholder="<?= $this->te('Kurze Beschreibung der Vorlage...') ?>">
                    <small class="form-hint"><?= $this->te('Wird beim Auswaehlen der Vorlage angezeigt.') ?></small>
                </div>
                <div class="form-group">
                    <label class="settings-toggle">
                        <input type="checkbox" name="is_active" value="1" <?= $template['is_active'] ? 'checked' : '' ?>>
                        <span class="toggle-text">
                            <strong><?= $this->te('Aktiv') ?></strong>
                            <small><?= $this->te('Wird bei neuen Seiten als Vorlage angeboten.') ?></small>
                        </span>
                    </label>
                </div>
            </div>
        </section>

        <!-- Vorlagen-Inhalt -->
        <section class="settings-card">
            <div class="settings-card-header">
                <span class="settings-card-icon">&#128221;</span>
                <div>
                    <h2><?= $this->te('Vorlagen-Inhalt') ?></h2>
                    <p class="settings-card-desc"><?= $this->te('Der HTML-Inhalt, der beim Erstellen einer neuen Seite eingefuegt wird.') ?></p>
                </div>
            </div>
            <div class="settings-card-body">
                <textarea name="content_html" id="tpl-content"><?= $this->e($template['content_html'] ?? '') ?></textarea>
            </div>
        </section>

        <div class="form-actions-bar">
            <button type="submit" class="btn btn-primary"><?= $this->te('Speichern') ?></button>
            <a href="/admin/page-templates" class="btn btn-secondary"><?= $this->te('Abbrechen') ?></a>
        </div>
    </form>
</div>

<?php if (TINYMCE_INSTALLED): ?>
<script src="<?= $this->asset('/assets/tinymce/tinymce.min.js') ?>"></script>
<script>
tinymce.init({
    selector: '#tpl-content',
    height: 500,
    language: 'de',
    language_url: '/assets/tinymce/langs/de.js',
    plugins: [
        'advlist', 'autolink', 'lists', 'link', 'charmap',
        'searchreplace', 'visualblocks', 'code', 'fullscreen',
        'insertdatetime', 'table', 'help', 'wordcount', 'codesample'
    ],
    toolbar: [
        'undo redo | blocks | bold italic underline | forecolor backcolor removeformat',
        'alignleft aligncenter alignright | bullist numlist outdent indent | table link codesample | code fullscreen'
    ],
    menubar: false,
    promotion: false,
    branding: false,
    license_key: 'gpl',
    content_style: 'body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 16px; line-height: 1.7; color: #1f2937; padding: 1rem; } table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #d1d5db; padding: 0.75rem; } th { background: #f3f4f6; font-weight: 600; }'
});
</script>
<?php else: ?>
<link rel="stylesheet" href="<?= $this->asset('/assets/css/wysiwyg.css') ?>">
<script src="<?= $this->asset('/assets/js/wysiwyg.js') ?>"></script>
<script>
(function() {
    var ta   = document.getElementById('tpl-content');
    var wrap = document.createElement('div');
    wrap.className = 'wysiwyg-editor-container';
    ta.parentNode.insertBefore(wrap, ta);
    wrap.appendChild(ta);
    new OpenNIT.WysiwygEditor(wrap, {
        uploadUrl: '/upload/image',
        csrfToken: document.querySelector('input[name="_csrf"]')?.value || ''
    });
}());
</script>
<?php endif; ?>

<style>
.page-back-nav {
    margin-bottom: 1rem;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions-bar {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.settings-toggle {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
}

.settings-toggle input {
    margin-top: 0.2em;
}

.toggle-text strong {
    display: block;
    font-size: var(--font-size-sm, 0.875rem);
}

.toggle-text small {
    display: block;
    color: var(--color-text-muted, var(--gray-500));
    font-size: var(--font-size-xs, 0.75rem);
}

@media (max-width: 640px) {
    .form-row-2 {
        grid-template-columns: 1fr;
    }
}

.icon-select {
    font-size: 1.1rem;
    padding: 0.375rem 0.5rem;
}
</style>