diff --git a/public/assets/js/ui-editor.js b/public/assets/js/ui-editor.js index a380ecf..7650fa9 100644 --- a/public/assets/js/ui-editor.js +++ b/public/assets/js/ui-editor.js @@ -266,7 +266,7 @@ export function initEditor() { versionItems = items || []; if (!versionSelect) return; const rows = Array.isArray(versionItems) ? versionItems : []; - versionSelect.innerHTML = ''; + versionSelect.innerHTML = ''; if (!rows.length) { const opt = document.createElement('option'); opt.value = ''; @@ -277,18 +277,17 @@ export function initEditor() { return; } versionSelect.disabled = false; - rows.forEach((item) => { + rows.forEach((item, idx) => { const opt = document.createElement('option'); const label = `#${item.version_no} – ${formatVersionDate(item.created_at)}`; opt.value = String(item.id); opt.textContent = label; versionSelect.appendChild(opt); + if (!lastVersionSelection && idx === 0) { + lastVersionSelection = String(item.id); + } }); - if (lastVersionSelection) { - versionSelect.value = lastVersionSelection; - } else { - versionSelect.value = ''; - } + if (lastVersionSelection) versionSelect.value = lastVersionSelection; } async function loadVersionsForCurrent() { diff --git a/src/ApiKernel.php b/src/ApiKernel.php index 801ee59..4285201 100644 --- a/src/ApiKernel.php +++ b/src/ApiKernel.php @@ -857,6 +857,16 @@ class ApiKernel foreach ($data as $k => $v) $stmt->bindValue(":$k", $v); $stmt->execute(); $newId = (int)$this->pdo->lastInsertId(); + try { + $stmt = $this->pdo->prepare("SELECT * FROM `$itemsTable` WHERE `id` = :id AND `customer_id` = :cid LIMIT 1"); + $stmt->execute([':id' => $newId, ':cid' => $customerId]); + $row = $stmt->fetch(); + if ($row) { + $this->createContentVersion($row, $itemCols, $customerId, (int)$section['id']); + } + } catch (Throwable $e) { + // ignore versioning failures on create + } $this->respond(['ok' => true, 'kind' => 'content', 'id' => $newId, 'item' => ['id' => $newId, 'name' => $name]]); }