fixing rolodex and search

This commit is contained in:
HotSwapp
2025-08-11 21:58:25 -05:00
parent 278eb7c5d4
commit c76b68d009
25 changed files with 1651 additions and 915 deletions

View File

@@ -381,14 +381,7 @@ let lookupData = {
employees: []
};
// 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
// Initialize on page load
document.addEventListener('DOMContentLoaded', function() {
@@ -446,9 +439,9 @@ async function loadLookupData() {
try {
// Load all lookup data in parallel
const [fileTypesRes, statusesRes, employeesRes] = await Promise.all([
fetch('/api/files/lookups/file-types', { headers: getAuthHeaders() }),
fetch('/api/files/lookups/file-statuses', { headers: getAuthHeaders() }),
fetch('/api/files/lookups/employees', { headers: getAuthHeaders() })
window.http.wrappedFetch('/api/files/lookups/file-types'),
window.http.wrappedFetch('/api/files/lookups/file-statuses'),
window.http.wrappedFetch('/api/files/lookups/employees')
]);
if (fileTypesRes.ok) {
@@ -505,9 +498,7 @@ async function loadFiles(page = 0, filters = {}) {
...filters
});
const response = await fetch(`/api/files/?${params}`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/files/?${params}`);
if (!response.ok) throw new Error('Failed to load files');
@@ -628,9 +619,7 @@ function showAddFileModal() {
async function editFile(fileNo) {
try {
const response = await fetch(`/api/files/${fileNo}`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/files/${fileNo}`);
if (!response.ok) throw new Error('Failed to load file');
@@ -687,9 +676,7 @@ function populateFileForm(file) {
async function loadClientInfo(clientId) {
try {
const response = await fetch(`/api/customers/${clientId}`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/customers/${clientId}`);
if (response.ok) {
const client = await response.json();
@@ -705,9 +692,7 @@ async function loadClientInfo(clientId) {
async function loadFinancialSummary(fileNo) {
try {
const response = await fetch(`/api/files/${fileNo}/financial-summary`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/files/${fileNo}/financial-summary`);
if (response.ok) {
const data = await response.json();
@@ -771,9 +756,8 @@ async function saveFile() {
const url = isEditing ? `/api/files/${editingFileNo}` : '/api/files/';
const method = isEditing ? 'PUT' : 'POST';
const response = await fetch(url, {
const response = await window.http.wrappedFetch(url, {
method: method,
headers: getAuthHeaders(),
body: JSON.stringify(fileData)
});
@@ -798,9 +782,8 @@ async function deleteFile() {
}
try {
const response = await fetch(`/api/files/${editingFileNo}`, {
method: 'DELETE',
headers: getAuthHeaders()
const response = await window.http.wrappedFetch(`/api/files/${editingFileNo}`, {
method: 'DELETE'
});
if (!response.ok) throw new Error('Failed to delete file');
@@ -820,9 +803,8 @@ async function closeFile() {
try {
const body = closeDate ? JSON.stringify({ close_date: closeDate }) : '';
const response = await fetch(`/api/files/${editingFileNo}/close`, {
const response = await window.http.wrappedFetch(`/api/files/${editingFileNo}/close`, {
method: 'POST',
headers: getAuthHeaders(),
body: body
});
@@ -841,9 +823,8 @@ async function closeFile() {
async function reopenFile() {
try {
const response = await fetch(`/api/files/${editingFileNo}/reopen`, {
method: 'POST',
headers: getAuthHeaders()
const response = await window.http.wrappedFetch(`/api/files/${editingFileNo}/reopen`, {
method: 'POST'
});
if (!response.ok) throw new Error('Failed to reopen file');
@@ -871,9 +852,7 @@ async function searchClients() {
const params = new URLSearchParams({ limit: 100 });
if (search) params.append('search', search);
const response = await fetch(`/api/customers/?${params}`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/customers/?${params}`);
if (!response.ok) throw new Error('Failed to search clients');
@@ -916,9 +895,7 @@ async function validateFileNumber() {
if (!fileNo || isEditing) return;
try {
const response = await fetch(`/api/files/${fileNo}`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/files/${fileNo}`);
if (response.ok) {
showAlert('File number already exists', 'warning');
@@ -951,9 +928,7 @@ async function performAdvancedSearch() {
}
try {
const response = await fetch(`/api/files/search/advanced?${params}`, {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch(`/api/files/search/advanced?${params}`);
if (!response.ok) throw new Error('Advanced search failed');
@@ -975,9 +950,7 @@ function clearAdvancedSearch() {
async function showStats() {
try {
const response = await fetch('/api/files/stats/summary', {
headers: getAuthHeaders()
});
const response = await window.http.wrappedFetch('/api/files/stats/summary');
if (!response.ok) throw new Error('Failed to load statistics');
@@ -1057,7 +1030,7 @@ function showAlert(message, type = 'info') {
async function loadDocuments(fileNo) {
try {
const response = await fetch(`/api/documents/${fileNo}/uploaded`, { headers: getAuthHeaders() });
const response = await window.http.wrappedFetch(`/api/documents/${fileNo}/uploaded`);
if (!response.ok) throw new Error('Failed to load documents');
const docs = await response.json();
displayDocuments(docs);
@@ -1126,10 +1099,10 @@ async function uploadDocument() {
formData.append('description', description);
try {
const response = await fetch(`/api/documents/upload/${editingFileNo}`, {
const response = await window.http.wrappedFetch(`/api/documents/upload/${editingFileNo}`, {
method: 'POST',
body: formData,
headers: getAuthHeaders() // Note: no Content-Type, browser sets it
// Note: no Content-Type; browser sets multipart boundaries
});
if (!response.ok) {
const error = await response.json();
@@ -1164,9 +1137,8 @@ function downloadDocument(path) {
async function deleteDocument(docId) {
if (!confirm('Are you sure you want to delete this document?')) return;
try {
const response = await fetch(`/api/documents/uploaded/${docId}`, {
const response = await window.http.wrappedFetch(`/api/documents/uploaded/${docId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (!response.ok) throw new Error('Failed to delete');
showAlert('Document deleted', 'success');
@@ -1186,10 +1158,9 @@ async function updateDocumentDescription(docId, description) {
const formData = new FormData();
formData.append('description', description);
try {
const response = await fetch(`/api/documents/uploaded/${docId}`, {
const response = await window.http.wrappedFetch(`/api/documents/uploaded/${docId}`, {
method: 'PUT',
body: formData,
headers: getAuthHeaders()
});
if (!response.ok) throw new Error('Failed to update');
showAlert('Description updated', 'success');