Pipeline Status Report

Pulls your live deals from the monday.com Pipeline board and groups them by status, ready to send to your TC and escrow.

Click any Notes cell to type a note. Notes save to the "Report Notes" column on the deal in monday.com and go into the email and PDF.
'; } function createHtmlDraft(html, to){ msg("Connecting to Gmail…"); withGmailToken(function(token){ msg("Creating the Gmail draft…"); var mime = [ to ? "To: " + to : null, "Subject: =?UTF-8?B?" + b64utf8(subjectLine()) + "?=", "MIME-Version: 1.0", "Content-Type: text/html; charset=UTF-8", "Content-Transfer-Encoding: base64", "", b64utf8(htmlEmail(html)).replace(/(.{76})/g, "$1\r\n") ].filter(function(l){ return l !== null; }).join("\r\n"); fetch("https://gmail.googleapis.com/gmail/v1/users/me/drafts", { method:"POST", headers:{"Authorization":"Bearer " + token, "Content-Type":"application/json"}, body:JSON.stringify({message:{raw:b64url(mime)}}) }).then(function(r){ return r.json().then(function(j){ if(!r.ok) throw new Error((j.error && j.error.message) || ("Gmail error " + r.status)); return j; }); }).then(function(d){ var link = "https://mail.google.com/mail/u/0/#drafts?compose=" + encodeURIComponent(d.message.id); var w = window.open(link, "_blank"); var m = $("llp-msg"); m.className = "llp-msg"; m.innerHTML = ""; m.appendChild(document.createTextNode(w ? "Draft created in Gmail with the formatted report. " : "Draft created in Gmail. ")); var a = document.createElement("a"); a.href = link; a.target = "_blank"; a.rel = "noopener"; a.textContent = "Open the draft"; m.appendChild(a); }).catch(function(e){ if(/invalid|expired|401/i.test(e.message)){ gToken = null; } msg("Couldn't create the Gmail draft: " + e.message, true); }); }); } function createGmail(){ var html = reportHTML(); if(!html) return; var to = $("llp-to").value.trim(); keySet(TO_KEY, to); if(GOOGLE_CLIENT_ID){ createHtmlDraft(html, to); return; } // Copy the formatted report (synchronously, before Gmail takes focus), then open a Gmail compose window. var box = document.createElement("div"); box.style.cssText = "position:fixed;left:-10000px;top:0;width:1000px;background:#fff;"; box.innerHTML = html; document.body.appendChild(box); var r = document.createRange(), sel = window.getSelection(); r.selectNodeContents(box); sel.removeAllRanges(); sel.addRange(r); var ok = false; try { ok = document.execCommand("copy"); } catch(e){} sel.removeAllRanges(); document.body.removeChild(box); // The message body is filled in automatically with a plain-text version of the report. var body = plainText(lastDeals), trimmed = false; var MAX = 7000; // keep the Gmail link under the length Gmail accepts if(encodeURIComponent(body).length > MAX){ while(encodeURIComponent(body).length > MAX - 300) body = body.slice(0, body.lastIndexOf("\n")); body += "\n\n[Report shortened. The full formatted report is on the clipboard: paste it here.]"; trimmed = true; } var url = "https://mail.google.com/mail/?view=cm&fs=1&su=" + encodeURIComponent(reportTitle()) + (to ? "&to=" + encodeURIComponent(to) : "") + "&body=" + encodeURIComponent(body); var w = window.open(url, "_blank"); if(!w){ msg("Allow pop-ups for this site so Gmail can open.", true); return; } msg(trimmed ? "Gmail opened with a shortened report. Paste (Ctrl+V / Cmd+V) to add the full formatted version." : "Gmail opened with the report filled in." + (ok ? " Prefer the formatted tables? Select all in the message body and paste (Ctrl+V / Cmd+V) to replace it." : "")); } function printReport(){ var html = reportHTML(); if(!html) return; var w = window.open("", "_blank"); if(!w){ msg("Allow pop-ups for this site to print.", true); return; } w.document.write('' + esc(reportTitle()) + '' + html + ''); w.document.close(); w.focus(); setTimeout(function(){ w.print(); }, 300); } /* ---------------- Init ---------------- */ var saved = storeGet(); if(saved){ $("llp-token").value = saved; $("llp-remember").checked = true; } $("llp-go").addEventListener("click", generate); $("llp-token").addEventListener("keydown", function(e){ if(e.key === "Enter") generate(); }); $("llp-forget").addEventListener("click", function(){ storeSet(""); $("llp-token").value = ""; $("llp-remember").checked = false; msg("Saved token removed from this device."); }); $("llp-gmail").addEventListener("click", createGmail); $("llp-print").addEventListener("click", printReport); $("llp-to").value = keyGet(TO_KEY); $("llp-report").addEventListener("input", function(e){ var t = e.target; if(t && t.getAttribute && t.getAttribute("data-note")){ var id = t.getAttribute("data-note"), txt = t.innerText.trim(); noteSave(id, txt); queueNotePush(id, txt); } }); $("llp-report").addEventListener("focusout", function(e){ var t = e.target; if(t && t.getAttribute && t.getAttribute("data-note")) flushNote(t.getAttribute("data-note")); }); // Exposed for testing only window.__llp = {render:render, toDeal:toDeal, plainText:plainText, syncNotes:syncNotes, setToken:function(t){ mondayToken = t; }, queueNotePush:queueNotePush, flushNote:flushNote}; })();