feat: add template selector to batch detail for CV generation
This commit is contained in:
@@ -143,6 +143,17 @@ async function uploadBatchDoc(file) {
|
||||
// BATCH DETAIL VIEW
|
||||
// ============================================================
|
||||
let currentBatch = null;
|
||||
let batchTemplates = [];
|
||||
|
||||
async function loadBatchTemplates() {
|
||||
try {
|
||||
const resp = await fetch('http://' + location.hostname + ':8771/api/carbone/templates');
|
||||
const data = await resp.json();
|
||||
batchTemplates = data.templates || [];
|
||||
} catch (e) {
|
||||
batchTemplates = [];
|
||||
}
|
||||
}
|
||||
|
||||
async function openBatch(batchId) {
|
||||
currentBatchId = batchId;
|
||||
@@ -151,6 +162,8 @@ async function openBatch(batchId) {
|
||||
detail.style.display = 'block';
|
||||
detail.innerHTML = '<div class="loading">Loading batch...</div>';
|
||||
|
||||
await loadBatchTemplates();
|
||||
|
||||
try {
|
||||
const resp = await fetch('/api/batches/' + batchId);
|
||||
const data = await resp.json();
|
||||
@@ -226,6 +239,12 @@ function renderBatchDetail(data) {
|
||||
positionsHtml += '</div>';
|
||||
}
|
||||
|
||||
// Build template selector options
|
||||
const currentTemplateId = batch.template_id || '';
|
||||
const templateOptions = batchTemplates.map(t =>
|
||||
'<option value="' + t.id + '"' + (t.id === currentTemplateId ? ' selected' : '') + '>' + escapeHtml(t.name) + '</option>'
|
||||
).join('');
|
||||
|
||||
document.getElementById('batch-detail-view').innerHTML = `
|
||||
<div class="flex-between mb-16">
|
||||
<div>
|
||||
@@ -239,10 +258,40 @@ function renderBatchDetail(data) {
|
||||
<button class="btn btn-outline" onclick="closeBatchDetail()">Back</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mb-16">
|
||||
<div class="form-group" style="margin:0">
|
||||
<label>Template for CV Generation</label>
|
||||
<div class="flex gap-8">
|
||||
<select id="batch-template-select" style="flex:1" onchange="saveBatchTemplate()">
|
||||
<option value="">— Select a template —</option>
|
||||
${templateOptions}
|
||||
</select>
|
||||
${batchTemplates.length === 0 ? '<span class="text-muted text-sm">No templates uploaded. Go to Templates page to add one.</span>' : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
${positionsHtml}
|
||||
`;
|
||||
}
|
||||
|
||||
async function saveBatchTemplate() {
|
||||
const templateId = document.getElementById('batch-template-select').value;
|
||||
try {
|
||||
await fetch('/api/batches/' + currentBatchId, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name: currentBatch.batch.name,
|
||||
description: currentBatch.batch.description,
|
||||
template_id: templateId
|
||||
})
|
||||
});
|
||||
toast('Template saved for this batch');
|
||||
} catch (e) {
|
||||
toast('Error saving template: ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function closeBatchDetail() {
|
||||
document.getElementById('batches-list-view').style.display = 'block';
|
||||
document.getElementById('batch-detail-view').style.display = 'none';
|
||||
|
||||
@@ -152,6 +152,6 @@
|
||||
|
||||
<script src="/static/app.js?v=17"></script>
|
||||
<script src="/static/carbone.js?v=16"></script>
|
||||
<script src="/static/batches.js?v=1"></script>
|
||||
<script src="/static/batches.js?v=2"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user