<%@ Page Title="" Language="VB" MasterPageFile="~/App_MasterPage/mpManager.master" AutoEventWireup="false" CodeFile="TagData.aspx.vb" Inherits="Manager_TagData" %>
<%@ Register assembly="ControlPageing" namespace="ControlPageing" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="chpPageTitle" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="chpHead" Runat="Server">
<style type="text/css">
.Field span{ display:block; padding:0px 3px 0px 3px; float:left; cursor:pointer;border: 1px solid #777777; margin:2px; text-align:center; line-height:22px;}
</style>
<script language="javascript" type="text/javascript">
    function OpenClass() {
        $.dialog({
            lock: false,
            title: '标签分组',
            content: 'url:/Manager/Tags/TagClass.aspx',
            min: false,
            max: false,
            width: 700,
            height: 450
        });
    }
    function confirmWindow(url) {
        $.dialog.confirm('<div style="width:240px;line-height:25px;">单击确定将删除此标签，删除后将无法恢复！<br />你确定要删除这个标签吗？</div>', function() {
            window.location = url;
        });
    }
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="chpScript" Runat="Server">

    <script type="text/javascript" src="/App_Themes/ManagerTheme/Js/jquery.min.js"></script> 
    <script type="text/javascript" src="/App_Themes/ManagerTheme/js/lhgdialog.min.js"></script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="chpTitle" Runat="Server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="chpContent" Runat="Server">
    <asp:MultiView ID="MultiView1" runat="server">
        <asp:View ID="View_Edit" runat="server">
         <script language="javascript" type="text/javascript">
             $(document).ready(function() {
                $.getJSON("/GetSQLClass.gdr?tmp=" + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
                     $("#SQLClass").append("<option value='0' selected='selected'>所有分类</option>");
                     if (data.length > 0) {
                         for (var i = 0; i < data.length; i++) {
                             $("#SQLClass").append("<option value='" + data[i].ID + "'>" + data[i].ClassName + "</option>");
                         }
                     }
                     GetSQLList(0);
                 });
                 $('#<%=imgSave.ClientID %>').bind('click', function() { EnCode(); });
                 cbClick();
                 //GetJsList();
             });
             function cbClick() {
                 $("#FieldList").html('');
                 
//                 if (cbValue) {
//                     $('#trNotCTL').css('display', 'none');
//                     $('#trIsCTL').css('display', 'block');
//                 } else {
//                     $('#trNotCTL').css('display', 'block');
//                     $('#trIsCTL').css('display', 'none');
//                 }
             }
             (function($) {
                 $.fn.insertAtCaret = function(tagName) {
                     return this.each(function() {
                         if (document.selection) {
                             //IE support
                             this.focus();
                             sel = document.selection.createRange();
                             sel.text = tagName;
                             this.focus();
                         } else if (this.selectionStart || this.selectionStart == '0') {
                             //MOZILLA/NETSCAPE support
                             startPos = this.selectionStart;
                             endPos = this.selectionEnd;
                             scrollTop = this.scrollTop;
                             this.value = this.value.substring(0, startPos) + tagName + this.value.substring(endPos, this.value.length);
                             this.focus();
                             this.selectionStart = startPos + tagName.length;
                             this.selectionEnd = startPos + tagName.length;
                             this.scrollTop = scrollTop;
                         } else {
                             this.value += tagName;
                             this.focus();
                         }
                     });
                 };
             })(jQuery);
             
             function GetFieldList(SQLID) {
                 $("#FieldList").html('');
                 var strHTML = "";
                 $.getJSON('/GetFieldList.gdr?SQLID=' + SQLID + '&tmp=' + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
                     if (data.length > 0) {
                         for (var i = 0; i < data.length; i++) {
                             var FieldNote = data[i].FieldNote;
                             if (FieldNote == null || FieldNote == "") { FieldNote = data[i].FieldName; }
                             strHTML += "<span id='" + data[i].FieldName + "'>" + FieldNote + "</span>";
                         }
                         $("#FieldList").html(strHTML);
                         $('#FieldList>span').each(function() {
                             $(this).bind('click', function() { $('#<%=txtTagContent.ClientID %>').insertAtCaret('<field name="' + this.id + '" />'); });
                         });
                     }
                 });                
             }
             function EnCode() {
                 $('#<%=txtTagContent.ClientID %>').attr('value', URLencode($('#<%=txtTagContent.ClientID %>').attr('value')));
             }
             function URLencode(sStr) {
                 var aStr = sStr.replace(/\+/g, '/&/&');
                return encodeURI(aStr);
             }
             function GetSQLList(ClassID) {
                 $("#SQLID").html('');
                 $("#SQLID").append("<option value='0' selected='selected'>所有查询</option>");
                 $.getJSON('/GetSQLList.gdr?ClassID=' + ClassID + '&tmp=' + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
                     if (data.length > 0) {
                         for (var i = 0; i < data.length; i++) {
                             $("#SQLID").append("<option value='" + data[i].ID + "'>" + data[i].SQLName + "</option>");
                         }
                     }
                 });
             }
             function InsertLanguage(lID) {
                 var strURL = '';
                 var mWidth;
                 var mHeight;
                 switch (lID) {
                     case 1:
                         strURL = '/Manager/Tags/FunctionIf.htm';
                         mWidth = 600;
                         mHeight = 310;
                         break;
                     case 2:
                         strURL = '/Manager/Tags/FunctionSelect.htm';
                         mWidth = 600;
                         mHeight = 350;
                         break;
                     case 3:
                         strURL = '/Manager/Tags/FunctionData.htm';
                         mWidth = 600;
                         mHeight = 280;
                         break;
                     case 4:
                         strURL = '/Manager/Tags/FunctionUpload.htm';
                         mWidth = 600;
                         mHeight = 370;
                         break;
                     case 6:
                         strURL = '/Manager/Tags/FunctionCookieRead.htm';
                         mWidth = 600;
                         mHeight = 290;
                         break;
                     case 5:
                         strURL = '/Manager/Tags/FunctionCookieWrite.htm';
                         mWidth = 600;
                         mHeight = 270;
                         break;
                     case 7:
                         strURL = '/Manager/Tags/FunctionSubmit.htm';
                         mWidth = 600;
                         mHeight = 300;
                         break;
                     case 8:
                         strURL = '/Manager/Tags/FunctionRndCode.htm';
                         mWidth = 600;
                         mHeight = 270;
                         break;
                     case 9:
                         $('#<%=txtTagContent.ClientID %>').insertAtCaret('<@sitecounter@><@/sitecounter@>');
                         return;
                         break;
                 }
                 $.dialog({ lock: true,
                     content: 'url:' + strURL,
                     min: false,
                     max: false,
                     cache:false,
                     title:'函数设置',
                     data: '/Sites/Site<%=BaseFunction.PublicMethod.GetApplication("SiteID") %>/Template<%=BaseFunction.PublicMethod.GetApplication("DefaultGroup") %>/',
                     width: mWidth,
                     height: mHeight
                 });
             }
             function InsertFunction(strFunction) {
                 $('#<%=txtTagContent.ClientID %>').insertAtCaret(strFunction);
             }
