<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Admin_Template.aspx.vb"
    Inherits="TourEx.Web.Admin_Template" %>
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题页</title>
<link rel="stylesheet" type="text/css" href="Css/Style.css"/>
<script language="javascript" src="../Sys/Js/jquery.js"></script>
<script type="text/javascript" src="../Sys/Js/CreateSelect.js"></script>
<script language="javascript" src="../Sys/Js/AlertWindow.js"></script>
</head>
<body>
    <div id="messWindow" class="messWindow">
    </div>
    <div id="AddTemplate" class="promptWindow" align="center">
        <div class="titleBar">
            <span>添加模板</span><span onclick="HideWindow()" style="float:right;"><img src="Images/popclose.gif" /></span></div>
        <div class="mainContent">
            <form action="?Act=Add" method="post" onsubmit="return CheckAddForm();">
            <table width="96%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D6DFF7">
                <tr>
                    <td class="subMainLeft" width="80">模板名：</td>
                    <td class="subMainRight" align="left"><input name="T_Name" type="text" id="T_Name" size="15" class="formTitle"/></td>
                </tr>
                <tr>
                    <td class="subMainLeft" width="80">目录名：</td>
                    <td class="subMainRight" align="left">
                        <input type="text" name="T_Folder" id="T_Folder" onkeyup="this.value=this.value.replace(/\W/g,'');"
                            size="20" maxlength="20" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\W/g,''))" class="formTitle">
                    </td>
                </tr>
            </table>
			<div class="subMainFoot"><input name="submit" type="submit" class="formInput01" value="添加" /> <input type="button" class="formInput02" value="取消" onclick="HideWindow()"/></div>
            </form>

            <script type="text/javascript">
        			<!--//
        				function CheckAddForm()
        				{
        				    var Name = $('input[name="T_Name"]','#AddTemplate');
        					var NameV = $.trim(Name.val());
        					Name.val(NameV);
        					if(NameV==''){alert('请填写模板名!');Name.focus();return false;};
        					var Folder = $('input[name="T_Folder"]','#AddTemplate');
        					var FolderV = $.trim(Folder.val().toLowerCase());
        					Folder.val(FolderV);
        					if(FolderV==''){alert('请填写目录名!');Folder.focus();return false;};
        					var T = $('#TemplateList>select').children();
        					for(var i=0;i<T.length;i++)
        					{
        						if($(T).eq(i).html()==NameV){alert('模板名重复!');Name.focus();return false;}
        						if($(T).eq(i).attr('T_Folder')==FolderV){alert('目录名重复!');Folder.focus();return false;}
        					}
        					return true;
        				}
        			//-->
            </script>

        </div>
    </div>
    <div id="ViewFile" class="promptWindow" align="center">
        <div class="titleBar">
            <span>查看文件</span><span onclick="HideWindow()" style="float:right;"><img src="Images/popclose.gif" /></span></div>
        <div class="mainContent">
            <iframe src="" id="ViewFileIframe" name="ViewFileIframe" width="100%" height="100%" scrolling="No" frameborder="0" onload="this.style.height=ViewFileIframe.document.body.scrollHeight>500?500:ViewFileIframe.document.body.scrollHeight+5">
            </iframe>
        </div>
    </div>
    <div id="UpFile" class="promptWindow" align="center">
        <div class="titleBar">
            <span>上传文件</span><span onclick="HideWindow()" style="float:right;"><img src="Images/popclose.gif" /></span></div>
        <div class="mainContent">
            <form action="?ID=<%=ThisID %>&Act=UpFile&Path=<%=Path %>" enctype="multipart/form-data"
            onsubmit="return CheckUpFile();" method="post">
            <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D6DFF7">
                <tr>
                    <td class="subMainLeft" width="100">
                        上传文件：
                    </td>
                    <td class="subMainRight" id="UpFileList" align="left">
                        <input name="upload" type="file" />
                    </td>
                </tr>
            </table>
			<div class="subMainFoot"><input type="submit" value="确定" class="formInput01" /> <input id="Button1" type="button" value="添加上传" onclick="$('#UpFileList').append('<input name=\'upload\' type=\'file\' /><br />');" class="formInput02" /></div>
            </form>

            <script type="text/javascript">
               function CheckUpFile()
               {
                    var files=0;
                    var isfile=true;
       	            var upext = 'bmp,ico,jpg,jpeg,gif,png,swf,avi,js,css,html';
       	            $('#UpFileList>:file').each(function(){
       	                var fname = $(this).val();
       	                if(fname!='')
       	                {
       	                    files++;
       	                    if(!fname.match(new RegExp('\.('+upext.replace(/,/g,'|')+')$','i')))isfile=false;
       	                }
       	            });
   	                if(!isfile)
   	                {
   	                    alert('上传文件扩展名必需为：'+upext);return false;
   	                }else if(files==0){
   	                    alert('请选择要上传的文件');return false;
   	                }
   	                return true;
               }
            </script>

        </div>
    </div>
    <div id="AddFile" class="promptWindow" align="center">
        <div class="titleBar">
            <span>添加文件夹/文件</span><span onclick="HideWindow()" style="float:right;"><img src="Images/popclose.gif" /></span></div>
        <div class="mainContent">
            <form action="?Act=AddFile&Path=<%=Path %>" method="post" onsubmit="return CheckAddFile();">
            <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D6DFF7">
                <tr>
                    <td class="subMainLeft" width="100">文件夹/文件名：</td>
                    <td class="subMainRight" align="left">
                        <input type="text" name="T_Name" onkeyup="this.value=this.value.replace(/[^\w\.]/g,'');"
                            size="20" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\w\.]/g,''))" class="formTitle">
                    </td>
                </tr>
            </table>
			<div class="subMainFoot"><input type="submit" value="确定" class="formInput01" /> <input type="button" class="formInput02" value="取消" onclick="HideWindow()"/></div>
            </form>

            <script type="text/javascript">
        			<!--//
        				function CheckAddFile()
        				{
        				    var Name = $('input[name="T_Name"]','#AddFile');
        					var V = $.trim(Name.val());
        					Name.val(V);
        					if(V=='')
        					{
        					    alert('请填写名称！');return false;
        					}
        					if(V.indexOf('.')!=-1)
        					{
    					       	var upext = 'html,css,js';
   	                            if(!V.match(new RegExp('\.('+upext.replace(/,/g,'|')+')$','i')))
   	                            {
   		                            alert('只允许添加'+upext+'文件');return false;
   	                            }
        					}
        					return true;
        				}
        			//-->
            </script>

        </div>
    </div>
    <form action="?act=edit&id=<%=thisid %>" method="post">
	<ul class="tools">
		<li class="upload"><span><a href="javascript:void(0);" onclick="ShowWindow('','UpFile')">上传文件</a></span></li>
		<li class="add"><span><a href="javascript:void(0);" onclick="ShowWindow('','AddFile')">添加页面</a></span></li>
		<li class="add"><span><a href="javascript:void(0);" onclick="ShowWindow('','AddTemplate')">添加模板</a></span></li>
		<li class="search">选择模板： <span id="TemplateList">
            <input id="TemplateID" type="hidden" />
        </span>
            <input type="button" id="Default" value="设为默认" onclick="location='?Act=default&ID='+$('#TemplateID').val()" />
            <input type="button" id="Del" onclick="if(confirm('确定要删除这个模板吗？')){location='?Act=del&id='+$('#TemplateID').val();}"
                value="删除" />
            改名为：<input name="Edit_T_Name" id="Edit_T_Name" type="text" class="searchTitle"/>
            <input type="submit" name="Submit" value="" class="searchInput" style="background:url(Images/toolsSearch1.gif);"/>
            <input type="button" id="Generate" value="" onclick="location='?Act=generate&ID='+$('#TemplateID').val()" class="searchInput" style="background:url(Images/toolsSearch2.gif);"/></li>
	</ul>
    </form>
    <form id="BatchSubmit" name="BatchSubmit" method="post" action="?act=edit&id=<%=ThisID %>"
    style="display: none">
    </form>
                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabBox">
                    <tr class="tabTitleMain">
                        <td class="selectAll">文件夹/文件(<asp:Label ID="navIgation" runat="server" Text=""></asp:Label>)</td>
                        <td width="100">操作</td>
                    </tr>
    <asp:Repeater ID="Repeater" runat="server">
        <ItemTemplate>
            <tr class="tabTextMain" onmouseout="this.style.background='#FFFFFF';"
                onmouseover="this.style.background='#F4F7FA';">
                <td id="form_<%#Eval("T_ID")%>">
                    <input id="T_OName_<%#Eval("T_ID")%>" name="T_OName" type="hidden" value="<%#Eval("T_FilePath")%>" class="formTitle"/>
                    <input id="T_Name_<%#Eval("T_ID")%>" name="T_Name" type="text" value="<%#Eval("T_Name")%>"
                        size="50" class="formTitle"/><%#Eval("T_Ext")%>
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="Save(<%#Eval("T_ID")%>);return false;">保存</a>
                    <%#IIf(Eval("T_Ext") = "", "<a href=""?id=" & ThisID & "&Path=" & Eval("T_FilePath") & """>下级</a>", "")%>
                    <%#IIf(InStr(",.css,.js,.html,", "," & Eval("T_Ext") & ",") > 0, "<a href=""Admin_TemplateEdit.aspx?id=" & ThisID & "&Path=" & Eval("T_FilePath") & """>编辑</a>", "")%>
                    <%#IIf(InStr(",.jpg,.jpeg,.gif,.png,.swf,.avi,", "," & Eval("T_Ext") & ",") > 0, "<a href=""javascript:void(0);"" onclick=""$('#ViewFileIframe').attr('src','../Sys/Resource/Template/" & Folder & "/" & Eval("T_FilePath") & "');ShowWindow('','ViewFile')"">查看</a>", "")%>
                    <a href="javascript:void(0);" onclick="Del('<%#Eval("T_FilePath")%>');return false;">
                        删除</a>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
            <asp:Label ID="lblEmpty" Text="暂无" runat="server" Visible="<%#Boolean.Parse((Repeater.Items.Count = 0).ToString())%>"
                Width="100%" Style="text-align: center">     
            </asp:Label>
        </FooterTemplate>
    </asp:Repeater>
    <asp:Label ID="js" runat="server" Text=""></asp:Label>

    <script type="text/javascript">
    <!--//
        $('td[id^="form_"]').bind("click", function(event){
            if('TD'!=event.target.tagName)return false;
            var a = $(this).next('td').find("a:contains('编辑'),a:contains('下级')");
            if(a.length==0)return false;
            location=$(a).attr('href');
        }); 

        CreateSelect("TemplateList","TemplateID",<%=ThisID%> ,3,"",function(){location='?ID='+$('#TemplateID').val();},"Template","../");
        function Del(Path)
        {
            if(confirm('您确定删除这个文件夹(文件)吗！')){location='?act=delfile&id=<%=THisID %>&Path='+Path;}
        }
        function Save(ID)
        {
            var v = $.trim($('#T_Name_'+ID).val());
            if(confirm('您确定修改这个文件夹(文件)名吗！')){location='?act=movefile&id=<%=THisID %>&Path='+$('#T_OName_'+ID).val()+'&name='+v;}
        }
        function ChangeTemplate(ID)
        {
	        if(ID=='<%=T_DefaultID%>')
	        {
		        $('#Default,#Del').hide();
		        $('#Generate').show();
	        }else{
		        $('#Default,#Del').show();
		        $('#Generate').hide();
	        }
        }
        ChangeTemplate('<%=ThisID%>');
    //-->
    </script>

</body>
</html>
