05/22 Enhance codes and fix bugs 3
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
<div class="col-6 col-md-4">
|
||||
<button type="button" class="btn btn-secondary w-100 text-start template-btn"
|
||||
style="padding:10px 14px;font-size:13px;"
|
||||
data-name="{{ t.name }}"
|
||||
data-title="{{ t.title_hint }}"
|
||||
data-category="{{ t.category }}"
|
||||
data-priority="{{ t.priority }}"
|
||||
@@ -26,6 +27,23 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- Template preview panel -->
|
||||
<div id="tmpl-preview" style="display:none;margin-top:14px;padding:14px 16px;
|
||||
background:var(--surface2);border:1px solid var(--border);border-radius:8px;">
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;">
|
||||
<span style="font-size:12px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.5px;">Preview</span>
|
||||
<button type="button" id="tmpl-apply-btn" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-check2 me-1"></i>Apply Template
|
||||
</button>
|
||||
</div>
|
||||
<div style="font-size:13px;font-weight:600;color:var(--text);margin-bottom:4px;" id="tmpl-prev-title">—</div>
|
||||
<div style="display:flex;gap:6px;margin-bottom:8px;">
|
||||
<span style="font-size:11px;padding:1px 8px;border-radius:4px;background:var(--border);color:var(--muted);" id="tmpl-prev-cat">—</span>
|
||||
<span id="tmpl-prev-prio" class="badge">—</span>
|
||||
</div>
|
||||
<div style="font-size:12px;color:var(--muted);white-space:pre-wrap;line-height:1.55;max-height:100px;overflow-y:auto;" id="tmpl-prev-desc">—</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -135,33 +153,60 @@
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.querySelectorAll('.template-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const title = btn.dataset.title;
|
||||
const cat = btn.dataset.category;
|
||||
const prio = btn.dataset.priority;
|
||||
const desc = btn.dataset.description;
|
||||
(function () {
|
||||
const preview = document.getElementById('tmpl-preview');
|
||||
const applyBtn = document.getElementById('tmpl-apply-btn');
|
||||
const prevTitle = document.getElementById('tmpl-prev-title');
|
||||
const prevCat = document.getElementById('tmpl-prev-cat');
|
||||
const prevPrio = document.getElementById('tmpl-prev-prio');
|
||||
const prevDesc = document.getElementById('tmpl-prev-desc');
|
||||
|
||||
if (title) document.querySelector('input[name=title]').value = title;
|
||||
if (desc) document.querySelector('textarea[name=description]').value = desc;
|
||||
let activeData = null;
|
||||
|
||||
const catSel = document.querySelector('select[name=category]');
|
||||
if (catSel) {
|
||||
for (const opt of catSel.options) {
|
||||
if (opt.value === cat) { opt.selected = true; break; }
|
||||
}
|
||||
}
|
||||
function applyTemplate(data) {
|
||||
if (!data) return;
|
||||
if (data.title) document.querySelector('input[name=title]').value = data.title;
|
||||
if (data.desc) document.querySelector('textarea[name=description]').value = data.desc;
|
||||
const catSel = document.querySelector('select[name=category]');
|
||||
const prioSel = document.querySelector('select[name=priority]');
|
||||
if (prioSel) {
|
||||
for (const opt of prioSel.options) {
|
||||
if (opt.value === prio) { opt.selected = true; break; }
|
||||
}
|
||||
}
|
||||
// Scroll to form
|
||||
if (catSel) { for (const o of catSel.options) { if (o.value === data.cat) { o.selected = true; break; } } }
|
||||
if (prioSel) { for (const o of prioSel.options) { if (o.value === data.prio) { o.selected = true; break; } } }
|
||||
document.querySelector('input[name=title]').scrollIntoView({behavior:'smooth', block:'center'});
|
||||
document.querySelector('input[name=title]').focus();
|
||||
// Highlight briefly
|
||||
document.querySelector('input[name=title]').style.outline = '2px solid var(--accent)';
|
||||
setTimeout(() => { document.querySelector('input[name=title]').style.outline = ''; }, 1200);
|
||||
}
|
||||
|
||||
document.querySelectorAll('.template-btn').forEach(btn => {
|
||||
function showPreview() {
|
||||
activeData = {
|
||||
name: btn.dataset.name,
|
||||
title: btn.dataset.title,
|
||||
cat: btn.dataset.category,
|
||||
prio: btn.dataset.priority,
|
||||
desc: btn.dataset.description,
|
||||
};
|
||||
prevTitle.textContent = activeData.title || activeData.name;
|
||||
prevCat.textContent = (activeData.cat || '').replace(/_/g, ' ');
|
||||
prevDesc.textContent = activeData.desc || '(no description)';
|
||||
prevPrio.textContent = (activeData.prio || '').toUpperCase();
|
||||
prevPrio.className = 'badge badge-' + (activeData.prio || 'medium');
|
||||
preview.style.display = 'block';
|
||||
}
|
||||
|
||||
btn.addEventListener('mouseenter', showPreview);
|
||||
btn.addEventListener('focus', showPreview);
|
||||
btn.addEventListener('click', function () {
|
||||
showPreview();
|
||||
applyTemplate(activeData);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (applyBtn) {
|
||||
applyBtn.addEventListener('click', () => applyTemplate(activeData));
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user