templates
This commit is contained in:
@@ -30,6 +30,18 @@
|
||||
.logo-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
|
||||
.logo-row input { flex: 1; background: #2a2a2a; border: 1px solid #444; color: #eee; padding: 6px 10px; border-radius: 4px; font-size: 12px; }
|
||||
.logo-row label { font-size: 12px; color: #aaa; white-space: nowrap; }
|
||||
|
||||
.version-panel { background: #222; border: 1px solid #444; border-radius: 6px; padding: 16px; margin-bottom: 20px; }
|
||||
.version-list { margin-top: 10px; max-height: 200px; overflow-y: auto; }
|
||||
.version-item { display: flex; justify-content: space-between; align-items: center; padding: 8px; border-bottom: 1px solid #333; font-size: 13px; }
|
||||
.version-item:hover { background: #2a2a2a; }
|
||||
.version-info { flex: 1; cursor: pointer; }
|
||||
.version-name { font-weight: bold; color: #C9A84C; }
|
||||
.version-date { font-size: 11px; color: #777; margin-top: 2px; }
|
||||
.version-actions { display: flex; gap: 8px; }
|
||||
.v-btn { padding: 4px 8px; font-size: 11px; }
|
||||
.save-form { display: flex; gap: 8px; margin-top: 10px; }
|
||||
.save-form input { flex: 1; background: #333; border: 1px solid #444; color: #eee; padding: 8px; border-radius: 4px; font-size: 13px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -43,6 +55,17 @@
|
||||
<main>
|
||||
<div class="layout">
|
||||
<div class="panel">
|
||||
<div class="version-panel">
|
||||
<h2>Saved Versions</h2>
|
||||
<div class="save-form">
|
||||
<input id="v-name" placeholder="Version Name (e.g. Holiday 2026)"/>
|
||||
<button onclick="saveVersion()" class="v-btn">Save As Version</button>
|
||||
</div>
|
||||
<div class="version-list" id="version-list">
|
||||
<div style="color:#777; padding: 10px;">Loading versions...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Handlebars Template (HTML)</h2>
|
||||
<textarea id="template-editor" spellcheck="false"></textarea>
|
||||
<div class="actions">
|
||||
@@ -80,9 +103,67 @@
|
||||
async function saveTemplate() {
|
||||
const content = document.getElementById('template-editor').value;
|
||||
const res = await fetch('/api/admin/template',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({content})}).then(r=>r.json());
|
||||
showStatus(res.ok ? 'Template saved! A .bak backup was created.' : 'Error: '+res.error, res.ok);
|
||||
showStatus(res.ok ? 'Template deployed! A .bak backup was created.' : 'Error: '+res.error, res.ok);
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
async function loadVersions() {
|
||||
const versions = await fetch('/api/admin/versions').then(r=>r.json()).catch(()=>[]);
|
||||
const list = document.getElementById('version-list');
|
||||
if (!versions.length) {
|
||||
list.innerHTML = '<div style="color:#777; padding:10px;">No saved versions yet.</div>';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = versions.map(v => `
|
||||
<div class="version-item">
|
||||
<div class="version-info" onclick="loadVersionData(${v.id})">
|
||||
<div class="version-name">${v.name}</div>
|
||||
<div class="version-date">${new Date(v.updated_at).toLocaleString()}</div>
|
||||
</div>
|
||||
<div class="version-actions">
|
||||
<button class="secondary v-btn" onclick="deployVersion(${v.id})">Deploy</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function saveVersion() {
|
||||
const name = document.getElementById('v-name').value.trim();
|
||||
const content = document.getElementById('template-editor').value;
|
||||
if (!name) return alert('Enter a version name.');
|
||||
|
||||
const res = await fetch('/api/admin/versions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, content })
|
||||
}).then(r=>r.json());
|
||||
|
||||
if (res.ok) {
|
||||
showStatus('Version saved!', true);
|
||||
document.getElementById('v-name').value = '';
|
||||
loadVersions();
|
||||
} else {
|
||||
showStatus('Error: '+res.error, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadVersionData(id) {
|
||||
const v = await fetch(`/api/admin/versions/${id}`).then(r=>r.json());
|
||||
document.getElementById('template-editor').value = v.content;
|
||||
document.getElementById('v-name').value = v.name;
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
async function deployVersion(id) {
|
||||
if (!confirm('Set this version as the ACTIVE template?')) return;
|
||||
const res = await fetch(`/api/admin/versions/${id}/deploy`, { method: 'POST' }).then(r=>r.json());
|
||||
if (res.ok) {
|
||||
showStatus('Version deployed and active!', true);
|
||||
} else {
|
||||
showStatus('Error: '+res.error, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function updatePreview() {
|
||||
const templateHtml = document.getElementById('template-editor').value;
|
||||
const userData = {
|
||||
@@ -102,6 +183,7 @@
|
||||
setTimeout(()=>{ el.style.display='none'; }, 5000);
|
||||
}
|
||||
loadTemplate();
|
||||
loadVersions();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user