summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/clientscript.js
blob: 1553d6788dd8241e009c8ecad540f3362bffa9b3 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

// Mouseover and clicking

var $ct = $('#conftable').find('.confrow');
$ct.click(function() {
    showmod(this, 'bold');
}).mouseenter(function() {
    showmod(this, 'fade');
}).mouseleave(function() {
    showmod(this, 'reset');
});
var $mt = $('#modtable').find('.modrow');
$mt.click(function() {
    showconf(this, 'bold');
}).mouseenter(function() {
    showconf(this, 'fade');
}).mouseleave(function() {
    showconf(this, 'reset');
});

var boldItem = false;
var revList = false;

function showpre(e, action) {
    if (boldItem && action !== 'bold') return 'reset';
    if (boldItem) {
        if (e === boldItem) action = 'fade';
        boldItem = false;
    }
    $mt.removeClass("slx-bold slx-fade");
    $ct.removeClass("slx-bold slx-fade");
    return action;
}

function buildRevList() {
    revList = {};
    $ct.each(function() {
        var elem = $(this);
        var cid = elem.data('id')+'';
        var list = (elem.data('modlist')+'').split(',');
        for (var i = 0; i < list.length; ++i) {
            if (!revList[list[i]]) revList[list[i]] = [];
            revList[list[i]].push(cid);
        }
    });
}

function showconf(e, action) {
    action = showpre(e, action);
    if (action === 'reset') return;
    var $e = $(e);
    if (!revList) buildRevList();
    var mid = $e.data('id')+'';
    var list = revList[mid];
    if (list && list.length > 0) $ct.each(function() {
        var elem = $(this);
        var cid = elem.data('id')+'';
        if (list.indexOf(cid) === -1)
            elem.addClass('slx-fade');
        else if (action === 'bold')
            elem.addClass('slx-bold');
    }); else $ct.addClass('slx-fade');
    if (action === 'bold') {
        boldItem = e;
        $e.addClass("slx-bold");
    }
}

function showmod(e, action) {
    action = showpre(e, action);
    if (action === 'reset') return;
    var $e = $(e);
    var list = ($e.data('modlist')+'').split(',');
    $mt.each(function () {
        var elem = $(this);
        if (list.indexOf(elem.data('id')+'') === -1)
            elem.addClass("slx-fade");
        else if (action === 'bold')
            elem.addClass("slx-bold");
    });
    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, 150 + 100 * 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');
    });
}