diff --git a/pages/main_form_page.go b/pages/main_form_page.go index d70406d..d8485c3 100644 --- a/pages/main_form_page.go +++ b/pages/main_form_page.go @@ -135,6 +135,9 @@ func MainFormPage(jwtToken string) string { + @@ -179,6 +182,7 @@ func MainFormPage(jwtToken string) string { var itemDiv = document.createElement('div'); itemDiv.style.cssText = 'display:flex; justify-content:space-between; align-items:flex-start; border-bottom:1px solid #ddd; padding-bottom:0.5rem; margin-bottom:0.5rem;'; + itemDiv.dataset.reportData = JSON.stringify(savedValues); var contentDiv = document.createElement('div'); contentDiv.className = 'item-content'; @@ -290,8 +294,48 @@ func MainFormPage(jwtToken string) string { // Submit button document.getElementById('submit-btn').addEventListener('click', function() { - document.getElementById('review-view').style.display = 'none'; - document.getElementById('confirm-view').style.display = 'block'; + var submitBtn = this; + submitBtn.disabled = true; + document.getElementById('submit-error').style.display = 'none'; + + var params = {activities: [], appearances: [], scholarship: []}; + document.querySelectorAll('fieldset').forEach(function(fieldset) { + var legend = fieldset.querySelector('legend'); + var legendText = legend ? legend.textContent.trim() : ''; + var summaryArea = fieldset.querySelector('.section-summary'); + if (!summaryArea) return; + + Array.prototype.forEach.call(summaryArea.children, function(itemDiv) { + var data = JSON.parse(itemDiv.dataset.reportData || '{}'); + if (legendText === 'Scholarship') { + params.scholarship.push({citation: data['scholarship-citation'] || '', hyperlink: data['scholarship-hyperlink'] || ''}); + } else if (legendText === 'Talks and Activities') { + params.activities.push({title: data['talks-title'] || '', description: data['talks-description'] || '', hyperlink: data['talks-hyperlink'] || ''}); + } else if (legendText === 'Media Appearances') { + params.appearances.push({title: data['media-title'] || '', description: data['media-description'] || '', hyperlink: data['media-hyperlink'] || ''}); + } + }); + }); + + fetch('/faculty/activity/api', { + method: 'POST', + headers: {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + JWT}, + body: JSON.stringify({jsonrpc: '2.0', method: 'report_activity', params: params, id: 1}) + }) + .then(function(resp) { return resp.json(); }) + .then(function(result) { + if (result.error) { + submitBtn.disabled = false; + document.getElementById('submit-error').style.display = ''; + return; + } + document.getElementById('review-view').style.display = 'none'; + document.getElementById('confirm-view').style.display = 'block'; + }) + .catch(function() { + submitBtn.disabled = false; + document.getElementById('submit-error').style.display = ''; + }); }); });