add insert lineup before and after

This commit is contained in:
2024-03-15 14:19:14 -05:00
parent dc17ca76ba
commit f2371c6b5a
12 changed files with 305 additions and 221 deletions

View File

@@ -49,7 +49,6 @@ function initFlagsCheckboxes(){
)
).forEach((slot, i) => {
const flags = new Set(slot.querySelector("input[name*=flags]")?.value?.split(',')?.map(s=>s.trim())) || new Set()
console.log(slot, flags)
if (flags.has('DHd')) {
slot.querySelector('[name=flag-dhd]').checked = true;
}
@@ -106,44 +105,6 @@ function refreshLineup() {
});
}
for (bcLineup of document.querySelectorAll("[id^=event-lineup]")) {
options = {
animation: 150,
handle: ".Panel-cell:has(.drag-handle), .Panel-cell:has(.sequence)",
ghostClass: "ghost",
group: {
name: bcLineup.id,
put: [bcLineup.id],
pull: [bcLineup.id],
},
onAdd: function (/**Event*/ evt) {
console.log("added to lineup");
// Add to Lineup
var itemEl = evt.item; // dragged HTMLElement
refreshLineup();
},
onUpdate: function (/**Event*/ evt) {
console.log("update to lineup");
// var itemEl = evt.item; // dragged HTMLElement
// refresh_lineup_order(itemEl);
refreshLineup();
},
};
new Sortable.create(bcLineup.querySelector("[id^=lineup-starting] .slot-set"), options);
new Sortable.create(bcLineup.querySelector("[id^=lineup-positiononly] .slot-set"), options);
options["sort"] = false;
new Sortable.create(bcLineup.querySelector("[id^=lineup-bench] .slot-set"), options);
new Sortable.create(bcLineup.querySelector("[id^=lineup-out] .slot-set"), {...options, group:{...options.group, put:[]}});
}
for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) {
const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box), div.position-label-flags')
Array.from(cells).forEach(cell=>{
cell.classList.add('u-hidden')
})
}
function refreshFlags(){
}
@@ -293,8 +254,6 @@ function emailModal(el, url) {
form = el.closest("form");
data = new FormData(form);
email_modal = document.querySelector("#modal");
fetch(url, {
method: "POST",
body: data,
@@ -309,12 +268,25 @@ function emailModal(el, url) {
return Promise.reject(response.text());
}
})
.then((lineup_table) => {
const email_textarea = document.querySelector('#email-editor')
const lineup_table_div = document.querySelector(".FieldGroup .lineup-email")
tinymce.activeEditor.setContent("Team,")
lineup_table_div.innerHTML = lineup_table
email_modal.classList.add("is-open");
.then((html) => {
const parser = new DOMParser()
const email_modal = parser.parseFromString(html, 'text/html')
const email_modal_node = email_modal.firstElementChild.querySelector('#modal')
email_modal_node.setAttribute('id', `lineup-email-data-${data.get('event_lineup_id')}`)
const body = document.querySelector('body')
email_modal_node.classList.add('is-open')
body.appendChild(email_modal_node)
tinymce.init({
selector:`#lineup-email-data-${data.get('event_lineup_id')} #email-editor`,
content_css:"/css/application.css",
plugins: 'image',
menubar: false,
toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | outdent indent | image',
paste_data_images: true,
statusbar:false})
// tinymce.activeEditor.setContent("Team,")
// lineup_table_div.innerHTML = lineup_table
// email_modal.classList.add("is-open");
// email_modal.querySelector(".Modal-body").innerHTML = html;
});
}
@@ -595,4 +567,87 @@ async function submitEmail () {
'text/html': new Blob([html_content], {type: 'text/html'})
})
])
}
}
function insertLineup(direction, teamId, eventId, element) {
const currentUrl = window.location.href;
let search_params
if (Number(direction) > 0) {
search_params = new URLSearchParams({
page_size:1,
index: 1
})
} else if (Number(direction) < 0) {
search_params = new URLSearchParams({
page_size:1,
index: -1
})
} else {throw new Error("Needs to be a negative number or a positive number")}
fetch(`/${teamId}/event/${eventId}/lineup/adjacent?`+search_params, {
method: "GET"
})
.then((response) => {
if (response.ok) {
return response.text();
} else {
return Promise.reject(response.text());
}
})
.then((html) =>{
const parser = new DOMParser();
const new_lineup_doc = parser.parseFromString(html, 'text/html')
const new_lineup_doc_node = new_lineup_doc.firstElementChild.querySelector('[id*=event-lineup]')
const lineup_container = document.querySelector("#lineup-container")
direction > 0 ? lineup_container.appendChild(new_lineup_doc_node) : lineup_container.insertBefore(new_lineup_doc_node, element.closest('[id*=event-lineup]'))
initPage();
})
}
function initPage (){
colorPositions();
initFlagsCheckboxes();
refreshLineup();
for (bcLineup of document.querySelectorAll("[id^=event-lineup]")) {
options = {
animation: 150,
handle: ".Panel-cell:has(.drag-handle), .Panel-cell:has(.sequence)",
ghostClass: "ghost",
group: {
name: bcLineup.id,
put: [bcLineup.id],
pull: [bcLineup.id],
},
onAdd: function (/**Event*/ evt) {
console.log("added to lineup");
// Add to Lineup
var itemEl = evt.item; // dragged HTMLElement
refreshLineup();
},
onUpdate: function (/**Event*/ evt) {
console.log("update to lineup");
// var itemEl = evt.item; // dragged HTMLElement
// refresh_lineup_order(itemEl);
refreshLineup();
},
};
new Sortable.create(bcLineup.querySelector("[id^=lineup-starting] .slot-set"), options);
new Sortable.create(bcLineup.querySelector("[id^=lineup-positiononly] .slot-set"), options);
options["sort"] = false;
new Sortable.create(bcLineup.querySelector("[id^=lineup-bench] .slot-set"), options);
new Sortable.create(bcLineup.querySelector("[id^=lineup-out] .slot-set"), {...options, group:{...options.group, put:[]}});
}
for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) {
const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box), div.position-label-flags')
Array.from(cells).forEach(cell=>{
cell.classList.add('u-hidden')
})
}
}
document.addEventListener('DOMContentLoaded', initPage)