<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NavContent.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.User.Content.NavContent" %>

<%@ Import Namespace="Resources" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>添加内容信息</title>
</head>
<body>
<pe:ExtendedSiteMapPath ID="YourPosition" SiteMapProvider="UserMapProvider" runat="server" />
    <form id="MainForm" runat="server">
    <div class="model_content_top">
        <h3>
            <pe:AlternateLiteral ID="AlternateLiteral1" Text="<%$ Res: User_Contents_NavContent_AlternateLiteral1,添加内容信息 %>" runat="Server" /></h3>
    </div>
    <div class="model_content_center">
        <ul class="add_model_content">
            <li>
                <label><asp:Localize ID="Localize1" Text="<%$ Res: User_Contents_NavContent_Localize1,请选择发表栏目： %>" runat="server" /></label><span id="NodeTree"></span></li>
            <li>
                <label><asp:Localize ID="Localize2" Text="<%$ Res: User_Contents_NavContent_Localize2,请选择添加的模型： %>" runat="server" /></label><span id="Model"></span></li>
        </ul>
        <div class="submit_model_content">
            <asp:Button ID="BtnSelectNode" CssClass="submit_button" runat="server" Text="<%$ Res: User_Contents_NavContent_BtnSelectNode,下一步 %>" OnClick="BtnSelectNode_Click" />
        </div>
    </div>
    <asp:HiddenField ID="HdnNodeId" runat="server" />
    <asp:HiddenField ID="HdnModelId" runat="server" />

    <script language="javascript" type="text/javascript">
        var node = 0;
        
        $(document).ready(function() {
            var xmlContent = GetNodeXml(null);
        });
        
        function GetNodeXml(parm) {
            var url = "NodeXml.aspx?Action=Content";

            if (parm != null || parm != "") {
                url = url + "&nodeId=" + parm;
            }
            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'xml',
                error: function() {
                    $("#NodeTree").html("<%=DynamicPageResources.User_Contents_NavContent_JSLoadNodeErr%>");
                },
                success: function(xml) {
                    node++;
                    ParseXml(xml);
                }
            });
        }

        function InitModelList(nodeId) {
            $.ajax({
                url: "NodeXml.aspx?Action=NodeInfo&NodeId=" + nodeId,
                type: 'POST',
                dataType: 'xml',
                error: function() {
                    $("#Model").html("<%=DynamicPageResources.User_Contents_NavContent_JSGetModeErr%>");
                },
                success: function(xml) {
                    InitModelSelect(xml);
                }
            });
        }

        function ParseXml(xmlContent) {
            if (xmlContent == null) {
                $("#NodeTree").html("<%=DynamicPageResources.User_Contents_NavContent_JSNoAdd%>");
                return;
            }
            var xmlSelect;

            $(xmlContent).find('tree').find('tree').each(function(i) {

                if ($(this).attr("icon") != "Forbid" || $(this).attr("childNumber") > 0) {

                    if (node > 1 && i == 0) {
                        xmlSelect = xmlSelect + "<option value=-3 selected=\"true\"><%=DynamicPageResources.User_Contents_NavContent_JSPleaseSelect%></option>";
                    }
                    if (i == 0) {
                        if (node == 1) {
                            document.getElementById("<%=HdnNodeId.ClientID%>").value = $(this).attr("nodeId");
                        }

                        if (parseInt($(this).attr("nodeId")) > 0) {
                            InitModelList($(this).attr("nodeId"))
                        }
                        if ($(this).attr("childNumber") > 0 && node == 1) {
                            xmlSelect = xmlSelect + "<option value=-3 selected=\"true\"><%=DynamicPageResources.User_Contents_NavContent_JSPleaseSelect%></option>";
                        }
                    }
                    xmlSelect = xmlSelect + "<option value=" + $(this).attr("nodeId") + ">" + $(this).attr("text") + "</option>";
                }
            }
                );
            CreateDom(xmlSelect);
        }
        function CreateDom(domContent) {
            if (String(domContent) != "undefined") {
                $("<select id='Node" + String(node) + "' onchange=ChangeModule(this)>" + domContent + "</select>").appendTo("#NodeTree");
            }
        }
        function ChangeModule(objSelect) {
            var i = parseInt(objSelect.id.replace("Node", ""));
            if (i > 0) {
                for (var m = i + 1; m <= node; m++) {
                    $("#Node" + m).remove();
                }
                node = i;

                //还需要根据nodeId判断是否前面加"请选择"
                var nodeId = objSelect.options[objSelect.options.selectedIndex].value;
                document.getElementById("<%=HdnNodeId.ClientID%>").value = nodeId;
                $("#Model").empty();

                GetNodeXml(nodeId);
                InitModelList(nodeId);
            }

        }

        function InitModelSelect(content) {

            if (content == null) {
                $("#Model").html("<%=DynamicPageResources.User_Contents_NavContent_JSNodeNoMode%>");
                return;
            }
            var xmlSelect = "";
            $("#Model").empty();

            $(content).find('tree ').find('tree ').each(function(i) {

                if (i == 0 && String($(this).attr("modelId")) != "undefined") {

                    document.getElementById("<%=HdnModelId.ClientID%>").value = $(this).attr("modelId");
                }

                if ($(this).attr("anchorType") != "0") {
                    xmlSelect = xmlSelect + "<option value=" + $(this).attr("modelId") + "><%=DynamicPageResources.User_Contents_NavContent_JSAdd%>" + $(this).text() + "</option>";
                }
            }
                );
            $("#Model").html("<select id='ModelName' onchange=ChangeModel(this)>" + xmlSelect + "</select>");

        }
        function ChangeModel(objSelect) {
            document.getElementById("<%=HdnModelId.ClientID%>").value = objSelect.options[objSelect.options.selectedIndex].value;

        }
            
           
    </script>

    </form>
</body>
</html>
