Game edition ok, and other minor tweaks

This commit is contained in:
Claude Brisson
2024-01-19 05:43:07 +01:00
parent 897246c7a6
commit cffa4ce699
9 changed files with 131 additions and 14 deletions

View File

@@ -18,6 +18,26 @@ function unpair(games) {
});
}
function editGame(game) {
let t = game.find('.table');
let w = game.find('.white');
let b = game.find('.black');
let h = game.find('.handicap');
let form = $('#pairing-form')[0];
form.val('id', game.data('id'));
form.val('t', t.data('value'));
form.val('w', w.data('id'));
$('#edit-pairing-white').text(w.text());
form.val('b', b.data('id'));
$('#edit-pairing-black').text(b.text());
form.val('h', h.data('value'));
$('#update-pairing').addClass('disabled');
modal('edit-pairing');
}
onLoad(()=>{
$('.listitem').on('click', e => {
if (e.shiftKey && typeof(focused) !== 'undefined') {
@@ -31,13 +51,17 @@ onLoad(()=>{
let parent = e.target.closest('.multi-select');
let children = parent.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');
focused = target.toggleClass('selected').attr('draggable', target.hasClass('selected'));
if (e.detail === 1) {
focused = target.toggleClass('selected').attr('draggable', target.hasClass('selected'));
} else {
focused = target.attr('draggable', target.hasClass('selected'));
editGame(focused);
}
}
});
$('#pair').on('click', e => {
@@ -56,4 +80,39 @@ onLoad(()=>{
}
unpair(games);
});
$('#pairing-form [name]').on('input', e => {
$('#update-pairing').removeClass('disabled');
});
$('#pairing-exchange').on('click', e => {
let form = $('#pairing-form')[0];
let w = form.val('w');
let b = form.val('b');
form.val('w', b);
form.val('b', w);
let wName = $('#edit-pairing-white').text();
let bName = $('#edit-pairing-black').text();
$('#edit-pairing-white').text(bName);
$('#edit-pairing-black').text(wName);
$('#update-pairing').removeClass('disabled');
});
$('#pairing-form').on('submit', e => {
e.preventDefault();
return false;
});
$('#update-pairing').on('click', e => {
let form = $('#pairing-form')[0];
let game = {
id: form.val('id'),
t: form.val('t'),
w: form.val('w'),
b: form.val('b'),
h: form.val('h')
}
api.putJson(`tour/${tour_id}/pair/${activeRound}`, game)
.then(game => {
if (game !== 'error') {
document.location.reload();
}
});
});
});