<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Admin/Guide.master"
    CodeBehind="DepartmentGuide.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.User.DepartmentGuide" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CphTitle" runat="server">
部门管理<span class="refresh" onclick="location.reload();"></span>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphSubMenu" runat="server">
<div class="guideexpand">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="departmentcategory">
<asp:Literal ID="LitDepartmentTitle" runat="server"></asp:Literal>
<asp:DropDownList ID="DpLDepartmentCategory" runat="server" Width="125px"></asp:DropDownList>
</td>
</tr>
</table>
</div>  

<table style="width:100%;height:100%;"  oncontextmenu="DoContextMenu(event)">
<tr>
<td valign ="top">
<div style="text-align: left">
    <table >
        <tr>
            <td align="left">
                <pe:XLoadTree ID="XLoadTreeCategory" RootIcon="WebSite"  runat="server"></pe:XLoadTree>
            </td>
        </tr>
    </table>
</div>
</td>
</tr>
</table>

<script type="text/javascript">

function DoContextMenu(event) {
    event.returnValue = false;
}

function rightMenu(id, hasChild, obj, event) {
    var toolMenu = new WebFXMenu;
    toolMenu.width = 76;

    if (id != "root") {
        toolMenu.add(new WebFXMenuItem("设置成员", "javascript:going(\"setadmin\"," + id + "," + hasChild + ",0);", '设置部门成员'));
        toolMenu.add(new WebFXMenuItem("添加部门", "javascript:going(\"add\"," + id + "," + hasChild + "," + obj + ");", '添加部门信息'));
        toolMenu.add(new WebFXMenuItem("修改部门", "javascript:going(\"editor\"," + id + "," + hasChild + "," + obj + ");", '修改部门信息'));
        toolMenu.add(new WebFXMenuItem("删除部门", "javascript:going(\"delete\"," + id + "," + hasChild + "," + obj + ");", '删除部门'));
    }
    else {
        toolMenu.add(new WebFXMenuItem("添加部门", "javascript:going(\"add\",0," + hasChild + ",0);", '添加部门信息'));
    }

    document.getElementById("menudata").innerHTML = toolMenu;
    var yScrolltop;
    var xScrollleft;
    if (self.pageYOffset || self.pageXOffset) {
        yScrolltop = self.pageYOffset;
        xScrollleft = self.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft) {
        yScrolltop = document.documentElement.scrollTop;
        xScrollleft = document.documentElement.scrollLeft;
    }
    else if (document.body) {
        yScrolltop = document.body.scrollTop;
        xScrollleft = document.body.scrollLeft;
    }
    toolMenu.left = event.clientX + xScrollleft;
    toolMenu.top = event.clientY + yScrolltop;
    toolMenu.show();
}

function going(mark, id, hasChild,cid) {
    switch (mark) {
        case "add":
            JumpToMainRight("Department.aspx?Action=Add&DepartmentId=" + id + '&cid=' + cid);
            break;
        case "editor":
            JumpToMainRight("Department.aspx?Action=Modify&DepartmentId=" + id + '&cid=' + cid);
            break;
        case "delete":
            var alertdescirpt = "确定要删除这个部门吗？";
            if (hasChild == 1) {
                alertdescirpt += "\n\r如果删除成功，此部门下的所有子部门都会被删除！";
            }
            if (window.confirm(alertdescirpt)) {
                JumpToMainRight("DepartmentManage.aspx?Action=" + mark + "&DepartmentId=" + id);
            }
            break;
        case "setadmin":
            JumpToMainRight("DepartmentMembers.aspx?DepartmentId=" + id);
        default:
            // 默认情况下不做任何处理
            break;
    }
}

function GoSearch(obj) {
    var currentdorp = document.getElementById("<%=this.DpLDepartmentCategory.ClientID %>");
    var cateId = currentdorp.value;
    if (cateId != "") {
        var rootText='管理所有部门', newXmlSrc, rootAction;
        if (cateId != 0) {
            newXmlSrc = "GetDepartmentXmlData.aspx?DepartmentId=0&action=root&search=" + cateId;
            rootAction = "DepartmentManage.aspx?cid=" + cateId;
        }
        else {
            newXmlSrc = "GetDepartmentXmlData.aspx?DepartmentId=0&action=root";
            rootAction = "DepartmentManage.aspx";
        }
        var newtree = new WebFXLoadTree(rootText, newXmlSrc, rootAction, "2", rootIcon, rootIcon, "main_right");
        $("#treedata").html(newtree.toString());
    } 
}
</script>
</asp:Content>
