summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/clientscript.js
blob: 47761ea5b78acaeed486fd5c626708085d2424b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

// Ugly hack to get the ellipsisized fields to work

function forceTable(t)
{
    var pwidth = t.parent().innerWidth();
    var rows = t.find('tr');
    var row = rows.first();
    pwidth = Math.round(pwidth);
    t.width(pwidth);
    var sum = 0;
    row.find('td').each(function() {
        if (!$(this).hasClass('slx-width-ignore'))
            sum += $(this).outerWidth(true);
    });
    var w = Math.round(pwidth - sum);
    do {
        rows.find('.slx-dyn-ellipsis').each(function() {
            $(this).width(w).css('width', w + 'px').css('max-width', w + 'px');
        });
        w -= 3;
    } while (t.width() > pwidth);
}

// Mouseover and clicking

var boldItem = false;

function showmod(e, action) {
    var list = $(e).attr('data-modlist');
    list = list.split(',');
    if (action === 'bold') {
        $(boldItem).removeClass("slx-bold");
        if (boldItem === e) {
            action = 'fade';
            boldItem = false;
        }
    } else if (boldItem !== false) {
        return;
    }
    $('.modrow').each(function () {
        var elem = $(this);
        elem.removeClass("slx-fade slx-bold");
        if (action === 'reset')
            return;
        if (action === 'bold' && list.indexOf(elem.attr('data-id')) !== -1)
            elem.addClass("slx-bold");
        if (list.indexOf(elem.attr('data-id')) === -1)
            elem.addClass("slx-fade");
    });
    if (action === 'bold') {
        boldItem = e;
        $(e).addClass("slx-bold");
    }
}

// Polling for updated status (outdated, missing, ok)

var statusChecks = 0;

function checkBuildStatus() {
    var mods = [];
    var confs = [];
    $(".refmod.btn-primary").each(function (index) {
        mods.push($(this).val());
    });
    $(".refconf.btn-primary").each(function (index) {
        confs.push($(this).val());
    });
    if (mods.length === 0 && confs.length === 0) return;
    if (++statusChecks < 10) setTimeout(checkBuildStatus, 200 + 50 * statusChecks);
    $.post('?do=SysConfig', { mods: mods.join(), confs: confs.join(), token: TOKEN, action: 'status' }, function (data) {
        if (typeof data === 'undefined') return;
        if (typeof data.mods === 'object') updateButtonColor($(".refmod.btn-primary"), data.mods);
        if (typeof data.confs === 'object') updateButtonColor($(".refconf.btn-primary"), data.confs);
    }, 'json');
}

function updateButtonColor(list,ids) {
    list.each(function() {
        if (ids.indexOf($(this).val()) >= 0) $(this).removeClass('btn-primary').addClass('btn-default');
    });
}