示例#1
0
文件: interface.php 项目: xtha/salt
function renderLocationFilterPortlet()
{
    // Recursive function used to build the location tree
    function renderLocationCheckbox($subtree, $level = 0)
    {
        $self = __FUNCTION__;
        foreach ($subtree as $location_id => $location) {
            echo "<div class=tagbox style='text-align:left; padding-left:" . $level * 16 . "px;'>";
            $checked = !isset($_SESSION['locationFilter']) || in_array($location['id'], $_SESSION['locationFilter']) ? 'checked' : '';
            echo "<label><input type=checkbox name='location_id[]' class={$level} value='{$location['id']}'{$checked} onClick=checkAll(this)>{$location['name']}";
            echo '</label>';
            if ($location['kidc']) {
                echo "<a id='lfa" . $location['id'] . "' onclick=\"expand('{$location['id']}')\" href\"#\" > - </a>";
                echo "<div id='lfd" . $location['id'] . "'>";
                $self($location['kids'], $level + 1);
                echo '</div>';
            }
            echo '</div>';
        }
    }
    addJS(<<<END
function checkAll(bx) {
\tfor (var tbls=document.getElementsByTagName("table"), i=tbls.length; i--;)
\t\tif (tbls[i].id == "locationFilter") {
\t\t\tvar bxs=tbls[i].getElementsByTagName("input");
\t\t\tvar in_tree = false;
\t\t\tfor (var j=0; j<bxs.length; j++) {
\t\t\t\tif(in_tree == false && bxs[j].value == bx.value)
\t\t\t\t\tin_tree = true;
\t\t\t\telse if(parseInt(bxs[j].className) <= parseInt(bx.className))
\t\t\t\t\tin_tree = false;
\t\t\t\tif (bxs[j].type=="checkbox" && in_tree == true)
\t\t\t\t\tbxs[j].checked = bx.checked;
\t\t\t}
\t\t}
}

function collapseAll(bx) {
\tfor (var tbls=document.getElementsByTagName("table"), i=tbls.length; i--;)
\t\tif (tbls[i].id == "locationFilter") {
\t\t\tvar bxs=tbls[i].getElementsByTagName("div");
\t\t\t//loop through divs to hide unchecked
\t\t\tfor (var j=0; j<bxs.length; j++) {
\t\t\t\tvar is_checked = -1;
\t\t\t\tvar in_div=bxs[j].getElementsByTagName("input");
\t\t\t\t//loop through input to find if any is checked
\t\t\t\tfor (var k=0; k<in_div.length; k++) {
\t\t\t\t\tif(in_div[k].type="checkbox") {
\t\t\t\t\t\tif (in_div[k].checked == true) {
\t\t\t\t\t\t\tis_checked = true;
\t\t\t\t\t\t\tbreak;
\t\t\t\t\t\t}
\t\t\t\t\t\telse
\t\t\t\t\t\t\tis_checked = false;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\t// nothing selected and element id is lfd, collapse it
\t\t\t\tif (is_checked == false && !bxs[j].id.indexOf("lfd"))
\t\t\t\t\texpand(bxs[j].id.substr(3));
\t\t\t}
\t\t}
}

function expand(id) {
\tvar divid = document.getElementById("lfd" + id);
\tvar iconid = document.getElementById("lfa" + id);
\tif (divid.style.display == 'none') {
\t\tdivid.style.display = 'block';
\t\ticonid.innerHTML = ' - ';
\t} else {
\t\tdivid.style.display = 'none';
\t\ticonid.innerHTML = ' + ';
\t}
}
END
, TRUE);
    startPortlet('Location filter');
    echo <<<END
<table border=0 align=center cellspacing=0 class="tagtree" id="locationFilter">
    <form method=post>
    <input type=hidden name=page value=rackspace>
    <input type=hidden name=tab value=default>
    <input type=hidden name=changeLocationFilter value=true>
END;
    $locationlist = listCells('location');
    if (count($locationlist)) {
        echo "<tr><td class=tagbox style='padding-left: 0px'><label>";
        echo "<input type=checkbox name='location'  onClick=checkAll(this)> Toggle all";
        echo "<img src=?module=chrome&uri=pix/1x1t.gif onLoad=collapseAll(this)>";
        // dirty hack to collapse all when page is displayed
        echo "</label></td></tr>\n";
        echo "<tr><td class=tagbox><hr>\n";
        renderLocationCheckbox(treeFromList($locationlist));
        echo "<hr></td></tr>\n";
        echo '<tr><td>';
        printImageHREF('setfilter', 'set filter', TRUE);
        echo "</td></tr>\n";
    } else {
        echo "<tr><td class='tagbox sparenetwork'>(no locations exist)</td></tr>\n";
        echo "<tr><td>";
        printImageHREF('setfilter gray');
        echo "</td></tr>\n";
    }
    echo "</form></table>\n";
    finishPortlet();
}
示例#2
0
function renderLocationFilterPortlet()
{
    // Recursive function used to build the location tree
    function renderLocationCheckbox($subtree, $level = 0)
    {
        $self = __FUNCTION__;
        foreach ($subtree as $location_id => $location) {
            echo "<tr><td class=tagbox style='padding-left: " . $level * 16 . "px;'><label>";
            $checked = in_array($location['id'], $_SESSION['locationFilter']) ? 'checked' : '';
            echo "<label><input type=checkbox name='location_id[]' value='{$location['id']}'{$checked}>{$location['name']}";
            echo "</label></td></tr>\n";
            if ($location['kidc']) {
                $self($location['kids'], $level + 1);
            }
        }
    }
    // TODO: add some javascript to toggle all children when a parent is toggled
    startPortlet('Location filter');
    echo <<<END
<table border=0 align=center cellspacing=0 class="tagtree">
    <form method=get>
    <input type=hidden name=page value=rackspace>
    <input type=hidden name=tab value=default>
    <input type=hidden name=changeLocationFilter value=true>
END;
    $locationlist = listCells('location');
    if (count($locationlist)) {
        echo "<tr><td class=tagbox><hr></td></tr>\n";
        renderLocationCheckbox(treeFromList($locationlist));
        echo "<tr><td class=tagbox><hr></td></tr>\n";
        echo "<tr><td>";
        printImageHREF('setfilter', 'set filter', TRUE);
        echo "</td></tr>\n";
    } else {
        echo "<tr><td class='tagbox sparenetwork'>(no locations exist)</td></tr>\n";
        echo "<tr><td>";
        printImageHREF('setfilter gray');
        echo "</td></tr>\n";
    }
    echo "</form></table>\n";
    finishPortlet();
}