Revision cce434fc

b/ui/static/synnefo.js
1607 1607
        return;
1608 1608
    }
1609 1609
    
1610
    var has_active_indicators = function(el)
1611
    {
1612
        return ($("img.spinner:visible", el.parent().parent()).length >= 1) || ($("img.wave:visible", el.parent().parent()).length >= 1) 
1610
    function update_action_icon_indicators(force)
1611
    {   
1612
        function show(el, action) {
1613
            $(".action-indicator", $(el)).attr("class", "action-indicator " + action);
1614
            $(".action-indicator", $(el)).show();
1615
        }
1616

  
1617
        function hide(el) {   
1618
            $(".action-indicator", $(el)).hide();
1619
        }
1620
        
1621
        function get_pending_actions(el) {
1622
            return $(".confirm_single:visible", $(el));
1623
        }
1624
        
1625
        function other_indicators(el) {
1626
           return $("img.wave:visible, img.spinner:visible", $(el))
1627
        }
1628
        
1629
        $("div.machine:visible, div.single-container").each(function(index, el){
1630
            var el = $(el);
1631
            var pending = get_pending_actions(el);
1632
            var other = other_indicators(el);
1633
            var action = undefined;
1634
            var force_action = force;
1635
            var visible = $(el).css("display") == "block";
1636

  
1637
            if (force_action !==undefined && force_action.el !== el[0]) {
1638
                // force action for other vm
1639
                // skipping force action
1640
                force_action = undefined;
1641
            }
1642
             
1643
            if (force_action !==undefined && force_action.el === el[0]) {
1644
                action = force_action.action;
1645
            }
1646

  
1647
            if (other.length >= 1) {
1648
                return;
1649
            }
1650

  
1651
            if (pending.length >= 1 && force_action === undefined) {      
1652
                action = $(pending.parent()).attr("class").replace("action-container","");
1653
            }
1654
            
1655
            if (action in {'console':''}) {
1656
                return;
1657
            }
1658
            
1659
            if (action !== undefined) {
1660
                show(el, action);
1661
            } else {
1662
                try {   
1663
                    if (el.attr('id') == pending_actions[0][1])
1664
                    {
1665
                        return;   
1666
                    }
1667
                } catch (err) {
1668
                }
1669
                hide(el);
1670
            }
1671

  
1672
        });
1613 1673
    }
1614 1674

  
1615 1675
    // action indicators
1616
    $(".action-container").live('mouseover', function(evn){
1617
        var el = $(evn.currentTarget);
1618
        // we dont need the single-action class
1619
        var action_class = el.attr("class").replace("action-container","");
1620
        // pass the hovered element action related class to the indicator image
1621
        $("div.action-indicator", el.parent().parent()).attr("class", "action-indicator " + action_class);
1622

  
1623
        // spinner || wave indicators already visible. dont show action image to avoid clutter
1624
        if (has_active_indicators(el))
1676
    $(".action-container").live('mouseover', function(evn) {
1677
        force_action = {'el': $(evn.currentTarget).parent().parent()[0], 'action':$(evn.currentTarget).attr("class").replace("action-container","")};
1678
        // single view
1679
        if ($(force_action.el).attr("class") == "upper")
1625 1680
        {
1626
            return;
1627
        }
1628
        $("div.action-indicator", el.parent().parent()).show();
1681
            force_action.el = $(evn.currentTarget).parent().parent().parent()[0]
1682
        };
1683
        update_action_icon_indicators(force_action);
1629 1684
    });
1630 1685

  
1686
    // register events where icons should get updated
1687

  
1631 1688
    // hide action indicator image on mouse out, spinner appear, wave appear
1632 1689
    $(".action-container").live("mouseout", function(evn){
1633
        var el = $(evn.currentTarget);
1634
        $("div.action-indicator").hide();
1635
        
1636
        var pending_for_confirm_action = $(".confirm_single:visible", el.parent().parent());
1637
        // if we mouse out and another action is in confirmation mode
1638
        if (!has_active_indicators(el))
1639
        {
1640
            // no actions pending
1641
            if (pending_for_confirm_action.length == 0)
1642
            {
1643
                return;
1644
            }
1690
        update_action_icon_indicators();
1691
    });
1645 1692

  
1646
            // find action pending and show icon
1647
            var action_container = $($(pending_for_confirm_action[0]).parent());
1648
            var action_class = action_container.attr("class").replace("action-container","");
1649
            $("div.action-indicator", action_container.parent().parent()).attr("class", "action-indicator " + action_class);
1650
            $("div.action-indicator").show();
1651
        }
1652
        
1693
    $(".confirm_single").live("click", function(evn){
1694
        update_action_icon_indicators();
1653 1695
    });
1654 1696

  
1655 1697
    $("img.spinner, img.wave").live('show', function(){
1656 1698
        $("div.action-indicator").hide();
1657 1699
    });
1700

  
1701
    $(".confirm_single button.no").live('click', function(evn){
1702
        $("div.action-indicator", $(evn.currentTarget).parent().parent()).hide();
1703
    });
1704

  
1705
    $(".confirm_multiple button.no").click(function(){
1706
        $("div.action-indicator").hide();
1707
    });
1708

  
1709
    $(".confirm_multiple button.yes").click(function(){
1710
        $("div.action-indicator").hide();
1711
    });
1658 1712
}
1659 1713

  
1660 1714
function init_action_indicator_list_handlers()
......
1721 1775
        update_action_indicator_icons(action_class, false);
1722 1776
    });
1723 1777
    
1778

  
1779
    // register events where icons should get updated
1724 1780
    $(".actions a.enabled").live("click", function(evn) {
1725 1781
        // clear previous selections
1726 1782
        $("a.selected").removeClass("selected");

Also available in: Unified diff