<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ResourceLibrary_Form.aspx.cs"
    Inherits="RM.Web.Training.ResourceLibrary.ResourceLibrary_Form" %>

<!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 id="Head1" runat="server">
    <title>资源操作</title>
    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Validator/JValidator.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Live/swfobject.js"></script>
    <style>
        .List li
        {
            margin: 2px auto;
        }
        .List span
        {
            margin: 2px;
        }
        .List span select
        {
            max-width: 150px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="tksup" style="position: absolute; top: 25px; display: none; border: 1px #ccc solid;
        width: 610px; margin-left: 10px; background-color: White; padding-left: 10px;">
    </div>
    <div>
        <table border="0" cellpadding="0" cellspacing="0" class="frm">
            <tr>
                <td>
                    <input type="button" onclick="shangchuan_mo();" value="本地上传视频" />
                </td>
                <td>
                    <input type="button" onclick="shangchuan_fj();" value="本地上传附件" />
                </td>
                <th>
                    增加外网地址：
                </th>
                <td>
                    <input type="text" style="width: 500px;" value="" id="NetUrl" />
                    <input type="button" value="插入" onclick="UrlInsert();" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div>
                        <ol class="List">
                        </ol>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="frmbottom" style="margin-top: 30px;">
        <asp:LinkButton ID="Save" runat="server" class="l-btn" OnClick="Save_Click"><span class="l-btn-left">
            <img src="/Themes/Images/disk.png" alt="" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Save")%></span></asp:LinkButton>
        <a class="l-btn" href="javascript:void(0)" onclick="OpenClose();"><span class="l-btn-left">
            <img src="/Themes/Images/cancel.png" alt="" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Close")%></span></a>
    </div>
    </form>
    <script type="text/javascript">
        var JsonTypeHtml="";
        var SoIndex=0;
    var jsontype=<%=JsonType %>;
    $(function(){
    LoadTypeJson();
    });
        //删除视频
    function moviedelete(obj)
    {
        $(obj).parent().parent("li").remove();
    }
    //视频上传
        function shangchuan_mo(){
        addtype=1;
         var flashvars = {
                FileType:'*.html;*.htm;*.shtml;*.flv;*.mp4',
                FileMaxCount:10,
                FilePath:'/Training/Courseware/Courseware_movieAdd.ashx',
                FileSize:1024*3000
            };
            FlexUpload(flashvars);
    } 
    //附件上传
    function shangchuan_fj(){
    addtype=2;
         var flashvars = {
FileType:'*.bmp;*.jpg;*.jpge;*.gif;*.png;*.rar;*.zip;*.doc;*.docx;*.wps;*.avi;*.chm;*.mp3;*.mp4;*.xls;*.xlsx;*.txt;*.pdf;*.ppt;*.pptx',
                FileMaxCount:10,
                FilePath:'/Training/Courseware/UpLoadShares.ashx',
                FileSize:1024*300
            };
            FlexUpload(flashvars);
    }
    //Flex文件上传
    function FlexUpload(flashvars)
    {
        $("#tksup").show();
        $("#tksup").append("<div id='ad1'></div>");

        var swfVersionStr = "10.0.0";
        var xiSwfUrlStr = "/live/playerProductInstall.swf";
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
        var attributes = {};
        attributes.id = "ad1";
        attributes.name = "ad1";
        attributes.align = "middle";
        swfobject.embedSWF("/Live/TKS-UP.swf", "ad1","600", "270", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
    }
    //Flex上传回调函数
    //---name:为文件名---data:FilePath地址返回值
    function uploadCompelete(name,data){
    
        if(addtype==1){//视频
            if (data=="1") {
                   showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_size")%>",2000, 5);
              }else if(data=="3"){
                 showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Abnormal network connection")%>", 2000, 5);
               }else if(data =="4"){
                 showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_not")%>", 2000, 5);
               }else {
                    path=data;
                    if (path != "") {
                        name = name.substring(name.lastIndexOf("\\") + 1, name.lastIndexOf("."));
                       AddLoad(name,path,1);
                    }
               }
        }
        else if(addtype==2){//附件
            if (data==-3) {
                    showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_not")%>,",2000, 5);
             }else if(data==-2){
                 showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_size")%>", 2000, 5);
             }else {
               path=data;
               if (path != "") {
                name = name.substring(name.lastIndexOf("\\") + 1, name.lastIndexOf("."));
             AddLoad(name,path,2);
             }
        }
    }
    }
    //全部文件上传结束后触发
    function uploadEnd(name){
        $("#tksup").hide();
        $("#ad1").remove();
    }
    //父级
    function LoadTypeJson()
    {
        //        rs = eval('(' + rs + ')');
        $.each(jsontype,function(i,obj){
            if (obj.CoursewareType_ParentId=="0") {
                JsonTypeHtml+="<option value=\""+obj.CoursewareType_CtId+"\">"+obj.CoursewareType_CtName+"</option>";
                LoadTypeChild(obj.CoursewareType_CtId);
         }
       });
    }
    //子集
    function LoadTypeChild(Fid){
         $.each(jsontype,function(i,obj){
         if (obj.CoursewareType_ParentId==Fid) {
              JsonTypeHtml+="<option value=\""+obj.CoursewareType_CtId+"\">"+obj.CoursewareType_CtName+"</option>";
              LoadTypeChild(obj.CoursewareType_CtId);
                }
         });
    }
    //赋值分类name
    function CopyTypeName(obj){
    $(obj).parent().find("[type=hidden]").val($(obj).find("option:selected").text());
    }
    //插入方法
    function UrlInsert()
    {
    var text=$("#NetUrl").val();
    if (text.indexOf(".flv")>=0||text.indexOf(".mp4")>=0) {
    AddLoad("",text,1);
}else {
     AddLoad("",text,2);
}
    }
    function AddLoad(name,path,addtype)
    {
      var check1="selected=\"selected\"";
      var check2="selected=\"selected\"";
            if (addtype==1) {
            check2="";
            }else {
            check1="";
        }
          $(".List").append("<li><span>文件名：<input type=\"text\" name=\"Resource_Name\" value=\""+decodeURI(name)+"\" /></span> <span>文件地址：<input type=\"text\" name=\"Resource_Url\" value=\""+path+"\" /></span> <span>所属分类：<select name=\"Resource_TypeID\" id=\"Resource_TypeID_"+SoIndex+"\" onchange=\"CopyTypeName(this);\"> <option value=\"0\" selected=\"selected\">请选择</option> </select><input type=\"hidden\"  name=\"Resource_TypeName\" /></span> <span>类型：<select name=\"Resource_Code\"><option value=\"1\" "+check1+">视频</option> <option value=\"2\""+check2+">文档</option> </select></span> <span>下载中心是否显示：<select name=\"Resource_IsShow\"><option value=\"1\" selected=\"selected\">不显示</option><option value=\"0\">显示</option></select></span> <span><input type=\"button\" value=\"×\" onclick=\"moviedelete(this)\" /></span> </li>");
           $("#Resource_TypeID_"+SoIndex).append(JsonTypeHtml);
          SoIndex++;
    }

    </script>
</body>
</html>
