Poista vanha Tiedostot-osio asiakasprofiilista (korvattu Dokumentit-osiolla)
- Poistettu Tiedostot-section, loadFiles-kutsu ja file-upload event listener - Poistettu loadFiles() ja deleteFile() funktiot (formatFileSize jää käyttöön) - Dokumentit-osio korvaa vanhan tiedostojärjestelmän versioituina dokumentteina Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
46
script.js
46
script.js
@@ -589,15 +589,6 @@ function showDetail(id) {
|
|||||||
<div class="detail-item"><div class="detail-label">E-laskuvälittäjä</div><div class="detail-value">${detailVal(c.elaskuvalittaja)}</div></div>
|
<div class="detail-item"><div class="detail-label">E-laskuvälittäjä</div><div class="detail-value">${detailVal(c.elaskuvalittaja)}</div></div>
|
||||||
</div></div>
|
</div></div>
|
||||||
${c.lisatiedot ? `<div class="detail-section"><h3>Lisätiedot</h3><p style="white-space:pre-wrap;color:#555;">${esc(c.lisatiedot)}</p></div>` : ''}
|
${c.lisatiedot ? `<div class="detail-section"><h3>Lisätiedot</h3><p style="white-space:pre-wrap;color:#555;">${esc(c.lisatiedot)}</p></div>` : ''}
|
||||||
<div class="detail-section"><h3>Tiedostot</h3>
|
|
||||||
<div class="file-upload-area">
|
|
||||||
<label class="file-upload-btn btn-primary" style="display:inline-block;cursor:pointer;font-size:0.85rem;padding:8px 16px;">
|
|
||||||
+ Lisää tiedosto <input type="file" id="file-upload-input" style="display:none" multiple>
|
|
||||||
</label>
|
|
||||||
<span style="font-size:0.8rem;color:#999;margin-left:8px;">Max 20 MB / tiedosto</span>
|
|
||||||
</div>
|
|
||||||
<div id="file-list" class="file-list" style="margin-top:0.75rem;"></div>
|
|
||||||
</div>
|
|
||||||
<div class="detail-section"><h3>Dokumentit</h3>
|
<div class="detail-section"><h3>Dokumentit</h3>
|
||||||
<div id="customer-docs-list" style="margin-bottom:0.75rem;"><span style="color:#aaa;font-size:0.85rem;">Ladataan...</span></div>
|
<div id="customer-docs-list" style="margin-bottom:0.75rem;"><span style="color:#aaa;font-size:0.85rem;">Ladataan...</span></div>
|
||||||
<button class="btn-primary" style="font-size:0.85rem;padding:6px 14px;" onclick="openDocEditForCustomer('${id}')">+ Lisää dokumentti</button>
|
<button class="btn-primary" style="font-size:0.85rem;padding:6px 14px;" onclick="openDocEditForCustomer('${id}')">+ Lisää dokumentti</button>
|
||||||
@@ -608,22 +599,7 @@ function showDetail(id) {
|
|||||||
const pricesHidden = document.getElementById('customer-table')?.classList.contains('prices-hidden');
|
const pricesHidden = document.getElementById('customer-table')?.classList.contains('prices-hidden');
|
||||||
detailModal.querySelector('.modal-content')?.classList.toggle('prices-hidden', !!pricesHidden);
|
detailModal.querySelector('.modal-content')?.classList.toggle('prices-hidden', !!pricesHidden);
|
||||||
detailModal.style.display = 'flex';
|
detailModal.style.display = 'flex';
|
||||||
loadFiles(id);
|
|
||||||
loadCustomerDocuments(id);
|
loadCustomerDocuments(id);
|
||||||
document.getElementById('file-upload-input').addEventListener('change', async function () {
|
|
||||||
for (const file of this.files) {
|
|
||||||
const fd = new FormData();
|
|
||||||
fd.append('customer_id', id);
|
|
||||||
fd.append('file', file);
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API}?action=file_upload`, { method: 'POST', credentials: 'include', body: fd });
|
|
||||||
const data = await res.json();
|
|
||||||
if (!res.ok) alert(data.error || 'Virhe');
|
|
||||||
} catch (e) { alert('Tiedoston lähetys epäonnistui'); }
|
|
||||||
}
|
|
||||||
this.value = '';
|
|
||||||
loadFiles(id);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCustomerDocuments(customerId) {
|
async function loadCustomerDocuments(customerId) {
|
||||||
@@ -664,34 +640,12 @@ window.openDocEditForCustomer = function(customerId, forceCategory) {
|
|||||||
openDocEdit(null, forceCategory || null, customerId);
|
openDocEdit(null, forceCategory || null, customerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function loadFiles(customerId) {
|
|
||||||
const fileList = document.getElementById('file-list');
|
|
||||||
if (!fileList) return;
|
|
||||||
try {
|
|
||||||
const files = await apiCall(`file_list&customer_id=${customerId}`);
|
|
||||||
if (files.length === 0) { fileList.innerHTML = '<p style="color:#aaa;font-size:0.85rem;">Ei tiedostoja.</p>'; return; }
|
|
||||||
fileList.innerHTML = files.map(f => `<div class="file-item">
|
|
||||||
<div class="file-info">
|
|
||||||
<a href="${API}?action=file_download&customer_id=${customerId}&filename=${encodeURIComponent(f.filename)}" class="file-name" target="_blank">${esc(f.filename)}</a>
|
|
||||||
<span class="file-meta">${formatFileSize(f.size)} · ${f.modified}</span>
|
|
||||||
</div>
|
|
||||||
<button class="file-delete-btn" onclick="deleteFile('${customerId}','${esc(f.filename)}')" title="Poista">✕</button>
|
|
||||||
</div>`).join('');
|
|
||||||
} catch (e) { fileList.innerHTML = '<p style="color:#e74c3c;font-size:0.85rem;">Virhe ladattaessa tiedostoja.</p>'; }
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatFileSize(bytes) {
|
function formatFileSize(bytes) {
|
||||||
if (bytes < 1024) return bytes + ' B';
|
if (bytes < 1024) return bytes + ' B';
|
||||||
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
||||||
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteFile(customerId, filename) {
|
|
||||||
if (!confirm(`Poistetaanko tiedosto "${filename}"?`)) return;
|
|
||||||
await apiCall('file_delete', 'POST', { customer_id: customerId, filename });
|
|
||||||
loadFiles(customerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detail modal actions
|
// Detail modal actions
|
||||||
document.getElementById('detail-close').addEventListener('click', () => detailModal.style.display = 'none');
|
document.getElementById('detail-close').addEventListener('click', () => detailModal.style.display = 'none');
|
||||||
document.getElementById('detail-cancel').addEventListener('click', () => detailModal.style.display = 'none');
|
document.getElementById('detail-cancel').addEventListener('click', () => detailModal.style.display = 'none');
|
||||||
|
|||||||
Reference in New Issue
Block a user