Teams handing in progress

This commit is contained in:
Claude Brisson
2024-04-15 16:33:17 +02:00
parent 2395c4e071
commit 179a502bbc
20 changed files with 249 additions and 68 deletions

View File

@@ -81,36 +81,43 @@ function updatePairable() {
}
onLoad(()=>{
// note - this handler is also in use for lists on Mac Mahon super groups and teams pages
$('.listitem').on('click', e => {
let listitem = e.target.closest('.listitem');
let box = e.target.closest('.multi-select');
if (e.shiftKey && typeof(focused) !== 'undefined') {
let from = focused.index('.listitem');
let to = e.target.closest('.listitem').index('.listitem');
let to = listitem.index('.listitem');
if (from > to) {
let tmp = from;
from = to;
to = tmp;
}
let parent = e.target.closest('.multi-select');
let children = parent.childNodes.filter('.listitem');
let children = box.childNodes.filter('.listitem');
for (let j = from; j <= to; ++j) { new Tablesort($('#players')[0]);
children.item(j).addClass('selected');
children.item(j).attr('draggable', true);
}
} else {
let target = e.target.closest('.listitem');
if (e.detail === 1) {
focused = target.toggleClass('selected').attr('draggable', target.hasClass('selected'));
} else if (target.closest('#paired')) {
focused = target.attr('draggable', target.hasClass('selected'));
editGame(focused);
} else {
editPairable(focused);
// single click
focused = listitem.toggleClass('selected').attr('draggable', listitem.hasClass('selected'));
} else if (listitem.closest('#pairing-lists')) {
// on pairing page
if (listitem.closest('#paired')) {
// double click
focused = listitem.attr('draggable', listitem.hasClass('selected'));
editGame(focused);
} else if (listitem.closest('#pairables')) {
editPairable(focused);
}
}
}
box.dispatchEvent(new CustomEvent('listitems'));
});
$('#pair').on('click', e => {
let parts = $('#pairables .selected.listitem').map(item => parseInt(item.data("id")));
if (parts.length == 0) {
if (parts.length) {
$('#pairables .listitem').addClass('selected');
parts = $('#pairables .selected.listitem').map(item => parseInt(item.data("id")));
}

View File

@@ -0,0 +1,44 @@
function teamUp(players) {
api.postJson(`tour/${tour_id}/team`, {
"name": $('#team-name')[0].value,
"players": players
}).then(rst => {
if (rst !== 'error') {
document.location.reload();
}
});
}
function split(teams) {
let promises = teams.map(team => api.deleteJson(`tour/${tour_id}/team/${team}`));
Promise.all(promises)
.then(rsts => {
for (let rst of rsts) {
if (!rst.success) console.error(rst.error)
}
document.location.reload();
});
}
onLoad(() => {
$('#teamup').on('click', e => {
let rows = $('#teamables .selected.listitem')
let players = rows.map(item => parseInt(item.data("id")));
if (players.length !== 0) teamUp(players);
});
$('#split').on('click', e => {
let rows = $('#teams .selected.listitem')
let teams = rows.map(item => parseInt(item.data("id")));
if (teams.length !== 0) split(teams);
});
$('#teamables').on('listitems', () => {
let rows = $('#teamables .selected.listitem');
if (rows.length === teamSize) {
$('#team-name')[0].value = rows.map(row => row.data('name')).join('-');
$('#teamup').removeClass('disabled');
} else {
$('#team-name')[0].value = '';
$('#teamup').addClass('disabled');
}
});
});