mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-14 21:44:08 +02:00
Catching edge-cases
This commit is contained in:
parent
72fdcfdac0
commit
711c71c114
2 changed files with 31 additions and 26 deletions
|
@ -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,33 +20,38 @@ 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 = [];
|
||||||
const nameToUrlMap = {};
|
if (otherContactsDiv) {
|
||||||
otherContactLinks.forEach(link => {
|
otherContactLinks = otherContactsDiv.querySelectorAll('a');
|
||||||
const name = link.textContent.trim();
|
const nameToUrlMap = {};
|
||||||
const url = link.href;
|
otherContactLinks.forEach(link => {
|
||||||
nameToUrlMap[name] = url;
|
const name = link.textContent.trim();
|
||||||
});
|
const url = link.href;
|
||||||
|
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');
|
||||||
const otherContactsRows = otherContactsTable.querySelectorAll('tr');
|
if (otherContactsTable) {
|
||||||
const bulletList = document.createElement('ul');
|
const otherContactsRows = otherContactsTable.querySelectorAll('tr');
|
||||||
otherContactsRows.forEach(contactRow => {
|
const bulletList = document.createElement('ul');
|
||||||
// Extract the contact details
|
otherContactsRows.forEach(contactRow => {
|
||||||
const name = contactRow.querySelector('th').textContent.trim();
|
// Extract the contact details
|
||||||
const title = contactRow.querySelectorAll('td')[0].textContent.trim();
|
const name = contactRow.querySelector('th').textContent.trim();
|
||||||
const email = contactRow.querySelectorAll('td')[1].textContent.trim();
|
const title = contactRow.querySelectorAll('td')[0].textContent.trim();
|
||||||
const phone = contactRow.querySelectorAll('td')[2].textContent.trim();
|
const email = contactRow.querySelectorAll('td')[1].textContent.trim();
|
||||||
const url = nameToUrlMap[name] || '#';
|
const phone = contactRow.querySelectorAll('td')[2].textContent.trim();
|
||||||
// Format the contact information
|
const url = nameToUrlMap[name] || '#';
|
||||||
const listItem = document.createElement('li');
|
// Format the contact information
|
||||||
listItem.innerHTML = `<a href="${url}">${name}</a>, ${title}, ${email}, ${phone}`;
|
const listItem = document.createElement('li');
|
||||||
bulletList.appendChild(listItem);
|
listItem.innerHTML = `<a href="${url}">${name}</a>, ${title}, ${email}, ${phone}`;
|
||||||
});
|
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>` +
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue