Untitled
unknown
plain_text
a year ago
6.4 kB
6
Indexable
if (players[0]['submitted'] != 1) {
// Inicializar el select del modal con las opciones de scoring
const modalSelect = $('#modalScoring');
const options = target["scoring"].split(',');
options.forEach(function (value) {
value = value.trim();
var option = document.createElement('option');
option.innerHTML = value;
if (value == 'M') {
value = 0;
}
if (value == 'X' || value == 'x') {
value = target['value_of_x'] ?? 10;
}
option.setAttribute('value', value);
modalSelect.append(option);
});
let activeCell = null;
// Manejar el click en una celda
$("th.ends").on('click', function() {
$('.bg-teal').removeClass('bg-teal');
$(this).addClass('bg-teal');
activeCell = $(this);
// Reset del select
modalSelect.val('');
// Mostrar el modal
$('#scoringModal').modal('show');
});
// Manejar la confirmación del score
$('#confirmScore').on('click', function() {
if (!activeCell) return;
const selectedValue = modalSelect.val();
const selectedLabel = modalSelect.find('option:selected').text();
if (!selectedValue) return;
resetTimer();
var input = activeCell.find("input[id*='_arrow_']").filter(function () {
return $(this).val() == "";
}).eq(0);
if (input.length == 0) {
input = activeCell.find("input[id*='_arrow_']").eq(0);
}
var id = input.attr('id');
var parts = id.split('_');
var end = parts[1];
var arrow = parts[3];
$(`#${id}`).val(selectedLabel).trigger('change');
$(`#${id}_time`).val(target['timing'] - time);
$(`#${id}_text`).text(selectedLabel);
var end_score = 0;
for (let i = 1; i <= arrows_per_ends; i++) {
let value = $(`input#end_${end}_arrow_${i}`).val();
if (value != '') {
switch (value) {
case 'M':
value = 0;
break;
case 'X':
value = (isNaN(target['value_of_x']) ? 10 : target['value_of_x']);
break;
default:
break;
}
end_score += parseInt(value);
}
}
$(`.end_${end}_score span`).text(end_score);
$(`#end_${end}_score`).val(end_score);
$(`[name="end[${end}][score]"]`).text(end_score);
// populate running score
for (let i = 1; i <= total_number_of_ends; i++) {
var end_running = $(`.end_${i-1}_running`).text();
end_running = parseInt(end_running);
if (end_running == '' || isNaN(end_running)) {
end_running = 0;
}
let end_score2 = $(`.end_${i}_score span`).text();
end_score2 = parseInt(end_score2);
if (end_score2 == '' || isNaN(end_score2)) {
end_score2 = 0;
}
$(`.end_${i}_running`).text(end_running + end_score2);
running_score = end_running + end_score2;
}
activeCell.removeClass('bg-teal');
activeCell.addClass('bg-primary');
// Reset tiempo
time = target['timing'];
// Cerrar modal
$('#scoringModal').modal('hide');
// Verificar si es el último arrow
var remainingInputs = $("input[id*='_arrow_']").filter(function () {
return $(this).val() == "";
});
if (remainingInputs.length <= 1) {
$('#time').text('00:00');
$('#scoring').hide();
$('#matchBtn').text('Finish');
$('#matchBtn').show();
$('#scoreDropdown').append(`<div class="card bg-secondary totalScoreDiv">
<div class="card-body">
<div class="mt-0 text-center">
<span class="arrowscore">${getTotalsByScore(user_id)}</span>
</div>
</div>
</div>`);
}
});
// Reset
$("input[id*='_arrow_']").parent().on('click', function () {
$('.bg-teal').removeClass('bg-teal');
$(this).addClass('bg-teal');
$(this).removeClass('bg-primary');
$(this).find('span').text("");
let id = $(this).find('input').attr('id');
id = id.substring(0, id.length - 6);
$(`#${id}`).val("");
$(`#${id}_time`).val(0);
var end_score = 0;
var parts = $(this).find('input').attr('id').split('_');
var end = parts[1];
for (let i = 1; i <= arrows_per_ends; i++) {
let value = $(`input#end_${end}_arrow_${i}`).val();
if (value != '') {
switch (value) {
case 'M':
value = 0;
break;
case 'X':
value = (isNaN(target['value_of_x']) ? 10 : target['value_of_x']);
break;
default:
break;
}
end_score += parseInt(value);
}
}
if (end_score == '' || isNaN(end_score)) {
end_score = 0;
}
$(`.end_${end}_score span`).text(end_score);
$(`#end_${end}_score`).val(end_score);
$(`[name="end[${end}][score]"]`).text(end_score);
// populate running score
for (let i = 1; i <= total_number_of_ends; i++) {
var end_running = $(`.end_${i-1}_running`).text();
end_running = parseInt(end_running);
if (end_running == '' || isNaN(end_running)) {
end_running = 0;
}
let end_score2 = $(`.end_${i}_score span`).text();
end_score2 = parseInt(end_score2);
if (end_score2 == '' || isNaN(end_score2)) {
end_score2 = 0;
}
$(`.end_${i}_running`).text(end_running + end_score2);
running_score = end_running + end_score2;
}
});
}Editor is loading...
Leave a Comment