Quelltext des aktuellen Standes
<?php
$this->layout('layouts/main', [
'page_title' => $page_title,
'current_route' => $current_route,
'full_width' => true,
'extra_css' => ['/assets/css/catalog.css?v=' . filemtime(dirname(__DIR__, 2) . '/public/assets/css/catalog.css')],
]);
$bundle = $bundle ?? null;
$id = $bundle ? (int)$bundle['id'] : 0;
$action = $id > 0 ? '/catalog/bundles/' . $id : '/catalog/bundles';
$rows = $bundle_items ?? [];
$options = '';
foreach (($all_items ?? []) as $ai) {
$options .= '<option value="' . (int)$ai['id'] . '">' . htmlspecialchars((string)$ai['name'], ENT_QUOTES) . '</option>';
}
?>
<div class="cat-wrap">
<div class="content-header">
<div>
<h1><?= $id > 0 ? 'Profil bearbeiten' : 'Neues Profil' ?></h1>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/"><?= $this->te('Home') ?></a></li>
<li class="breadcrumb-item"><a href="/catalog/bundles"><?= $this->te('Profile') ?></a></li>
<li class="breadcrumb-item active"><?= $id > 0 ? $this->e($bundle['name']) : 'Neu' ?></li>
</ol>
</div>
<div class="content-header-actions">
<a href="/catalog/bundles" class="btn btn-default"><i class="fas fa-arrow-left"></i> <?= $this->te('Abbrechen') ?></a>
</div>
</div>
<div class="page-body">
<form method="post" action="<?= $action ?>">
<input type="hidden" name="_csrf" value="<?= $this->e($this->csrf()) ?>">
<div class="detail-card">
<div class="detail-card-body">
<div class="form-group">
<label for="b-name"><?= $this->te('Name') ?> <span class="text-danger">*</span></label>
<input type="text" id="b-name" name="name" class="form-control" maxlength="200" required
value="<?= $this->e($bundle['name'] ?? '') ?>" placeholder="<?= $this->te('z. B. Arbeitsplatz Standard') ?>">
</div>
<div class="form-group">
<label for="b-desc"><?= $this->te('Beschreibung') ?></label>
<textarea id="b-desc" name="description" class="form-control" rows="2"><?= $this->e($bundle['description'] ?? '') ?></textarea>
</div>
<label class="settings-toggle">
<input type="checkbox" name="is_active" value="1" <?= (int)($bundle['is_active'] ?? 1) === 1 ? 'checked' : '' ?>>
<span class="toggle-text"><strong><?= $this->te('Aktiv') ?></strong> <small><?= $this->te('Nur aktive Profile erscheinen in der Kalkulation.') ?></small></span>
</label>
<h3 class="cat-subhead"><?= $this->te('Positionen') ?></h3>
<div id="b-rows"></div>
<button type="button" class="btn btn-default btn-sm" id="b-add"><i class="fas fa-plus"></i> <?= $this->te('Position hinzufügen') ?></button>
</div>
</div>
<div class="cat-form-actions">
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> <?= $this->te('Speichern') ?></button>
<a href="/catalog/bundles" class="btn btn-default"><?= $this->te('Abbrechen') ?></a>
</div>
</form>
</div>
</div>
<template id="b-row-tpl">
<div class="cat-brow">
<select name="item_id[]" class="form-control" data-searchable><?= $options ?></select>
<input type="number" name="quantity[]" class="form-control cat-brow-qty" value="1" min="1">
<button type="button" class="btn btn-outline-danger btn-sm cat-brow-rm" title="<?= $this->te('Entfernen') ?>">×</button>
</div>
</template>
<script>
(function () {
var host = document.getElementById('b-rows');
var tpl = document.getElementById('b-row-tpl');
function addRow(itemId, qty) {
var node = tpl.content.cloneNode(true);
var sel = node.querySelector('select');
var q = node.querySelector('input');
if (itemId) { sel.value = String(itemId); }
if (qty) { q.value = qty; }
node.querySelector('.cat-brow-rm').addEventListener('click', function () { this.closest('.cat-brow').remove(); });
host.appendChild(node);
// Nachträglich eingefügte Zeile: durchsuchbares Dropdown aufwerten
// (beim Erst-Rendern übernimmt das die globale Initialisierung).
if (window.ssInit) { window.ssInit(host); }
}
document.getElementById('b-add').addEventListener('click', function () { addRow(); });
var existing = <?= json_encode(array_map(fn($r) => ['id' => (int)$r['item_id'], 'qty' => (int)$r['quantity']], $rows), JSON_UNESCAPED_UNICODE) ?>;
if (existing.length) { existing.forEach(function (r) { addRow(r.id, r.qty); }); } else { addRow(); }
})();
</script>