function updateWeight()

in project/paperbench/paperbench/gui/static/script.js [149:181]


function updateWeight(taskId) {
    var newWeight = document.getElementById('weight-' + taskId).innerText.trim();
    // Ensure the weight is a positive integer
    newWeight = parseInt(newWeight);
    if (isNaN(newWeight) || newWeight <= 0) {
        alert('Weight must be a positive integer.');
        location.reload(); // Reload to reset the displayed weight
        return;
    }
    
    fetch('/update_weight', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({ 'node_id': taskId, 'weight': newWeight }),
    })
    .then(response => response.json())
    .then(data => {
        if (data.status === 'success') {
            console.log('Weight updated for node', taskId);
        } else {
            console.error('Error updating weight:', data.message);
            alert('Failed to update weight: ' + data.message);
            location.reload(); // Reload to reset the displayed weight
        }
    })
    .catch(error => {
        console.error('Error updating weight:', error);
        alert('Failed to update weight. Please try again.');
        location.reload(); // Reload to reset the displayed weight
    });
}