Backup #2140

ID2140
Dateipfad/var/www/dev.campus.systemische-tools.de/src/View/config/form.php
Version4
Typ modified
Größe7.0 KB
Hash8b691df9a63cbf2005dd8aa03ec9148410a7d3f2eb1c624bc07589cf1658c647
Datum2025-12-30 20:33:46
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php ob_start(); ?>

<h1><?= $isEdit ? 'Bearbeiten: ' . htmlspecialchars($config['name']) : 'Neue Konfiguration' ?></h1>


<form class="form"
      hx-post="<?= $isEdit ? '/config/' . $config['id'] : '/config' ?>"
      hx-headers='{"X-CSRF-TOKEN": "<?= $csrfToken ?>"}'
      hx-disabled-elt="button[type=submit]">

    <div class="form-row">
        <div class="form-group form-group--half">
            <label for="type">Typ *</label>
            <select name="type" id="type" class="form-select" <?= $isEdit ? 'disabled' : 'required' ?>>
                <option value="">-- Typ wählen --</option>
                <?php foreach ($types as $type): ?>
                <option value="<?= $type ?>" <?= ($config['type'] ?? '') === $type ? 'selected' : '' ?>><?= $typeLabels[$type] ?? $type ?></option>
                <?php endforeach; ?>
            </select>
            <?php if ($isEdit): ?>
            <input type="hidden" name="type" value="<?= $config['type'] ?>">
            <?php endif; ?>
        </div>
        <div class="form-group form-group--half">
            <label for="status">Status</label>
            <select name="status" id="status" class="form-select">
                <option value="draft" <?= ($config['status'] ?? 'draft') === 'draft' ? 'selected' : '' ?>>Entwurf</option>
                <option value="active" <?= ($config['status'] ?? '') === 'active' ? 'selected' : '' ?>>Aktiv</option>
                <option value="deprecated" <?= ($config['status'] ?? '') === 'deprecated' ? 'selected' : '' ?>>Deprecated</option>
            </select>
        </div>
    </div>

    <div class="form-row">
        <div class="form-group form-group--half">
            <label for="name">Name *</label>
            <input type="text" name="name" id="name" class="form-input" value="<?= htmlspecialchars($config['name'] ?? '') ?>" required>
        </div>
        <div class="form-group form-group--half">
            <label for="slug">Slug *</label>
            <input type="text" name="slug" id="slug" class="form-input" value="<?= htmlspecialchars($config['slug'] ?? '') ?>" required pattern="[a-z0-9-]+">
            <small>Nur Kleinbuchstaben, Zahlen und Bindestriche</small>
        </div>
    </div>

    <div class="form-row">
        <div class="form-group form-group--half">
            <label for="version"><?= $isEdit ? 'Neue Version *' : 'Version' ?></label>
            <input type="text" name="<?= $isEdit ? 'new_version' : 'version' ?>" id="version" class="form-input"
                   value="<?= $isEdit ? '' : htmlspecialchars($config['version'] ?? '1.0') ?>"
                   placeholder="<?= $isEdit ? 'z.B. ' . $this->incrementVersion($config['version'] ?? '1.0') : '1.0' ?>"
                   <?= $isEdit ? 'required' : '' ?>>
            <?php if ($isEdit): ?>
            <small>Aktuelle Version: <?= htmlspecialchars($config['version']) ?></small>
            <?php endif; ?>
        </div>
        <div class="form-group form-group--half">
            <label for="parent_id">Parent (optional)</label>
            <select name="parent_id" id="parent_id" class="form-select">
                <option value="">-- Kein Parent --</option>
                <?php foreach ($parents as $parent): ?>
                <option value="<?= $parent['id'] ?>" <?= ($config['parent_id'] ?? '') == $parent['id'] ? 'selected' : '' ?>>
                    [<?= $typeLabels[$parent['type']] ?? $parent['type'] ?>] <?= htmlspecialchars($parent['name']) ?>
                </option>
                <?php endforeach; ?>
            </select>
            <small>Nur für Rules: Verknüpfung zu Contract/Organization</small>
        </div>
    </div>

    <div class="form-group">
        <label for="description">Beschreibung</label>
        <textarea name="description" id="description" class="form-textarea" rows="2"><?= htmlspecialchars($config['description'] ?? '') ?></textarea>
    </div>

    <?php if ($isEdit): ?>
    <div class="form-group">
        <label for="change_description">Änderungsbeschreibung</label>
        <input type="text" name="change_description" id="change_description" class="form-input" placeholder="Was wurde geändert?">
    </div>
    <?php endif; ?>

    <div class="form-group">
        <label for="content">Content (JSON) *</label>
        <textarea name="content" id="content" class="form-textarea form-textarea--code" rows="15" required><?= htmlspecialchars($config['content'] ?? '{}') ?></textarea>
        <small>
            <button type="button" class="btn btn--small btn--secondary" onclick="formatJson()">JSON formatieren</button>
            <button type="button" class="btn btn--small btn--secondary" onclick="validateJson()">JSON prüfen</button>
            <span id="json-status"></span>
        </small>
    </div>

    <div class="form-actions">
        <button type="submit" class="btn btn--primary"><?= $isEdit ? 'Speichern' : 'Erstellen' ?></button>
        <a href="<?= $isEdit ? '/config/' . $config['id'] : '/config' ?>" class="btn btn--secondary">Abbrechen</a>
    </div>
