call api to submit after clicking the submit button

master
Joshua Herring 3 weeks ago
parent 989aa547a1
commit c53482cbe3

@ -135,6 +135,9 @@ func MainFormPage(jwtToken string) string {
<button class="rvt-button rvt-button--secondary" type="button" id="return-btn">Return to Input</button>
<button class="rvt-button" type="button" id="submit-btn">Submit</button>
</div>
<div id="submit-error" class="rvt-alert rvt-alert--danger rvt-m-top-lg" role="alert" aria-live="polite" style="display:none">
<div class="rvt-alert__message">Something went wrong. We apologize for the inconvenience. Please return and resubmit your items later. If you continue to encounter difficulties, please report this to the Associate Dean for Research and Faculty Affairs.</div>
</div>
</div>
<!-- Confirmation view -->
@ -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 = '';
});
});
});

Loading…
Cancel
Save