<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
 <%List<string> feilei = ViewData["分类列表"] as List<string>; %>
    <link rel="stylesheet" href="/Content/StyleSheet/themes/base/jquery.treeview.css" />
    <link rel="stylesheet" href="/Content/StyleSheet/fenlei/fenlei.css" />
    <style type="text/css">
.boxy-wrapper input[type=text]{padding:2px;font-size:16px;height:20px;line-height:20px;}
.boxy-wrapper div{padding:3px;font-size:12px;}
    </style>
	<script src="/Scripts/JQuery/jquery.treeview.js" type="text/javascript"></script>
	<script src="/Scripts/JQuery/jquery.treeview.edit.js" type="text/javascript"></script>
	<script src="/Scripts/JQuery/jquery.treeview.async.js" type="text/javascript"></script>
    <script src="/Scripts/Views/Examiner/fenleiguanli.js"></script>
	<script type="text/javascript">
	    function initTrees() {
            var a=[];var i=0;
            <%foreach(var a in feilei){%>a[i++]="<%:a%>";<%}%>
            i=0;
	        $("#mixed").treeview({
	            url: "/feileiguanli/feileilist",
                ajax: {
	                type: "POST",
                    afterload:function(msg){
                        if(i<a.length&&a[i]!=""){
                            $(".hasChildren-hitarea",$("#"+a[i])).click();
                        }i++;
                    }
	            },
                collapsed:true,
		        unique: true
                    
	        });
            $(".dingji-hitarea").click();
	    }
	    $(document).ready(function () {
	        initTrees();
	        
	    });
        function windowreload(feilei)
        {
            window.location.href="/feileiguanli/index?feilei="+encodeURIComponent(feilei);
        }
	</script>
    <ul id="mixed">
        <li id="" class="hasChildren dingji"><span><div onmouseout='分类管理.选择.样式还原(this)' onmouseover='分类管理.选择.样式选中(this)'><div style='float:left;width:150px;'>全部分类</div><div style='float:left;display:none;' class='hangtiao'><a href='javascript:void(0);' onclick='分类管理.添加分类.创建窗口(this)' feilei="">添加下级分类</a></div></div><div style="clear:both;"></div></span>
        <ul style="display:block">
            <%foreach(var a in LoveKaoExam.Data.分类.得到顶级分类列表()){ %>
                <li id="<%:a.分类名称%>" class="<%:a.是否有下级==true?"hasChildren expandable":"" %>" >
                <div style='padding:6px;padding-top:0px;' onmouseout='分类管理.选择.样式还原(this)' onmouseover='分类管理.选择.样式选中(this)'><div style='float:left;width:150px;'><%:a.分类名称%></div><div style='float:left;width:80px;' class="paixuhaoyc" style="display:none;">排序号:<%:a.排序号%></div><div style='float:left;display:none;' class='hangtiao'><a href='javascript:void(0);' onclick='分类管理.添加分类.创建窗口(this)' feilei="<%:a.分类名称%>">添加下级分类</a> &nbsp; &nbsp; &nbsp; &nbsp;<a href='javascript:void(0);' onclick='分类管理.修改分类.创建窗口(this)' feilei="<%:a.分类名称%>">修改名称</a> &nbsp; &nbsp; &nbsp; &nbsp;<a href='javascript:void(0);' onclick='分类管理.修改父类.创建窗口(this)' feilei="<%:a.分类名称%>" fulei="">修改所属分类</a> &nbsp; &nbsp; &nbsp; &nbsp;<a href='javascript:void(0);' onclick='分类管理.修改排序.创建窗口(this)' paixu="<%:a.排序号 %>" feilei="<%:a.分类名称%>">修改排序</a> &nbsp; &nbsp; &nbsp; &nbsp;<a href='javascript:void(0);' onclick='分类管理.删除分类.创建窗口(this)' feilei="<%:a.分类名称%>" fulei="">删除</a></div><div style='clear:both;'></div></div>
                <%if (a.是否有下级) { 
                    %>
                    <ul style="display:none;"><li class="last"><span class="placeholder">&nbsp;</span></li></ul>
                    
                <%} %>
                </li>
            <%} %>
			</ul>
            </li>
    </ul>
   
    <script type="text/javascript">
        var 分类管理 = {
            添加分类: {
                创建窗口: function (obj) {
                    obj = $(obj).attr("feilei");
                    if (obj == "")
                        obj = "全部分类";
                    var a = "<div style='padding:10px;'>父分类：<span id='parentname'>" + obj + "</span><br/><input id='feileiname'/><br/><br/><input type='button' value='添加' onclick='分类管理.添加分类.添加(this);'/></div>";
                    new Boxy(a, { title: "添加子分类:" + obj });
                },
                添加: function (obj) {
                    $(obj).attr("disabled", "disabled");
                    $.ajax({
                        url: "/feileiguanli/feileitianjia",
                        data: "feilei=" + encodeURIComponent($(obj).parent().children("#feileiname").val()) + "&fufeilei=" + encodeURIComponent($(obj).parent().children("#parentname").html()),
                        type: "POST",
                        success: function (msg) {
                            if (msg != "true") {
                                $(obj).attr("disabled", ""); alert(msg);
                            }
                            else {
                                windowreload($(obj).parent().children("#feileiname").val());
                            }
                        }
                    });
                }
            },
            修改分类: {
                创建窗口: function (obj) {
                    obj = $(obj).attr("feilei");
                    var a = "<div style='padding:10px;'><input value='" + obj + "' id='feileinewname'/><input value='" + obj + "' id='feileioldname' type='hidden'><br/><br/><input type='button' value='修改' onclick='分类管理.修改分类.修改(this);'/></div>";
                    new Boxy(a, { title: "修改分类名称:" + obj });
                },
                修改: function (obj) {
                    $(obj).attr("disabled", "disabled");
                    $.ajax({
                        url: "/feileiguanli/feileixiugai",
                        data: "newfeilei=" + encodeURIComponent($(obj).parent().children("#feileinewname").val()) + "&oldfeilei=" + encodeURIComponent($(obj).parent().children("#feileioldname").val()),
                        type: "POST",
                        newname: $(obj).parent().children("#feileinewname").val(),
                        success: function (msg) {
                            if (msg != "true") {
                                $(obj).attr("disabled", ""); alert(msg);
                            }
                            else {
                                windowreload(this.newname);
                            }
                        }
                    });
                }
            },
            修改父类: {
                创建窗口: function (obj, obj2) {
                    obj2 = $(obj).attr("feilei");
                    obj = $(obj).attr("fulei");
                    this.已选择的分类 = obj;
                    if (obj == "")
                        obj = "全部分类";
                    var a = "<div style='padding:20px;'>被移动分类：<span id='beixiugailei'>" + obj2 + "</span><div id='parentname'>原父分类:" + obj + "</div><div id='newfufeilei'></div><input type='button' onclick='分类管理.修改父类.选择分类(this)' value='选择分类'/>&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='确定修改' onclick='分类管理.修改父类.修改(this)'/></div>";
                    new Boxy(a, { title: "移动分类:" + obj2 });
                },
                已选择的分类: null,
                选择分类: function (obj) {
                    var _this = this;
                    分类.分类选择.创建窗口(function (msg) {
                        _this.已选择的分类 = msg[msg.length - 1];
                        $(obj).parent().children("#newfufeilei").html("移动到新父类:【" + _this.已选择的分类 + "】下");
                    });
                },
                修改: function (obj) {
                    $(obj).attr("disabled", "disabled");
                    var _p = this.已选择的分类;
                    $.ajax({
                        url: "/feileiguanli/fuleixiugai",
                        data: "feilei=" + encodeURIComponent($(obj).parent().children("#beixiugailei").html()) + "&fulei=" + encodeURIComponent(_p),
                        type: "POST",
                        fulei: $(obj).parent().children("#parentname").html(),
                        success: function (msg) {
                            if (msg != "true") {
                                $(obj).attr("disabled", ""); alert(msg);
                            }
                            else {
                                windowreload(this.fulei);
                            }
                        }
                    });
                }
            },
            修改排序: {
                创建窗口: function (obj, obj2) {
                    $(".paixuhaoyc").show();
                    obj2 = $(obj).attr("feilei");
                    obj = $(obj).attr("paixu");
                    var x = "<div style='padding:10px;'><input id='paixuhao' value='" + obj + "'/><input type='hidden' id='paixufeilei' value='" + obj2 + "'><input type='button' value='修改排序' onclick='分类管理.修改排序.修改(this)'/></div>";
                    new Boxy(x, { title: "修改分类" + obj2 + "排序:" + obj, afterHide: function () {
                        $(".paixuhaoyc").hide();
                    } });
                },
                修改: function (obj) {
                    $(obj).attr("disabled", "disabled");
                    $.ajax({
                        url: "/feileiguanli/xiugaipaixu",
                        data: "feilei=" + encodeURIComponent($(obj).parent().children("#paixufeilei").val()) + "&paixu=" + encodeURIComponent($(obj).parent().children("#paixuhao").val()),
                        type: "POST",
                        success: function (msg) {
                            if (msg != "true") {
                                $(obj).attr("disabled", ""); alert(msg);
                            }
                            else {
                                windowreload($(obj).parent().children("#paixufeilei").val());
                            }
                        }
                    });
                }
            },
            删除分类: {
                创建窗口: function (obj) {
                    var parent = $(obj).attr("fulei");
                    obj = $(obj).attr("feilei");
                    var x = "<div style='padding:20px;'><input id='parentshanchu' type='hidden' value='" + parent + "'/><div id='shanxufeilei'>" + obj + "</div><div id='zhuanyijieguo'>不转移数据</div><input type='hidden' id='zhuanyishuju'/><div id='zhuanyifeilei'><br/>注:删除分类会删除所有此分类下的子分类和所有数据</div><div><input type='button' onclick='分类管理.删除分类.选择分类(this)' value='转移数据到目标分类'/>&nbsp;&nbsp;&nbsp;&nbsp;<input value='不转移' type='button' onclick='分类管理.删除分类.不转移(this)'/></div><div style='text-align:center'><br/><input type='button' value='确定删除分类' onclick='分类管理.删除分类.删除(this)'/></div></div>";
                    new Boxy(x, { title: "删除分类:" + obj });
                },
                选择分类: function (obj) {
                    var _this = this;
                    分类.分类选择.创建窗口(function (msg) {
                        $(obj).parent().parent().children("#zhuanyijieguo").html("转移数据至分类:" + msg[msg.length - 1]);
                        $(obj).parent().parent().children("#zhuanyishuju").val(msg[msg.length - 1]);
                    });
                },
                不转移: function (obj) {
                    $(obj).parent().parent().children("#zhuanyishuju").val("");
                    $(obj).parent().parent().children("#zhuanyijieguo").html("不转移分类");
                },
                删除: function (obj) {
                    $(obj).attr("disabled", "disabled");
                    var parent = $("#parentshanchu").val();
                    $.ajax({
                        url: "/feileiguanli/feileishanchu",
                        data: "feilei=" + encodeURIComponent($(obj).parent().parent().children("#shanxufeilei").html()) + "&qita=" + encodeURIComponent($(obj).parent().parent().children("#zhuanyishuju").val()),
                        type: "POST",
                        parentfeilei: parent,
                        success: function (msg) {
                            if (msg != "true") {
                                $(obj).attr("disabled", ""); alert(msg);
                            }
                            else {
                                windowreload(parent);
                            }
                        }
                    });
                }
            }
        };


        分类管理.选择 = {
            样式还原: function (obj) {
                $(obj).css("background", "");
                $(".hangtiao", obj).hide();
            },
            样式选中: function (obj) {
                $(obj).css("background", "#eeffe1");
                $(".hangtiao", obj).show();
            }
        }


    </script>

</asp:Content>
