fixing rolodex and search
This commit is contained in:
@@ -446,9 +446,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
function initializeDocuments() {
|
||||
if (typeof apiGet === 'function') {
|
||||
// Ensure API headers are set up with token
|
||||
if (window.apiHeaders && token) {
|
||||
window.apiHeaders['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
// Authorization is injected by window.http.wrappedFetch
|
||||
|
||||
// Initialize the first tab as active
|
||||
document.getElementById('templates-tab').click();
|
||||
@@ -594,14 +592,7 @@ function setupEventHandlers() {
|
||||
document.getElementById('refreshQdrosBtn').addEventListener('click', loadQdros);
|
||||
}
|
||||
|
||||
// Helper function for authenticated API calls
|
||||
function getAuthHeaders() {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
return {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
}
|
||||
// Authorization and JSON headers are injected by window.http.wrappedFetch
|
||||
|
||||
async function loadTemplates() {
|
||||
try {
|
||||
@@ -624,9 +615,7 @@ async function loadTemplates() {
|
||||
|
||||
console.log('🔍 DEBUG: Making API call to:', url);
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch(url);
|
||||
console.log('🔍 DEBUG: Response status:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -658,7 +647,7 @@ function createTemplateRow(template) {
|
||||
const row = document.createElement('tr');
|
||||
const variableCount = Object.keys(template.variables || {}).length;
|
||||
|
||||
row.innerHTML = `
|
||||
const rowHtml = `
|
||||
<td class="px-4 py-2"><code>${template.form_id}</code></td>
|
||||
<td class="px-4 py-2">${template.form_name}</td>
|
||||
<td class="px-4 py-2"><span class="inline-block px-2 py-0.5 text-xs rounded bg-neutral-100 text-neutral-700 border border-neutral-300">${template.category}</span></td>
|
||||
@@ -677,6 +666,7 @@ function createTemplateRow(template) {
|
||||
</div>
|
||||
</td>
|
||||
`;
|
||||
if (window.setSafeHTML) { window.setSafeHTML(row, rowHtml); } else { row.innerHTML = rowHtml; }
|
||||
|
||||
return row;
|
||||
}
|
||||
@@ -696,9 +686,7 @@ async function loadQdros() {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ detail: 'Unknown error' }));
|
||||
@@ -727,7 +715,7 @@ function displayQdros(qdros) {
|
||||
function createQdroRow(qdro) {
|
||||
const row = document.createElement('tr');
|
||||
|
||||
row.innerHTML = `
|
||||
const qdroRowHtml = `
|
||||
<td><code>${qdro.file_no}</code></td>
|
||||
<td>${qdro.version}</td>
|
||||
<td>${qdro.participant_name || ''}</td>
|
||||
@@ -747,6 +735,7 @@ function createQdroRow(qdro) {
|
||||
</div>
|
||||
</td>
|
||||
`;
|
||||
if (window.setSafeHTML) { window.setSafeHTML(row, qdroRowHtml); } else { row.innerHTML = qdroRowHtml; }
|
||||
|
||||
return row;
|
||||
}
|
||||
@@ -768,9 +757,7 @@ async function loadCategories() {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch('/api/documents/categories/', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch('/api/documents/categories/');
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({ detail: 'Unknown error' }));
|
||||
@@ -819,9 +806,7 @@ function openTemplateModal(templateId = null) {
|
||||
|
||||
async function loadTemplateForEditing(templateId) {
|
||||
try {
|
||||
const response = await fetch(`/api/documents/templates/${templateId}`, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch(`/api/documents/templates/${templateId}`);
|
||||
if (!response.ok) throw new Error('Failed to load template');
|
||||
|
||||
const template = await response.json();
|
||||
@@ -856,11 +841,8 @@ async function saveTemplate() {
|
||||
const url = isEdit ? `/api/documents/templates/${templateData.form_id}` : '/api/documents/templates/';
|
||||
const method = isEdit ? 'PUT' : 'POST';
|
||||
|
||||
const response = await fetch(url, {
|
||||
const response = await window.http.wrappedFetch(url, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(templateData)
|
||||
});
|
||||
|
||||
@@ -901,9 +883,7 @@ function extractVariables(content) {
|
||||
|
||||
async function loadDocumentStats() {
|
||||
try {
|
||||
const response = await fetch('/api/documents/stats/summary', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch('/api/documents/stats/summary');
|
||||
if (!response.ok) throw new Error('Failed to load statistics');
|
||||
|
||||
const stats = await response.json();
|
||||
@@ -918,7 +898,8 @@ async function loadDocumentStats() {
|
||||
Object.entries(stats.templates_by_category).forEach(([category, count]) => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'flex items-center justify-between mb-1';
|
||||
div.innerHTML = `<span>${category}</span><span class="inline-block px-2 py-0.5 text-xs rounded bg-neutral-200 text-neutral-700">${count}</span>`;
|
||||
const html = `<span>${category}</span><span class="inline-block px-2 py-0.5 text-xs rounded bg-neutral-200 text-neutral-700">${count}</span>`;
|
||||
if (window.setSafeHTML) { window.setSafeHTML(div, html); } else { div.innerHTML = html; }
|
||||
categoriesDiv.appendChild(div);
|
||||
});
|
||||
|
||||
@@ -932,11 +913,12 @@ async function loadDocumentStats() {
|
||||
stats.recent_activity.forEach(activity => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'mb-2 p-2 border rounded';
|
||||
div.innerHTML = `
|
||||
const activityHtml = `
|
||||
<small class="text-neutral-500">${activity.type}</small><br>
|
||||
<strong>File: ${activity.file_no}</strong><br>
|
||||
<span class="${getStatusBadgeClass(activity.status)}">${activity.status}</span>
|
||||
`;
|
||||
if (window.setSafeHTML) { window.setSafeHTML(div, activityHtml); } else { div.innerHTML = activityHtml; }
|
||||
activityDiv.appendChild(div);
|
||||
});
|
||||
}
|
||||
@@ -983,9 +965,8 @@ async function logClientError({ message, action = null, error = null, extra = nu
|
||||
user_agent: navigator.userAgent,
|
||||
extra
|
||||
};
|
||||
await fetch('/api/documents/client-error', {
|
||||
await window.http.wrappedFetch('/api/documents/client-error', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
} catch (_) {
|
||||
@@ -1010,9 +991,8 @@ async function generateFromTemplate(templateId) {
|
||||
async function deleteTemplate(templateId) {
|
||||
if (confirm('Are you sure you want to delete this template?')) {
|
||||
try {
|
||||
const response = await fetch(`/api/documents/templates/${templateId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
const response = await window.http.wrappedFetch(`/api/documents/templates/${templateId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Failed to delete template');
|
||||
@@ -1034,9 +1014,7 @@ function openGenerateModal() {
|
||||
|
||||
async function loadTemplatesForGeneration() {
|
||||
try {
|
||||
const response = await fetch('/api/documents/templates/', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch('/api/documents/templates/');
|
||||
if (!response.ok) throw new Error('Failed to load templates');
|
||||
|
||||
const templates = await response.json();
|
||||
@@ -1057,9 +1035,7 @@ async function loadTemplatesForGeneration() {
|
||||
|
||||
async function loadTemplatePreview(templateId) {
|
||||
try {
|
||||
const response = await fetch(`/api/documents/templates/${templateId}`, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const response = await window.http.wrappedFetch(`/api/documents/templates/${templateId}`);
|
||||
if (!response.ok) throw new Error('Failed to load template');
|
||||
|
||||
const template = await response.json();
|
||||
@@ -1100,9 +1076,8 @@ async function generateDocument() {
|
||||
});
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/documents/generate/${templateId}`, {
|
||||
const response = await window.http.wrappedFetch(`/api/documents/generate/${templateId}`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
|
||||
@@ -1131,7 +1106,7 @@ function addCustomVariableInput() {
|
||||
const container = document.getElementById('customVariables');
|
||||
const div = document.createElement('div');
|
||||
div.className = 'grid grid-cols-12 gap-2 mb-2 custom-var-input';
|
||||
div.innerHTML = `
|
||||
const customVarHtml = `
|
||||
<div class="col-span-12 md:col-span-5">
|
||||
<input type="text" class="w-full px-3 py-1.5 border border-neutral-300 dark:border-neutral-600 rounded var-name" placeholder="Variable name">
|
||||
</div>
|
||||
@@ -1144,6 +1119,7 @@ function addCustomVariableInput() {
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
if (window.setSafeHTML) { window.setSafeHTML(div, customVarHtml); } else { div.innerHTML = customVarHtml; }
|
||||
container.appendChild(div);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user