<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" Inherits="Kesion.NET.WebSite.Admin.Course.KS_CosFacePeriod" CodeBehind="KS.CosFacePeriod.aspx.cs" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Course" %>
<%@ Import Namespace="Kesion.APPCode" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" runat="server">
    <asp:Panel ID="Panel1" runat="server">
    
    <div class="listedit">
        <ul>
             <li id='p6'><a href="javascript:;" onclick="location.href='KS.CosFaceList.aspx';" class="button">返回课程列表</a></li>
        </ul>
     </div>
     <div class="footer_page"></div>
	 <!--当前课程信息-->
     <asp:PlaceHolder ID="PlaceHolder1"  runat="server"></asp:PlaceHolder> 
     <div class="content-area pageBlank">
        <div class="myTitle">
            <div class="tabButton">
                <a class="on" href="KS.CosFacePeriod.aspx?CourseId=<%=CourseID %>&type=1&Costype=2">课时</a>
            </div>
            课时管理<span class="titleTips">该课程下共<span id="zhangnum"></span>章，<span id="jienum"></span>节，<span id="shinum"></span>课时</span>
        </div>
		<div class="quickSearch clearfix md20">
        	<div class="fr headOperation ">
            	<a onclick="add(<%=CourseID %>,1,0)" href="javascript:void(0);" class="button button_on ml15">添加章</a>
                <a onclick="add(<%=CourseID %>,2,0)" href="javascript:void(0);" class="button button_on ml15">添加节</a>
                <a href="KS.CosFacePeriod.aspx?action=add&CourseID=<%=CourseID %>" class="button button_on ml15">添加课时</a>
            </div>
            <div class="SearchBox fl">
                <input type="text"  value="" id="key" style="margin-right:8px;" onkeypress="if(event.keyCode === 13){ event.preventDefault(); loaddata()}" />
                <select id="userselect" style="margin-right:8px;">
                    <option value="2">课时</option> 
                </select>
                <input value="搜索" type="button" class="button" onclick="loaddata()" />
            </div>
        </div>
        <div class="courseKeshi">
        	<div class="lineY"></div>
            <ul id="myloop">
            
        	</ul>
        </div>

    </div>
         
        <script>
            $(document).ready(function () {
                getmyPeriod();

            });

            function loaddata() {
                var key = $("#key").val();
                if (!key) {
                    alert("请输入课时名称")
                }
                else {
                    $.ajax({
                        url: "?action=searchperiod&key=" + key + "&courseID=<%=CourseID%>&userselect=" + $("#userselect").val(),
                        context: document.body,
                        type: "GET",
                        success: function (data) {
                            $("#myloop").html(data);
                        }
                    });
                }
            }

            function add(id, type, parentid) {
                parent.openWin('添加章节', '/plus/course/AddCoursePeriod.aspx?action=faceadd&type=' + type + '&parentid=' + parentid + '&Courseid=' + id, true, 600, 400);
            }
            function edit(id, Periodid, type, parentid) {
                parent.openWin('修改章节', '/plus/course/AddCoursePeriod.aspx?action=faceedit&type=' + type + '&Courseid=' + id + '&parentid=' + parentid + '&Periodid=' + Periodid, true, 600, 400);
            }


            function moveup(id, parentid) {
                location.href = 'KS.CosFacePeriod.Aspx?action=moveup&CourseId=<%=CourseID %>&Periodid=' + id + "&parentid=" + parentid;
            }
            function movedown(id, parentid) {
                location.href = 'KS.CosFacePeriod.Aspx?action=movedown&CourseId=<%=CourseID %>&Periodid=' + id + "&parentid=" + parentid;
            }



            function getmyPeriod()
            {
                $.ajax({
                    type: 'post',
                    dateType: 'json',
                    url: "/plus/course/CourseAjax.ashx?action=getfaceperiod&intendant=true",
                    data: { courseID: <%=CourseID %>},
                    success: function (msg) {
						
						
						
						
                        var info = JSON.parse(msg);
                        console.log(info);
                        if (info.status == "success")
                        {
                            $("#zhangnum").html(info.chapter);
                            $("#jienum").html(info.joint);
                            $("#shinum").html(info.time);
                            var length = info.data.length; 
                            for (var i = 0; i < length; i++) {
                                var period = info.data[i];
								console.log(info.data[i]);
								
                                
                                if (period.AddType == 0) {//章
								var infocontent = "<li class='chapter'><div class='menubtn'></div>" + period.periodname;
                                    infocontent += "<div class='rButton'><a href='javascript:;' onclick='edit(<%=CourseID %>," + period.periodid + ",1," + period.ParentID + ")' class='icon icon-edit' ><span>编辑</span></a>";
                                    infocontent += "<div class='addButton'><div class='icon icon-add'><span>添加</span></div><div class='box'><a href='javascript:;' onclick='add(<%=CourseID %>,2," + period.periodid + ")' >添加节</a>";
                                    infocontent += "<a href='" + period.addperiodurl + "' >添加课时</a></div></div>"; 
									infocontent += "<a href='" + period.delurl + "' onclick='return confirm(确定要删除信息么！);' class='icon icon-delete' ><span>删除</span></a></div>";
                                	infocontent += "</li>";
									
                                } else if (period.AddType == 1) {//节
								var infocontent = "<div class='box'><li class='section'><div class='menubtn'></div>" + period.periodname;
                                    infocontent += "<div class='rButton'><a href='javascript:;' onclick='edit(<%=CourseID %>," + period.periodid + ",2," + period.ParentID + ")'  class='icon icon-edit'><span>编辑</span></a>";
                                    infocontent += "<div class='addButton'><div class='icon icon-add'><span>添加</span></div><div class='box'><a href='" + period.addperiodurl + "' ><span>添加课时</span></a></div></div>"; 
									infocontent += "<a href='" + period.delurl + "' onclick='return confirm(确定要删除信息么！);' class='icon icon-delete' ><span>删除</span></a></div>";
                                	infocontent += "</li>";
									
                                } else {//时
								var infocontent = "<div class='box'><li class='keshi'><img src='../../admin/images/ks-img0.png'>" + period.periodname;
                                    infocontent += "<div class='rButton'><a href='" + period.editurl + "'  class='icon icon-edit'><span>编辑</span></a>";
                                    infocontent += "<input type='button' onclick='moveup(" + period.periodid + "," + period.ParentID +")' value='上移'>";
                                    infocontent += "<input type='button' onclick='movedown(" + period.periodid + "," + period.ParentID+")' value='下移'>";
									infocontent += "<a href='" + period.delurl + "' onclick='return confirm(确定要删除信息么！);' class='icon icon-delete' ><span>删除</span></a></div>";
                                	infocontent += "</li></div></div>";
                                }
                                
                                $("#myloop").append(infocontent);
                            }
                        }
						
						var num = $("#myloop li").length;
						if(num==0){
							$("#myloop").prev(".lineY").hide();
							$("#myloop").html('<div class="empty">您还未添加任何课时</div>')
						};
						$("#myloop li").hover(function(){
							$(this).find(".rButton").show();
						},function(){
							$(this).find(".rButton").hide();
						});
						
						$(".addButton").click(function(){
							$(this).toggleClass("addOn");
						});
						
						$(".rButton .icon").hover(function(){
							$(this).find("span").show();
						},function(){
							$(this).find("span").hide();
						});
						
						$(".rButton").click(function(){
							doNone(click());
						});
						
						//展开收缩
						click();
						function click(){
							$(".chapter,.section").click(function(){
								$(this).find(".menubtn").toggleClass("menubtn2");
								$(this).next(".box").stop().slideToggle(300);
							});
						};
						 //是否添加按钮
						$(".menubtn").each(function() {
							var num = $(this).parent().next(".box").length;
							if(num==0){
								$(this).hide();
							};
						});
						$(".chapterBox").each(function() {
							var i = $(this).index()+1;
							if(i>10){
								$(this).find(".chapter .menubtn").addClass("menubtn2");
								$(this).find(".chapter").siblings(".box").hide();
							};
						});


                    }
                });
            }


        </script>
    </asp:Panel>


    <asp:Panel ID="AddPanel" runat="server" Visible="false">
        <!--<KS:TopNav ID="TopNav1" runat="server" Text="" /> -->  
        <div class="content-area mt20">
        	<div class="myTitle">添加课时</div>
            <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable"> 
                <tr>
                    <td align="right" class="lefttd" height="30">所属章节</td>
                    <td class="righttd">
                        <asp:DropDownList ID="DrpChatpter" runat="server">
                            <asp:ListItem Value="0">--请选择章节信息--</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <asp:PlaceHolder ID="PeriodPlace" runat="server"></asp:PlaceHolder>

            </table>
          <div align="center">
              <KS:Foot ID="Foot1" runat="server"  OnSubmit="Foot1_Submit" />
          </div>
        </div>
         
    </asp:Panel>






</asp:Content>
