summaryrefslogblamecommitdiffstats
path: root/modules-available/sysconfig/clientscript.js
blob: 9dbb07457c40eee6ca3c93dcb9754f875af64dc4 (plain) (tree)
1
2
3
4
5
6
7
8
 

                         

                         
                          
 
                                                      






                               
                                                    








                                           
                                     
                                  




                                                      
                                               
                                        
                                                                      
               
         



                                           
       
 




                                                                                                                                     








                                                          
     
 
                             
                       
                              
                                        


                                                              

                                                                 







                                       
                                              
                                  

                                                           
                                                    














                                          
                                                                 

                               
                                                                   







                                          
     
     







                                                     
                                                                 

                                 
                                                                  


                                                        
                                                                                    

                                                                                                                         

                                                                                      


               









                                                                                      
 

// Mouseover and clicking

(function() {
    var boldItem = false;
    var modToConf = false;

    var $ct = $('#conftable').find('.confrow .title');
    $ct.click(function () {
        showmod(this, 'bold');
    }).mouseenter(function () {
        showmod(this, 'fade');
    }).mouseleave(function () {
        showmod(this, 'reset');
    });
    var $mt = $('#modtable').find('.modrow .title');
    $mt.click(function () {
        showconf(this, 'bold');
    }).mouseenter(function () {
        showconf(this, 'fade');
    }).mouseleave(function () {
        showconf(this, 'reset');
    });
    var $confirm = $('#delete-item-list');
    $('.btn-del-module').click(function() {
        var mid = $(this).val() + '';
        var list = modToConf[mid];
        if (!list || !list.length) {
            $confirm.append($msgs).addClass('hidden');
            return;
        }
        var $msgs = $confirm.find('ul').empty();
        for (var i = 0; i < list.length; ++i) {
            $msgs.append($('<li>').text(
                $('.confrow[data-id="' + list[i] + '"] .title').text()
            ));
        }
        $confirm.removeClass('hidden');
    });
    $('.btn-del-config').click(function() {
        $confirm.addClass('hidden');
    });

    buildRevList();
    var mods = [];
    $('#modtable .modrow').each(function() { mods.push($(this).data('id')) });
    mods.forEach(function(e) { if (modToConf[e] === undefined) $('.modrow[data-id=' + e + '] .icon-unused').removeClass('hidden') });

    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() {
        modToConf = {};
        $ct.each(function () {
            var elem = $(this).parent();
            var cid = elem.data('id') + '';
            var list = (elem.data('modlist') + '').split(',');
            for (var i = 0; i < list.length; ++i) {
                if (!modToConf[list[i]]) modToConf[list[i]] = [];
                modToConf[list[i]].push(cid);
            }
        });
    }

    function showconf(e, action) {
        action = showpre(e, action);
        if (action === 'reset') return;
        var $e = $(e);
        var mid = $e.parent().data('id') + '';
        var list = modToConf[mid];
        if (list && list.length > 0) $ct.each(function () {
            var elem = $(this);
            var cid = elem.parent().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.parent().data('modlist') + '').split(',');
        $mt.each(function () {
            var elem = $(this);
            if (list.indexOf(elem.parent().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 = [];
    $(".modrow .btn-rebuild.btn-primary").each(function (index) {
        mods.push($(this).val());
    });
    $(".confrow .btn-rebuild.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('.modrow', data.mods);
        if (typeof data.confs === 'object') updateButtonColor('.confrow', data.confs);
    }, 'json');
}

function updateButtonColor(rowclass,ids) {
    for (var i = 0; i < ids.length; ++i) {
        var e = ids[i];
        var $row = $(rowclass + '[data-id=' + e.id + ']');
        $row.find('.btn-rebuild').removeClass('btn-primary').addClass('btn-default');
        if (e.warnings && (typeof e.warnings === 'string') && e.warnings.length > 0) {
            $row.find('.row-warnings').text(e.warnings);
            $row.find('.btn-warnings').removeClass('hidden');
        }
    }
}