dealspace/portal/templates/app/request.html

525 lines
27 KiB
HTML

{{define "header-left"}}
<div class="flex items-center gap-3">
<a href="/app/projects" class="text-xl font-bold text-white tracking-tight"><span class="text-[#c9a84c]">Deal</span>space</a>
<span class="text-white/20">/</span>
<a href="/app/projects" class="text-sm text-[#94a3b8] hover:text-white transition">Projects</a>
<span class="text-white/20">/</span>
<a id="backToProject" href="/app/projects" class="text-sm text-[#94a3b8] hover:text-white transition">Project</a>
<span class="text-white/20">/</span>
<span id="reqRef" class="text-sm text-white font-medium">Request</span>
</div>
{{end}}
{{define "content"}}
<div class="p-8 max-w-6xl">
<!-- Two-column layout: Request + Response -->
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6 mb-6">
<!-- LEFT: Request -->
<div class="lg:col-span-7 bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6">
<div class="flex items-center gap-2 mb-5">
<span class="text-lg">&#128203;</span>
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider">Request</h2>
</div>
<div class="flex items-start gap-3 mb-4">
<h1 id="reqTitle" class="text-base font-semibold text-white leading-snug flex-1">Loading...</h1>
<button id="editReqBtn" onclick="startEditRequest()" class="shrink-0 p-1.5 rounded-lg hover:bg-white/[0.08] text-[#94a3b8] hover:text-white transition" title="Edit request">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
</button>
<span id="reqItemBadge" class="hidden shrink-0 px-2.5 py-1 rounded-md bg-[#c9a84c]/15 text-[#c9a84c] text-xs font-semibold"></span>
</div>
<p id="reqDesc" class="text-[#94a3b8] text-sm leading-relaxed mb-5"></p>
<!-- Edit mode form -->
<div id="reqEditMode" class="hidden mb-5">
<div class="space-y-3">
<div>
<label class="block text-xs font-medium text-[#94a3b8] mb-1">Title</label>
<input type="text" id="editReqTitle" class="w-full px-3 py-2 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white text-sm focus:outline-none focus:border-[#c9a84c]">
</div>
<div>
<label class="block text-xs font-medium text-[#94a3b8] mb-1">Description</label>
<textarea id="editReqDesc" rows="3" class="w-full px-3 py-2 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white text-sm focus:outline-none focus:border-[#c9a84c] resize-none"></textarea>
</div>
<div class="flex gap-3">
<div class="flex-1">
<label class="block text-xs font-medium text-[#94a3b8] mb-1">Priority</label>
<select id="editReqPriority" class="w-full px-3 py-2 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white text-sm focus:outline-none focus:border-[#c9a84c]">
<option value="critical">Critical</option>
<option value="high">High</option>
<option value="medium">Medium</option>
<option value="low">Low</option>
</select>
</div>
<div class="flex-1">
<label class="block text-xs font-medium text-[#94a3b8] mb-1">Status</label>
<select id="editReqStatus" class="w-full px-3 py-2 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white text-sm focus:outline-none focus:border-[#c9a84c]">
<option value="open">Open</option>
<option value="in_process">In Process</option>
<option value="partial">Partial</option>
<option value="complete">Complete</option>
</select>
</div>
</div>
<div class="flex gap-2">
<button onclick="saveEditRequestDetail()" class="px-4 py-2 bg-[#c9a84c] hover:bg-[#b8973f] text-[#0a1628] font-semibold rounded-lg text-sm transition">Save</button>
<button onclick="cancelEditRequestDetail()" class="px-4 py-2 bg-white/[0.05] hover:bg-white/[0.08] text-white rounded-lg text-sm transition">Cancel</button>
</div>
</div>
</div>
<div id="reqMetaBar" class="border-t border-white/[0.06] pt-4 flex flex-wrap items-center gap-3">
<span id="reqPriority" class="hidden px-2.5 py-1 rounded-full text-xs font-medium"></span>
<span id="reqDue" class="hidden text-xs text-[#475569]"></span>
<span id="reqStatus" class="px-2.5 py-1 rounded-full text-xs font-medium capitalize"></span>
</div>
</div>
<!-- RIGHT: Response -->
<div class="lg:col-span-5 bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6 flex flex-col">
<div class="flex items-center gap-2 mb-5">
<span class="text-lg">&#128193;</span>
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider">Response</h2>
</div>
<div id="answeredBanner" class="hidden mb-4 px-4 py-2.5 rounded-lg bg-green-500/10 border border-green-500/20 text-green-300 text-sm font-medium flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
Answered
</div>
<div id="answers" class="space-y-2 mb-4 flex-1"></div>
<div id="uploadArea" class="border-2 border-dashed border-white/[0.08] rounded-xl p-6 text-center hover:border-[#c9a84c]/40 transition cursor-pointer" onclick="document.getElementById('fileInput').click()">
<div class="text-2xl mb-1">&#128206;</div>
<p class="text-[#94a3b8] text-sm">Drop files to submit response</p>
<p class="text-[#475569] text-xs mt-1">PDF, DOCX, XLSX, images</p>
<input id="fileInput" type="file" multiple class="hidden" onchange="uploadFiles(this.files)">
</div>
<div id="uploadStatus" class="mt-2 text-sm text-[#94a3b8]"></div>
<button id="markAnsweredBtn" onclick="markAnswered()" class="hidden mt-4 w-full px-4 py-2.5 bg-green-600 hover:bg-green-700 text-white font-semibold rounded-lg text-sm transition flex items-center justify-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
Mark as Answered
</button>
</div>
</div>
<!-- BOTTOM: Discussion (channel-based) -->
<div class="bg-[#0d1f3c] border border-white/[0.08] rounded-xl overflow-hidden">
<!-- Channel tabs -->
<div class="border-b border-white/[0.08] flex items-center gap-0 overflow-x-auto" id="channelTabs">
<div class="px-4 py-3 text-xs text-[#475569]">Loading channels...</div>
</div>
<!-- Messages -->
<div id="channelComments" class="p-6 space-y-4 min-h-[120px] max-h-[480px] overflow-y-auto">
<p class="text-[#475569] text-sm">Select a channel above.</p>
</div>
<!-- Compose -->
<div id="commentComposer" class="border-t border-white/[0.08] p-4">
<div id="composeReadOnly" class="hidden py-1 text-xs text-[#475569] text-center">Read only in this channel.</div>
<div id="composeForm" class="flex gap-3 items-end">
<textarea id="commentText" rows="2" placeholder="Post an announcement..."
class="flex-1 px-4 py-2.5 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white placeholder-[#475569] focus:outline-none focus:border-[#c9a84c] focus:ring-1 focus:ring-[#c9a84c] text-sm resize-none"></textarea>
<button onclick="postComment(null)"
class="px-4 py-2.5 bg-[#c9a84c] hover:bg-[#b8973f] text-[#0a1628] font-semibold rounded-lg text-sm transition shrink-0">Post</button>
</div>
</div>
</div>
</div>
{{end}}
{{define "scripts"}}
<script>
const reqID = location.pathname.split('/').pop();
const statusColors = { open: 'bg-yellow-500/20 text-yellow-300', answered: 'bg-green-500/20 text-green-300', closed: 'bg-gray-500/20 text-gray-300', 'under-review': 'bg-blue-500/20 text-blue-300' };
const priorityColors = { high: 'bg-red-500/20 text-red-300', medium: 'bg-yellow-500/20 text-yellow-300', low: 'bg-blue-500/20 text-blue-300' };
let currentRequest = null;
let currentData = null;
let currentAnswers = [];
async function applyRoleRestrictions() {
try {
const res = await fetchAPI('/api/auth/me');
if (!res.ok) return;
const me = await res.json();
const role = me.test_role || '';
const isReadOnly = role === 'buyer' || role === 'seller' || role === 'advisor';
if (isReadOnly) {
const ua = document.getElementById('uploadArea');
if (ua) ua.style.display = 'none';
const mb = document.getElementById('markAnsweredBtn');
if (mb) mb.style.display = 'none';
const eb = document.getElementById('editReqBtn');
if (eb) eb.style.display = 'none';
const cc = document.getElementById('commentComposer');
if (cc) cc.style.display = 'none';
}
} catch(e) {}
}
async function loadAll() {
try {
const res = await fetchAPI('/api/requests/' + reqID);
if (!res.ok) { document.getElementById('reqTitle').textContent = 'Not found'; return; }
const json = await res.json();
currentRequest = json.request;
currentData = parseData(currentRequest.data_text);
const children = json.children || [];
renderRequest(currentRequest, currentData);
currentAnswers = children.filter(c => c.type === 'answer' || c.type === 'document');
renderAnswers(currentAnswers);
allComments = children.filter(c => c.type === 'comment');
await initChannels();
} catch(e) {
document.getElementById('reqTitle').textContent = 'Error loading request';
}
}
function renderRequest(req, d) {
const title = d.title || req.summary || 'Untitled';
document.title = title + ' \u2014 Dealspace';
document.getElementById('reqRef').textContent = d.item_number || title;
document.getElementById('reqTitle').textContent = title;
// Don't repeat description if it's the same as the title
const desc = d.description || '';
document.getElementById('reqDesc').textContent = desc === title ? '' : desc;
// Apply role-based UI restrictions
applyRoleRestrictions();
if (req.project_id) document.getElementById('backToProject').href = '/app/projects/' + req.project_id;
const badge = document.getElementById('reqItemBadge');
const badgeParts = [d.section, d.item_number].filter(Boolean);
if (badgeParts.length) { badge.textContent = badgeParts.join(' \u00b7 '); badge.classList.remove('hidden'); }
const prioEl = document.getElementById('reqPriority');
if (d.priority) {
const pc = priorityColors[d.priority] || 'bg-gray-500/20 text-gray-300';
prioEl.className = 'px-2.5 py-1 rounded-full text-xs font-medium capitalize ' + pc;
prioEl.textContent = d.priority + ' priority';
prioEl.classList.remove('hidden');
}
if (d.due_date) {
const dueEl = document.getElementById('reqDue');
dueEl.textContent = '\ud83d\udcc5 Due: ' + d.due_date;
dueEl.classList.remove('hidden');
}
const status = d.status || 'open';
const sc = statusColors[status] || 'bg-gray-500/20 text-gray-300';
const statusEl = document.getElementById('reqStatus');
statusEl.className = 'px-2.5 py-1 rounded-full text-xs font-medium capitalize ' + sc;
statusEl.textContent = status;
if (status === 'answered') {
document.getElementById('answeredBanner').classList.remove('hidden');
document.getElementById('markAnsweredBtn').classList.add('hidden');
} else {
document.getElementById('answeredBanner').classList.add('hidden');
document.getElementById('markAnsweredBtn').classList.remove('hidden');
}
}
// ---- Edit request detail ----
function startEditRequest() {
if (!currentData) return;
document.getElementById('editReqTitle').value = currentData.title || '';
document.getElementById('editReqDesc').value = currentData.description || '';
document.getElementById('editReqPriority').value = currentData.priority || 'medium';
document.getElementById('editReqStatus').value = currentData.status || 'open';
document.getElementById('reqTitle').classList.add('hidden');
document.getElementById('reqDesc').classList.add('hidden');
document.getElementById('editReqBtn').classList.add('hidden');
document.getElementById('reqMetaBar').classList.add('hidden');
document.getElementById('reqEditMode').classList.remove('hidden');
}
function cancelEditRequestDetail() {
document.getElementById('reqTitle').classList.remove('hidden');
document.getElementById('reqDesc').classList.remove('hidden');
document.getElementById('editReqBtn').classList.remove('hidden');
document.getElementById('reqMetaBar').classList.remove('hidden');
document.getElementById('reqEditMode').classList.add('hidden');
}
async function saveEditRequestDetail() {
if (!currentRequest || !currentData) return;
const projectID = currentRequest.project_id;
const updatedData = {
...currentData,
title: document.getElementById('editReqTitle').value.trim(),
description: document.getElementById('editReqDesc').value.trim(),
priority: document.getElementById('editReqPriority').value,
status: document.getElementById('editReqStatus').value
};
try {
const res = await fetchAPI('/api/projects/' + projectID + '/entries/' + reqID, {
method: 'PUT',
body: JSON.stringify({ data: JSON.stringify(updatedData), version: currentRequest.version })
});
if (res.ok) {
cancelEditRequestDetail();
loadAll();
}
} catch(e) {
console.error('Save failed:', e);
}
}
// ---- Answers / Files ----
function renderAnswers(docs) {
const el = document.getElementById('answers');
if (!docs || docs.length === 0) {
el.innerHTML = '<p class="text-[#475569] text-sm">No response submitted yet.</p>';
return;
}
const projectID = currentRequest.project_id;
el.innerHTML = docs.map(a => {
const d = parseData(a.data_text);
const name = d.filename || d.name || a.summary || 'Document';
const icon = name.endsWith('.pdf') ? '\ud83d\udcc4' : name.match(/\.(jpg|jpeg|png|gif)$/i) ? '\ud83d\uddbc\ufe0f' : name.match(/\.(xlsx?|csv)$/i) ? '\ud83d\udcca' : '\ud83d\udcce';
const objectID = d.object_id || '';
const downloadUrl = objectID ? '/api/projects/' + projectID + '/objects/' + objectID + '?filename=' + encodeURIComponent(name) : '#';
const previewUrl = objectID ? '/api/projects/' + projectID + '/objects/' + objectID + '/preview?filename=' + encodeURIComponent(name) : '';
const isVideo = /\.(mp4|mov|avi|mkv|webm)$/i.test(name);
return `<div class="flex items-center gap-3 px-3 py-2.5 rounded-lg bg-[#0a1628] border border-white/[0.05]">
<span class="text-xl">${icon}</span>
<div class="flex-1 min-w-0">
<div class="flex items-center gap-1">
<span class="text-white text-sm font-medium truncate" id="fname-${a.entry_id}">${escHtml(name)}</span>
<button onclick="startRenameFile('${a.entry_id}')" class="shrink-0 p-0.5 rounded hover:bg-white/[0.08] text-[#94a3b8] hover:text-white transition" title="Rename">
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
</button>
</div>
<div class="text-[#475569] text-xs">${a.created_at ? new Date(a.created_at * 1000).toLocaleString() : ''}</div>
</div>
<div class="flex items-center gap-2 shrink-0">
${objectID && previewUrl ? `<a href="${previewUrl}" target="_blank" class="px-2 py-1 rounded text-xs font-medium bg-white/[0.06] text-[#94a3b8] hover:text-white hover:bg-white/[0.1] transition">${isVideo ? 'Play' : 'Preview'}</a>` : ''}
${objectID ? `<a href="${downloadUrl}" class="text-[#c9a84c] text-sm hover:underline">Download</a>` : ''}
</div>
</div>`;
}).join('');
}
// ---- Rename file ----
function startRenameFile(answerId) {
const span = document.getElementById('fname-' + answerId);
if (!span) return;
const currentName = span.textContent;
const container = span.parentElement;
container.innerHTML = `<input type="text" value="" id="rename-input-${answerId}"
style="flex:1;padding:2px 6px;background:#0a1628;border:1px solid rgba(255,255,255,.12);border-radius:4px;color:white;font-size:13px;outline:none"
onkeydown="handleRenameKey(event,'${answerId}')" onblur="saveRenameFile('${answerId}')">`;
const input = document.getElementById('rename-input-' + answerId);
if (input) { input.value = currentName; input.focus(); input.select(); }
}
function handleRenameKey(e, answerId) {
if (e.key === 'Enter') { e.preventDefault(); e.target.blur(); }
if (e.key === 'Escape') { e.target.dataset.cancelled = 'true'; e.target.blur(); }
}
async function saveRenameFile(answerId) {
const input = document.getElementById('rename-input-' + answerId);
if (!input || input.dataset.cancelled === 'true') { loadAll(); return; }
const newName = input.value.trim();
if (!newName) { loadAll(); return; }
const answer = currentAnswers.find(a => a.entry_id === answerId);
if (!answer) { loadAll(); return; }
const projectID = currentRequest.project_id;
const d = parseData(answer.data_text);
d.filename = newName;
d.name = newName;
try {
await fetchAPI('/api/projects/' + projectID + '/entries/' + answerId, {
method: 'PUT',
body: JSON.stringify({ data: JSON.stringify(d), version: answer.version || 0 })
});
} catch(e) {
console.error('Rename failed:', e);
}
loadAll();
}
// renderComments replaced by channel system below
async function uploadFiles(files) {
if (!currentRequest) return;
const projectID = currentRequest.project_id;
const status = document.getElementById('uploadStatus');
for (const file of files) {
status.textContent = 'Uploading ' + file.name + '...';
const fd = new FormData();
fd.append('file', file);
try {
const uploadRes = await fetchAPI('/api/projects/' + projectID + '/objects', { method: 'POST', body: fd });
if (!uploadRes.ok) { status.textContent = 'Upload failed for ' + file.name; continue; }
const uploadData = await uploadRes.json();
const entryBody = {
project_id: projectID,
parent_id: reqID,
type: 'document',
data: JSON.stringify({ filename: file.name, name: file.name, content_type: file.type, object_id: uploadData.object_id })
};
const entryRes = await fetchAPI('/api/projects/' + projectID + '/entries', { method: 'POST', body: JSON.stringify(entryBody) });
if (entryRes.ok) { status.textContent = file.name + ' uploaded.'; }
else { status.textContent = 'Failed to save ' + file.name; }
} catch(e) { status.textContent = 'Error: ' + e.message; }
}
setTimeout(() => status.textContent = '', 3000);
loadAll();
}
// ---- Channel-based comment system ----
let activeChannel = 'announcements';
let allComments = [];
let dealOrgs = [];
let replyingToId = null;
async function initChannels() {
if (!currentRequest) return;
try {
const res = await fetchAPI('/api/projects/' + currentRequest.project_id + '/orgs');
dealOrgs = await res.json() || [];
} catch(e) { dealOrgs = []; }
renderChannelTabs();
switchChannel('announcements');
}
function renderChannelTabs() {
const container = document.getElementById('channelTabs');
const tabs = [
{ key: 'announcements', label: '📢 Announcements' },
...dealOrgs.map(o => {
const d = parseData(o.data_text);
return { key: 'org:' + o.entry_id, label: '🔒 ' + escHtml(d.org_name || d.name || 'Org') };
})
];
container.innerHTML = tabs.map(t =>
`<button onclick="switchChannel(${JSON.stringify(t.key)})"
class="px-4 py-3 text-sm font-medium whitespace-nowrap border-b-2 -mb-px transition
${activeChannel === t.key ? 'border-[#c9a84c] text-white' : 'border-transparent text-[#94a3b8] hover:text-white'}">
${t.label}
</button>`
).join('');
}
function switchChannel(key) {
activeChannel = key;
cancelReply();
renderChannelTabs();
renderChannelComments();
const ta = document.getElementById('commentText');
ta.placeholder = key === 'announcements' ? 'Post an announcement...' : 'Message this channel...';
}
function renderChannelComments() {
const el = document.getElementById('channelComments');
const ch = allComments.filter(c => (parseData(c.data_text).channel || 'announcements') === activeChannel);
const top = ch.filter(c => !parseData(c.data_text).parent_comment_id);
const nested = ch.filter(c => !!parseData(c.data_text).parent_comment_id);
if (top.length === 0) {
el.innerHTML = '<p class="text-[#475569] text-sm">No messages yet.</p>';
return;
}
el.innerHTML = top.map(c => {
const d = parseData(c.data_text);
const replies = nested.filter(r => parseData(r.data_text).parent_comment_id === c.entry_id);
return renderOneComment(c, d, false) + replies.map(r => renderOneComment(r, parseData(r.data_text), true)).join('');
}).join('');
el.scrollTop = el.scrollHeight;
}
function renderOneComment(c, d, isReply) {
const av = (d.author || '?')[0].toUpperCase();
const ts = c.created_at ? new Date(c.created_at * 1000).toLocaleString('en-US', {month:'short',day:'numeric',hour:'numeric',minute:'2-digit'}) : '';
const replyBtn = isReply ? '' : `<button onclick="startReply('${c.entry_id}')" class="text-xs text-[#475569] hover:text-[#94a3b8] ml-2 transition">Reply</button>`;
const indent = isReply ? 'ml-10 pl-4 border-l-2 border-[#c9a84c]/30' : '';
return `<div class="flex gap-3 ${indent}" data-comment-id="${c.entry_id}">
<div class="w-7 h-7 rounded-full bg-[#c9a84c]/20 flex items-center justify-center text-[#c9a84c] text-xs font-semibold shrink-0 mt-0.5">${av}</div>
<div class="flex-1 min-w-0">
<div class="flex items-baseline gap-2 mb-1">
<span class="text-white text-sm font-medium">${escHtml(d.author || 'Unknown')}</span>
<span class="text-[#475569] text-xs">${ts}</span>
${replyBtn}
</div>
<p class="text-[#94a3b8] text-sm leading-relaxed">${escHtml(d.text || '')}</p>
</div>
</div>`;
}
function startReply(commentId) {
cancelReply();
replyingToId = commentId;
const el = document.querySelector(`[data-comment-id="${commentId}"]`);
if (!el) return;
const form = document.createElement('div');
form.id = 'replyForm';
form.className = 'ml-10 pl-4 border-l-2 border-[#c9a84c]/30 mt-2';
form.innerHTML = `<div class="flex gap-2 items-end">
<textarea id="replyText" rows="2" placeholder="Reply..." class="flex-1 px-3 py-2 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white placeholder-[#475569] focus:outline-none focus:border-[#c9a84c] text-sm resize-none"></textarea>
<div class="flex flex-col gap-1">
<button onclick="postComment('${commentId}')" class="px-3 py-1.5 bg-[#c9a84c] hover:bg-[#b8973f] text-[#0a1628] font-semibold rounded-lg text-xs transition">Reply</button>
<button onclick="cancelReply()" class="px-3 py-1.5 bg-white/[0.05] hover:bg-white/[0.08] text-[#94a3b8] rounded-lg text-xs transition">Cancel</button>
</div>
</div>`;
el.insertAdjacentElement('afterend', form);
document.getElementById('replyText').focus();
}
function cancelReply() {
replyingToId = null;
const f = document.getElementById('replyForm');
if (f) f.remove();
}
async function postComment(parentCommentId) {
if (!currentRequest) return;
const text = parentCommentId
? (document.getElementById('replyText')?.value || '').trim()
: (document.getElementById('commentText')?.value || '').trim();
if (!text) return;
const projectID = currentRequest.project_id;
const body = {
project_id: projectID,
parent_id: reqID,
type: 'comment',
data: JSON.stringify({ text, author: user.name || user.email, channel: activeChannel, parent_comment_id: parentCommentId || null })
};
try {
const res = await fetchAPI('/api/projects/' + projectID + '/entries', { method: 'POST', body: JSON.stringify(body) });
if (res.ok) {
if (parentCommentId) cancelReply(); else document.getElementById('commentText').value = '';
await loadAll();
}
} catch(e) {}
}
async function markAnswered() {
if (!currentRequest || !currentData) return;
const projectID = currentRequest.project_id;
const updatedData = { ...currentData, status: 'answered' };
const body = {
data: JSON.stringify(updatedData),
version: currentRequest.version
};
try {
const res = await fetchAPI('/api/projects/' + projectID + '/entries/' + reqID, { method: 'PUT', body: JSON.stringify(body) });
if (res.ok) loadAll();
} catch(e) {}
}
// Drag and drop
const ua = document.getElementById('uploadArea');
ua.addEventListener('dragover', e => { e.preventDefault(); ua.classList.add('border-[#c9a84c]/60'); });
ua.addEventListener('dragleave', () => ua.classList.remove('border-[#c9a84c]/60'));
ua.addEventListener('drop', e => { e.preventDefault(); ua.classList.remove('border-[#c9a84c]/60'); uploadFiles(e.dataTransfer.files); });
loadAll();
</script>
{{end}}