
let entryTemplate =
    '<div class="score-entry">' +
    '<span class="score-entry-text"></span>' +
    '<span class="score-entry-points"></span>' +
    '</div>';

function nameTeam(team){
    if (team==='gli')
    return "Glissefondor";
    else if (team==='pek')
        return "Peksentard";
    else if (team==='boo')
        return "Boomsouffle";
    else
        return "Verredaigle";

}
function showScores(team) {
    console.log(team);
    $.alert({
        title: "<span id='title_" + team + "'>" + nameTeam(team) + "</span>",
        content: function () {
            let self = this;
            let object = {
                "function": 'get_scores',
                'team': team,
            };
            return $.ajax({
                url: "ajax/read",
                data: object,
                method: 'get'
            }).done(function (data) {
                for (let i = 0; i < data.length; i++) {
                    let $entry = $(entryTemplate);
                    $entry.attr('id', 'entry_' + i);
                    $entry.find('.score-entry-text').text(data[i]['text']);
                    $entry.find('.score-entry-points').text(data[i]['points']);
                    if (parseInt(data[i]['points']) > 0)
                        $entry.addClass('positive');
                    else
                        $entry.addClass('negative');
                    self.setContentAppend($entry);
                }
            }).fail(function(){
                self.setContent('Something went wrong.');
            });
        }
    });
}


