From 721e91aac75b77742c229dc7516d03fe865bd3b8 Mon Sep 17 00:00:00 2001 From: Rebecca Hsieh Date: Wed, 17 Jul 2024 11:05:09 -0700 Subject: [PATCH] Add in js file --- src/registrar/assets/js/copy-summary.js | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/registrar/assets/js/copy-summary.js diff --git a/src/registrar/assets/js/copy-summary.js b/src/registrar/assets/js/copy-summary.js new file mode 100644 index 000000000..42cedf008 --- /dev/null +++ b/src/registrar/assets/js/copy-summary.js @@ -0,0 +1,34 @@ + +document.addEventListener('DOMContentLoaded', function() { + document.getElementById('copy-summary-btn').addEventListener('click', function() { + // Generate the summary text + const organizationType = document.getElementById('id_organization_type').value; + const requestedDomain = document.getElementById('id_requested_domain').value; + const existingWebsites = Array.from(document.querySelectorAll('#id_current_websites')).map(el => el.text).join(', '); + const alternativeDomains = Array.from(document.querySelectorAll('#id_alternative_domains')).map(el => el.text).join(', '); + const submitter = document.getElementById('id_submitter').value; + const seniorOfficial = document.getElementById('id_senior_official').value; + const otherContacts = Array.from(document.querySelectorAll('#id_other_contacts option:checked')).map(el => el.text).join('\n* '); + + const summary = `*Recommendation:*\n\n` + + `*Organization Type:* ${organizationType}\n\n` + + `*Requested Domain:* ${requestedDomain}\n\n` + + `*Existing website(s):*\n${existingWebsites}\n\n` + + `*Rationale:*\n\n` + + `*Alternate Domain(s):*\n* ${alternativeDomains.split(', ').join('\n* ')}\n\n` + + `*Submitter:*\n\n* ${submitter}\n\n` + + `*Senior Official:*\n\n* ${seniorOfficial}\n\n` + + `*Additional Contact(s):*\n\n* ${otherContacts}\n\n`; + + // Create a temporary textarea element to hold the summary + const textArea = document.createElement('textarea'); + textArea.value = summary; + document.body.appendChild(textArea); + textArea.select(); + document.execCommand('copy'); + document.body.removeChild(textArea); + + alert('Summary copied to clipboard!'); + alert("hello"); + }); +});