//             function GetJs(JsID) {
//                 if (JsID != null && JsID != '0') {
//                     var SQLID = $("#SQLID").val();
//                     if (SQLID != null && SQLID != '0') {
//                         $.ajax({
//                             type: "GET",
//                             url: 'GetJs.gdr?JSID=' + JsID + '&SQLID=' + $("#SQLID").val() + '&tmp=' + (new Date()).getTime(),
//                             contentType: 'html',
//                             cache: false,
//                             success: function(responce) {
//                                 if (responce != null && responce != "") {
//                                     $('#<%=txtTagContent.ClientID %>').insertAtCaret(responce);
//                                 }
//                             }
//                         });
//                     } else { alert('请选择查询！'); }
//                 }
//             }
//             function GetJsList() {
//                 $("#SQLExec").html('');
//                 $.getJSON('GetJsList.gdr?tmp=' + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
//                    $("#SQLExec").append("<option value='0' selected='selected'>所有脚本</option>");
//                     if (data.length > 0) {
//                         for (var i = 0; i < data.length; i++) {
//                             $("#SQLExec").append("<option value='" + data[i].ID + "'>" + data[i].JsName + "</option>");
//                         }
//                     }
//                 });
//             }
    </script>
    	    <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0" class="line_table">
	    	<tr>
                    <td align="right" width="20%">分类序号：</td>
                    <td width="30%">
                        <asp:DropDownList ID="dplClassID" runat="server">
                        </asp:DropDownList>
                    </td>
                    <td width="50%"><font color="red">*</font></td>
                </tr>	    	<tr>
                    <td align="right" width="20%">标签名称：</td>
                    <td width="30%">
                        <asp:TextBox ID="txtTagName" runat="server"  Width="96%" ></asp:TextBox>
                    </td>
                    <td width="50%"><font color="red">*</font></td>
                </tr>	    	
                <tr>
                    <td align="right" width="20%">
                        函数标签：</td>
                    <td width="80%" class="Field" colspan="2">
                        <span onclick="InsertLanguage(2);">分支语句</span>
                        <span onclick="InsertLanguage(1);">逻辑判断</span>
                        <span onclick="InsertLanguage(3);">数据输出</span>
                        <span onclick="InsertLanguage(4);">文件上传</span>
                        <span onclick="InsertLanguage(7);">提交按钮</span>
                        <span onclick="InsertLanguage(8);">图片验证码</span>
                        <span onclick="InsertLanguage(5);">Cookie写入</span>
                        <span onclick="InsertLanguage(6);">Cookie读取</span>
                        <span onclick="InsertLanguage(9);">计数器</span>
                    </td>
                </tr>
                <tr ID="trNotCTL">
                    <td align="right" width="20%">查询语句：</td>
                    <td width="80%" colspan="2">
                        <select ID="SQLClass" name="SQLClass" onchange="GetSQLList(this.options[this.options.selectedIndex].value);">
                        </select>
                        <select ID="SQLID" name="SQLID" onchange="GetFieldList(this.options[this.options.selectedIndex].value);">
                        </select>
                        <!-- <select name="SQLExec" id="SQLExec" onchange="GetJs(this.options[this.options.selectedIndex].value,'');"></select>-->
                    </td>
                </tr>
                <tr>
                    <td align="right" width="20%">字段列表：</td>
                    <td width="80%" colspan="2" id="FieldList" class="Field">
                        &nbsp;</td>
                </tr>
                <tr>
                    <td align="right" width="20%" style="vertical-align:top; line-height:25px;">标签内容：</td>
                    <td width="80%" colspan="2">
                        <asp:TextBox ID="txtTagContent" runat="server"  Width="96%" 
                            TextMode="MultiLine" Height="299px"></asp:TextBox>
                    </td>
                </tr>                                                                                             	            
	        
                <tr>
                    <td align="right" colspan="3">
                        <p align="center">
                　          <asp:ImageButton ID="imgSave" runat="server" 
                                ImageUrl="~/App_Themes/ManagerTheme/Images/tj.jpg" style="height: 22px" ToolTip="添加" />
                            <asp:HiddenField ID="hfTagName" runat="server" />
                        </p>
                    </td>
                </tr>
	    </table>        
        </asp:View>
        <asp:View ID="View_List" runat="server">
    	    <div style="text-align: right;" class="edittd">
    	    <a href="#" onclick="javascript:OpenClass();"><img src="/App_Themes/ManagerTheme/Images/QuickMenu.gif" alt="标签分组" /> 标签分组</a>&nbsp;&nbsp;
    	    <asp:DropDownList ID="dplTagClass" runat="server" AutoPostBack="True"></asp:DropDownList>&nbsp;&nbsp;
        	<asp:CheckBox ID="cbSelectAll" runat="server" AutoPostBack="True" Text="全部" />&nbsp;
        	<asp:LinkButton ID="lnkBtnDel" runat="server"><img src="/App_Themes/ManagerTheme/Images/Delete.gif" style=" border:0px"/>&nbsp;删除选中</asp:LinkButton>&nbsp;&nbsp;
        	<a href="TagData.aspx?Action=Add"><img src="/App_Themes/ManagerTheme/Images/add.gif" style=" border:0px" />&nbsp;添加</a>
    	    </div>       
            <asp:Repeater ID="rptList" runat="server">
                <HeaderTemplate>
                    <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0" class="line_table">
			<tr>
			    <td width="5%" align="center" class="left_bt2">选择</td>
			    <td width="70%" align="left" class="left_bt2">标签名称</td>
			    <td align="center" width="25%" class="left_bt2">操作</td>
			</tr>
	        </HeaderTemplate>
                <ItemTemplate>
                    <tr class="menuout"   onMouseOver="this.className='menuin'" onMouseOut="this.className='menuout'">
			<td width="5%" align="center"><asp:CheckBox ID="CheckOn" runat="server" ToolTip='<%#Eval("ID")%>' /></td>
			<td width="70%" align="left"><%#Eval("TagName")%></td>
			<td width="25%" align="center"><a href="TagData.aspx?Action=Edit&ID=<%#Eval("ID") %>">
				<img src="/App_Themes/ManagerTheme/Images/Edit.gif" style=" border:0px" />&nbsp;编辑</a>&nbsp;&nbsp;&nbsp;
				<span style="cursor:pointer" onclick="confirmWindow('TagData.aspx?Action=Del&ID=<%#Eval("ID") %>');"><img src="/App_Themes/ManagerTheme/Images/Delete.gif" style=" border:0px" />&nbsp;删除</span></td>
			        </tr>
                </ItemTemplate>
                <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>
            <div style="text-align:center"> <cc1:iPaging ID="ListPaging" runat="server" /></div>        
        </asp:View>        
    </asp:MultiView>
</asp:Content>