Catching edge-cases

This commit is contained in:
CocoByte 2024-07-23 14:37:58 -06:00
parent 72fdcfdac0
commit 711c71c114
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
2 changed files with 31 additions and 26 deletions

View file

@ -1,7 +1,7 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
document.getElementById('copy-summary-btn').addEventListener('click', function() { document.getElementById('copy-summary-btn').addEventListener('click', function() {
/// Generate the summary text /// Generate a rich HTML summary text and copy to clipboard
//------ Organization Type //------ Organization Type
const organizationTypeElement = document.getElementById('id_organization_type'); const organizationTypeElement = document.getElementById('id_organization_type');
@ -20,18 +20,22 @@ document.addEventListener('DOMContentLoaded', function() {
//------ Additional Contacts //------ Additional Contacts
// 1 - Create a hyperlinks map so we can display contact details and also link to the contact // 1 - Create a hyperlinks map so we can display contact details and also link to the contact
const otherContactsDiv = document.querySelector('.form-row.field-other_contacts .readonly'); const otherContactsDiv = document.querySelector('.form-row.field-other_contacts .readonly');
const otherContactLinks = otherContactsDiv.querySelectorAll('a'); let otherContactLinks = [];
if (otherContactsDiv) {
otherContactLinks = otherContactsDiv.querySelectorAll('a');
const nameToUrlMap = {}; const nameToUrlMap = {};
otherContactLinks.forEach(link => { otherContactLinks.forEach(link => {
const name = link.textContent.trim(); const name = link.textContent.trim();
const url = link.href; const url = link.href;
nameToUrlMap[name] = url; nameToUrlMap[name] = url;
}); });
}
// 2 - Iterate through contact details and assemble html for summary // 2 - Iterate through contact details and assemble html for summary
let otherContactsSummary = "" let otherContactsSummary = ""
// Get the table rows of contact details // Get the table rows of contact details
const otherContactsTable = document.querySelector('.form-row.field-other_contacts table tbody'); const otherContactsTable = document.querySelector('.form-row.field-other_contacts table tbody');
if (otherContactsTable) {
const otherContactsRows = otherContactsTable.querySelectorAll('tr'); const otherContactsRows = otherContactsTable.querySelectorAll('tr');
const bulletList = document.createElement('ul'); const bulletList = document.createElement('ul');
otherContactsRows.forEach(contactRow => { otherContactsRows.forEach(contactRow => {
@ -47,6 +51,7 @@ document.addEventListener('DOMContentLoaded', function() {
bulletList.appendChild(listItem); bulletList.appendChild(listItem);
}); });
otherContactsSummary += bulletList.outerHTML otherContactsSummary += bulletList.outerHTML
}
//------ Requested Domains //------ Requested Domains
@ -69,7 +74,7 @@ document.addEventListener('DOMContentLoaded', function() {
const submitterTitle = extractTextById('contact_info_title', submitterDiv); const submitterTitle = extractTextById('contact_info_title', submitterDiv);
const submitterEmail = extractTextById('contact_info_email', submitterDiv); const submitterEmail = extractTextById('contact_info_email', submitterDiv);
const submitterPhone = extractTextById('contact_info_phone', submitterDiv); const submitterPhone = extractTextById('contact_info_phone', submitterDiv);
let submitterInfo = `${submitterName} ${submitterTitle} ${submitterEmail} ${submitterPhone}`; let submitterInfo = `${submitterName}${submitterTitle}${submitterEmail}${submitterPhone}`;
//------ Senior Official //------ Senior Official
@ -79,7 +84,7 @@ document.addEventListener('DOMContentLoaded', function() {
const seniorOfficialTitle = extractTextById('contact_info_title', seniorOfficialDiv); const seniorOfficialTitle = extractTextById('contact_info_title', seniorOfficialDiv);
const seniorOfficialEmail = extractTextById('contact_info_email', seniorOfficialDiv); const seniorOfficialEmail = extractTextById('contact_info_email', seniorOfficialDiv);
const seniorOfficialPhone = extractTextById('contact_info_phone', seniorOfficialDiv); const seniorOfficialPhone = extractTextById('contact_info_phone', seniorOfficialDiv);
let seniorOfficialInfo = `${seniorOfficialName} ${seniorOfficialTitle} ${seniorOfficialEmail} ${seniorOfficialPhone}`; let seniorOfficialInfo = `${seniorOfficialName}${seniorOfficialTitle}${seniorOfficialEmail}${seniorOfficialPhone}`;
const summary = `<strong>Recommendation:</strong></br>` + const summary = `<strong>Recommendation:</strong></br>` +
`<strong>Organization Type:</strong> ${organizationType}</br>` + `<strong>Organization Type:</strong> ${organizationType}</br>` +

View file

@ -32,7 +32,7 @@
{# Phone #} {# Phone #}
{% if user.phone %} {% if user.phone %}
<span id="contact_info_phone">{{ user.phone.as_national }}</span> <span id="contact_info_phone">{{ user.phone }}</span>
<br> <br>
{% else %} {% else %}
None<br> None<br>