diff --git a/src/public/js/eventlineup.js b/src/public/js/eventlineup.js index 9ef8112..ea62833 100644 --- a/src/public/js/eventlineup.js +++ b/src/public/js/eventlineup.js @@ -110,147 +110,6 @@ function refreshFlags(){ } -function copyEmailTable(itemEl, subject, recipients) { - // Create container for the HTML - // [1] - let bcLineup = itemEl.closest(".benchcoach-lineup"); - var container = document.createElement("div"); - var tbl = document.createElement("table"); - - let thead = tbl.createTHead(); - let thead_row = thead.insertRow(); - let thead_row_cell = thead_row.insertCell(); - thead_row_cell.appendChild(document.createElement("h3").appendChild(document.createTextNode("STARTING LINEUP"))); - thead_row_cell.colSpan = 3; - thead_row_cell.classList.add("title-cell"); - var tbody = tbl.createTBody(); - for (row of bcLineup.querySelector(".table-benchcoach-startinglineup").rows) { - let tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - cell.appendChild(document.createTextNode(parseInt(row.dataset.order) + 1)); - cell = tr.insertCell(); - cell.appendChild(document.createTextNode(row.dataset.playerName)); - cell.classList.add("name-cell"); - tr.insertCell().appendChild(document.createTextNode(row.dataset.position)); - } - - if (bcLineup.querySelector(".table-benchcoach-startingpositionalonly").rows.length > 0) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.colSpan = 3; - cell.appendChild(document.createTextNode("STARTING (POS. ONLY)")); - cell.classList.add("title-cell"); - - for (row of bcLineup.querySelector(".table-benchcoach-startingpositionalonly").rows) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - cell.appendChild(document.createTextNode("")); - cell = tr.insertCell(); - cell.appendChild(document.createTextNode(row.dataset.playerName)); - cell.classList.add("name-cell"); - tr.insertCell().appendChild(document.createTextNode(row.dataset.position)); - } - } - - if (bcLineup.querySelector(".table-benchcoach-bench").rows.length > 0) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.colSpan = 3; - cell.appendChild(document.createTextNode("SUBS")); - cell.classList.add("title-cell"); - - for (row of bcLineup.querySelector(".table-benchcoach-bench").rows) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - availability_status = { - None: "UNK", - 0: "NO", - 2: "MAY", - 1: "YES", - }[row.dataset.availabilityStatuscode]; - cell.appendChild(document.createTextNode(availability_status)); - cell = tr.insertCell(); - cell.appendChild(document.createTextNode(row.dataset.playerName)); - cell.classList.add("name-cell"); - tr.insertCell().appendChild(document.createTextNode("")); - } - } - - if (bcLineup.querySelector(".table-benchcoach-out").rows.length > 0) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.colSpan = 3; - cell.appendChild(document.createTextNode("OUT")); - cell.classList.add("title-cell"); - - for (row of bcLineup.querySelector(".table-benchcoach-out").rows) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - availability_status = { - None: "UNK", - 0: "NO", - 1: "MAY", - 2: "YES", - }[row.dataset.availabilityStatuscode]; - cell.appendChild(document.createTextNode(availability_status)); - tr.insertCell().appendChild(document.createTextNode(row.dataset.playerName)); - tr.insertCell().appendChild(document.createTextNode("")); - } - } - - container.appendChild(tbl); - for (cell of container.getElementsByClassName("title-cell")) { - cell.setAttribute("style", "font-weight:bold;background-color:#323669;color:#fff;padding:2px 5px;"); - } - - for (cell of container.getElementsByClassName("sequence-cell")) { - cell.setAttribute("style", "font-weight:bold;padding:2px 5px;"); - } - - for (cell of container.getElementsByClassName("name-cell")) { - cell.setAttribute("style", "width:200px;"); - } - - // Detect all style sheets of the page - var activeSheets = Array.prototype.slice.call(document.styleSheets).filter(function (sheet) { - return !sheet.disabled; - }); - - // Mount the container to the DOM to make `contentWindow` available - // [3] - document.body.appendChild(container); - - // Copy to clipboard - // [4] - window.getSelection().removeAllRanges(); - - var range = document.createRange(); - range.selectNode(container); - window.getSelection().addRange(range); - - // [5.1] - document.execCommand("copy"); - - // [5.2] - for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = true; - - // [5.3] - // document.execCommand('copy') - - // [5.4] - for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = false; - - // Remove the container - // [6] - document.body.removeChild(container); - subject_encoded = encodeURIComponent(subject); - window.open("readdle-spark://compose?recipient=manager@chihounds.com&subject=" + subject + "&bcc=" + recipients); -} - function emailModal(el, url) { form = el.closest("form"); console.log(form) @@ -341,184 +200,6 @@ async function onSubmit(form, event) { }, 3000) } -function copyEmailTable(itemEl, subject, recipients) { - // Create container for the HTML - // [1] - let bcLineup = itemEl.closest(".event-lineup"); - var container = document.createElement("div"); - var tbl = document.createElement("table"); - - let thead = tbl.createTHead(); - let thead_row = thead.insertRow(); - let thead_row_cell = thead_row.insertCell(); - thead_row_cell.appendChild(document.createElement("h3").appendChild(document.createTextNode("STARTING LINEUP"))); - thead_row_cell.colSpan = 3; - thead_row_cell.classList.add("title-cell"); - var tbody = tbl.createTBody(); - - lineup_slots_starting = bcLineup.querySelectorAll(".starting .slot-set .lineup-slot"); - - for (node of lineup_slots_starting) { - console.log("node", node); - let tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - sequence = node.querySelector("input[name*='sequence']").value; - console.log(sequence); - cell.appendChild(document.createTextNode(parseInt(sequence) + 1)); - name = node.querySelector("div:has(.lastname)"); - cell = tr.insertCell(); - cell.appendChild(document.createTextNode(name.textContent)); - cell.classList.add("name-cell"); - position_label = node.querySelector("input[name*='label']").value; - tr.insertCell().appendChild(document.createTextNode(position_label)); - } - - lineup_slots_position_only = bcLineup.querySelector(".position-only .slot-set .lineup-slot"); - console.log("lineup slots position", lineup_slots_position_only); - if (lineup_slots_position_only.length > 0) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.colSpan = 3; - cell.appendChild(document.createTextNode("STARTING (POS. ONLY)")); - cell.classList.add("title-cell"); - - for (node of lineup_slots_position_only) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - cell.appendChild(document.createTextNode("")); - cell = tr.insertCell(); - name = node.querySelector("div:has(.lastname)"); - cell.appendChild(document.createTextNode(name.textCotent)); - cell.classList.add("name-cell"); - position_label = node.querySelector("input[name*='label']").value; - tr.insertCell().appendChild(document.createTextNode(position_label)); - } - } - - lineup_slots_bench = bcLineup.querySelector(".bench .slot-set .lineup-slot"); - if (lineup_slots_bench > 0) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.colSpan = 3; - cell.appendChild(document.createTextNode("SUBS")); - cell.classList.add("title-cell"); - - for (node of lineup_slots_bench) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - - div_avail_code = node.querySelector("div[class*='availability-status-code']"); - if (div_with_avail_code.classList.includes("availability-status-code-1")) { - cell.appendChild(document.createTextNode("YES")); - } else if (div_with_avail_code.classList.includes("availability-status-code-2")) { - cell.appendChild(document.createTextNode("MAY")); - } else if (div_with_avail_code.classList.includes("availability-status-code-0")) { - cell.appendChild(document.createTextNode("NO")); - } else { - cell.appendChild(document.createTextNode("UNK")); - } - cell = tr.insertCell(); - name = node.querySelector("div:has(.lastname)"); - cell.appendChild(document.createTextNode(name.textCotent)); - cell.classList.add("name-cell"); - tr.insertCell().appendChild(document.createTextNode("")); - } - } - - lineup_slots_out = bcLineup.querySelector(".out .slot-set .lineup-slot"); - if (lineup_slots_out > 0) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.colSpan = 3; - cell.appendChild(document.createTextNode("OUT")); - cell.classList.add("title-cell"); - - for (node of lineup_slots_out) { - var tr = tbody.insertRow(); - cell = tr.insertCell(); - cell.classList.add("sequence-cell"); - div_avail_code = node.querySelector("div[class*='availability-status-code']"); - if (div_with_avail_code.classList.includes("availability-status-code-1")) { - cell.appendChild(document.createTextNode("YES")); - } else if (div_with_avail_code.classList.includes("availability-status-code-2")) { - cell.appendChild(document.createTextNode("MAY")); - } else if (div_with_avail_code.classList.includes("availability-status-code-0")) { - cell.appendChild(document.createTextNode("NO")); - } else { - cell.appendChild(document.createTextNode("UNK")); - } - cell = tr.insertCell(); - name = node.querySelector("div:has(.lastname)"); - cell.appendChild(document.createTextNode(name.textCotent)); - cell.classList.add("name-cell"); - tr.insertCell().appendChild(document.createTextNode("")); - } - } - - container.appendChild(tbl); - for (cell of container.getElementsByClassName("title-cell")) { - cell.setAttribute("style", "font-weight:bold;background-color:#323669;color:#fff;padding:2px 5px;"); - } - - for (cell of container.getElementsByClassName("sequence-cell")) { - cell.setAttribute("style", "font-weight:bold;padding:2px 5px;"); - } - - for (cell of container.getElementsByClassName("name-cell")) { - cell.setAttribute("style", "width:200px;"); - } - - // Detect all style sheets of the page - var activeSheets = Array.prototype.slice.call(document.styleSheets).filter(function (sheet) { - return !sheet.disabled; - }); - - // Mount the container to the DOM to make `contentWindow` available - // [3] - document.body.appendChild(container); - - // Copy to clipboard - // [4] - window.getSelection().removeAllRanges(); - - var range = document.createRange(); - range.selectNode(container); - window.getSelection().addRange(range); - - // [5.1] - document.execCommand("copy"); - - // [5.2] - for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = true; - - // [5.3] - // document.execCommand('copy') - - // [5.4] - for (var i = 0; i < activeSheets.length; i++) activeSheets[i].disabled = false; - - // Remove the container - // [6] - document.body.removeChild(container); - subject_encoded = encodeURIComponent(subject); - window.open("readdle-spark://compose?recipient=manager@chihounds.com&subject=" + subject + "&bcc=" + recipients); -} - -function toggleChildSlots (element) { - console.log(element); - console.log(element.closest(".slot-set")) - for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) { - console.log(lineup_slot) - const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box), button:has(+.position-label-flags)') - Array.from(cells).forEach(cell=>{ - cell.classList.toggle('u-hidden') - }) - } -} - async function copyEmailTable (element) { // range=document.createRange(); // window.getSelection().removeAllRanges(); @@ -582,6 +263,30 @@ async function copyEmailTable (element) { window.getSelection().removeAllRanges(); } +function toggleChildSlots (element) { + console.log(element); + console.log(element.closest(".slot-set")) + for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) { + console.log(lineup_slot) + const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box), button:has(+.position-label-flags)') + Array.from(cells).forEach(cell=>{ + cell.classList.toggle('u-hidden') + }) + } +} + + +function initSlots () { + const slots = Array.from(document.querySelectorAll('.lineup-slot')) + slots.forEach(slot=>{ + if (slot.dataset.initialSlotset) { + const parent = document.querySelector(`#${slot.dataset.initialSlotset} .slot-set`) + parent.appendChild(slot) + slot.removeAttribute('data-initial-slotset') + } + }) +} + function insertLineup(direction, teamId, eventId, element) { const currentUrl = window.location.href; let search_params @@ -637,16 +342,6 @@ function insertLineup(direction, teamId, eventId, element) { } -function initSlots () { - const slots = Array.from(document.querySelectorAll('.lineup-slot')) - slots.forEach(slot=>{ - if (slot.dataset.initialSlotset) { - const parent = document.querySelector(`#${slot.dataset.initialSlotset} .slot-set`) - parent.appendChild(slot) - slot.removeAttribute('data-initial-slotset') - } - }) -} function initPage (){ colorPositions(); initSlots(); diff --git a/src/routes/event.js b/src/routes/event.js index f7ce0d6..7d1c787 100644 --- a/src/routes/event.js +++ b/src/routes/event.js @@ -71,7 +71,5 @@ router.use("/:team_id([0-9]+)/event/:event_id([0-9]+)", loadEvent) router.get("/:team_id([0-9]+)/schedule", eventsController.getEvents); router.get("/:team_id([0-9]+)/event/:event_id([0-9]+)", eventsController.getEvent); router.post("/:team_id([0-9]+)/event/:event_id([0-9]+)/availability_reminders", upload.none(), eventsController.sendAvailabilityReminders) -// router.get("/:team_id([0-9]+)/event/:event_id([0-9]+)/lineup", eventsController.getLineup); -// router.get("/:team_id([0-9]+)/event/:event_id([0-9]+)/lineup_card", eventsController.getLineupCard); module.exports = {router, loadEvent, loadEvents} \ No newline at end of file