From a858a267c84bb2ad4b73ba8c9916406e36f565b7 Mon Sep 17 00:00:00 2001 From: Dinne Kopelevich Date: Thu, 5 Jun 2025 07:24:14 -0600 Subject: [PATCH] Add email functionality Signed-off-by: Dinne Kopelevich --- index.html | 1 + js/formDataToJson.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/index.html b/index.html index 5f9e7de..80ca1d2 100644 --- a/index.html +++ b/index.html @@ -78,6 +78,7 @@ + diff --git a/js/formDataToJson.js b/js/formDataToJson.js index 157aeae..9b8f0a0 100644 --- a/js/formDataToJson.js +++ b/js/formDataToJson.js @@ -322,7 +322,37 @@ async function downloadFile(event) { link.click(); } +// Triggers email(mailtolink) +async function emailFile(event) { + event.preventDefault(); + + const codeJson = document.getElementById("json-result").value + const jsonObject = JSON.parse(codeJson); + + try { + const cleanData = {...jsonObject}; + delete cleanData.submit; + + const jsonString = JSON.stringify(cleanData, null, 2); + + const subject = "Code.json generator Results"; + const body = `Hello,\n\nHere are the code.json results:\n\n${jsonString}\n\nThank you!`; + + const recipients = ["opensource@cms.hhs.gov"]; + + const mailtoLink = `mailto:${recipients}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; + + window.location.href = mailtoLink; + + console.log("Email client opened"); + } catch { + console.error("Error preparing email:", error); + showNotificationModal("Error preparing email. Please try again or copy the data manually.", 'error'); + } +} + window.createCodeJson = createCodeJson; window.copyToClipboard = copyToClipboard; window.downloadFile = downloadFile; window.createProjectPR = createProjectPR; +window.emailFile = emailFile;