Fix dynamic API base path for server deployment

This commit is contained in:
pongpon pitisuk
2026-09-12 14:34:09 +07:00
parent 72eb7cd0c8
commit e01d01464a
9 changed files with 262 additions and 52 deletions
+4 -3
View File
@@ -76,7 +76,7 @@ function renderEditor() {
<input type="hidden" id="edit-survey-cert-template-path" value="${escapeHtml(currentSurvey.certificate_template || '')}">
<div id="cert-preview-wrapper" style="margin-top:12px; display:${currentSurvey.certificate_template ? 'block' : 'none'};">
<img id="cert-template-preview" src="${currentSurvey.certificate_template ? '/survey/' + currentSurvey.certificate_template : ''}" style="max-height:140px; width:auto; border-radius:8px; border:1px solid var(--border-color); box-shadow:var(--shadow-sm);">
<img id="cert-template-preview" src="${currentSurvey.certificate_template ? (window.location.pathname.includes('/survey') ? '/survey/' : '/') + currentSurvey.certificate_template : ''}" style="max-height:140px; width:auto; border-radius:8px; border:1px solid var(--border-color); box-shadow:var(--shadow-sm);">
</div>
</div>
@@ -486,7 +486,8 @@ async function uploadCertTemplate(input) {
formData.append('template_image', file);
try {
const res = await fetch('/survey/api/surveys.php?action=uploadTemplate', {
const basePath = window.location.pathname.includes('/survey') ? '/survey' : '';
const res = await fetch(`${basePath}/api/surveys.php?action=uploadTemplate`, {
method: 'POST',
body: formData
});
@@ -501,7 +502,7 @@ async function uploadCertTemplate(input) {
// Update preview
const previewImg = document.getElementById('cert-template-preview');
const previewWrapper = document.getElementById('cert-preview-wrapper');
previewImg.src = '/survey/' + data.template_path;
previewImg.src = (basePath ? `${basePath}/` : '/') + data.template_path;
previewWrapper.style.display = 'block';
// Add dynamic delete button if it doesn't exist