</form>

<?php if ($isEdit): ?>
<hr>
<h3>Gefahrenzone</h3>
<button type="button" class="btn btn--danger"
        hx-post="/config/<?= $config['id'] ?>/delete"
        hx-headers='{"X-CSRF-TOKEN": "<?= $csrfToken ?>"}'
        hx-confirm="Wirklich loeschen? Diese Aktion kann nicht rueckgaengig gemacht werden."
        hx-disabled-elt="this">
    Konfiguration loeschen
</button>
<?php endif; ?>

<script>
// Auto-generate slug from name
document.getElementById('name')?.addEventListener('input', function() {
    const slugField = document.getElementById('slug');
    if (slugField && !slugField.dataset.manual) {
        slugField.value = this.value
            .toLowerCase()
            .replace(/[äöüß]/g, m => ({ä:'ae',ö:'oe',ü:'ue',ß:'ss'}[m]))
            .replace(/[^a-z0-9]+/g, '-')
            .replace(/^-|-$/g, '');
    }
});

document.getElementById('slug')?.addEventListener('input', function() {
    this.dataset.manual = 'true';
});

function formatJson() {
    const textarea = document.getElementById('content');
    try {
        const obj = JSON.parse(textarea.value);
        textarea.value = JSON.stringify(obj, null, 2);
        document.getElementById('json-status').innerHTML = '<span style="color:green">Formatiert</span>';
    } catch (e) {
        document.getElementById('json-status').innerHTML = '<span style="color:red">Ungültiges JSON: ' + e.message + '</span>';
    }
}

function validateJson() {
    const textarea = document.getElementById('content');
    try {
        JSON.parse(textarea.value);
        document.getElementById('json-status').innerHTML = '<span style="color:green">Gültiges JSON</span>';
    } catch (e) {
        document.getElementById('json-status').innerHTML = '<span style="color:red">Ungültiges JSON: ' + e.message + '</span>';
    }
}

// Initial validation
validateJson();
</script>

<style>
.form-textarea--code {
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    tab-size: 2;
}
</style>

<?php $content = ob_get_clean(); ?>
<?php require VIEW_PATH . '/layout.php'; ?>

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
2146 8 modified 8.7 KB 2025-12-30 20:41
2145 7 modified 8.7 KB 2025-12-30 20:41
2144 6 modified 8.5 KB 2025-12-30 20:40
2141 5 modified 8.2 KB 2025-12-30 20:34
2140 4 modified 7.0 KB 2025-12-30 20:33
1779 3 modified 7.2 KB 2025-12-27 14:05
1765 2 modified 7.1 KB 2025-12-27 12:53
1764 1 modified 7.1 KB 2025-12-27 12:53

← Zurück zur Übersicht