<%@ Page Language="C#" AutoEventWireup="true" Inherits="System_Label_SetStyle, QianboCMS" ValidateRequest="false" EnableEventValidation="false" %>
<%@ Import Namespace="Qianbo.Common" %>
<!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">
    <title>设置样式</title>
    <link rel="stylesheet" href="../Css/layout.css" type="text/css" />
    <script type="text/javascript" src="../../Js/jquery.js"></script>
    <script type="text/javascript" src="../../Js/lhgdialog/lhgdialog.min.js?self=true"></script>
    <script language="javascript" type="text/javascript" src="../../Js/Common.js"></script>
    <script language="javascript" type="text/javascript">
        function $(val) {
            return document.getElementById(val);
        }
        function setx(obj) {
            $("test").focus();
            if (document.selection) {
                var range = document.selection.createRange();
                range.text = obj.value;
            }
            obj.options[0].selected = true;
        }
        function CheckValidate() {
            if ($("txtTypeName").value.trim().length == 0) {
                alert("样式名称不能为空！");
                $("txtTypeName").focus();
                return false;
            }
            if ($("test").value.trim().length == 0) {
                alert("样式内容不能为空！");
                return false;
            }
            return true;
        }
        function ChangeModel() {
            if ($("ddlModel").value == "2") {
                $("userCustomField").style.display = "";
                $("articleField").style.display = "none";
            }
            else {
                $("articleField").style.display = "";
                $("userCustomField").style.display = "none";
            }
        }
        function ContentStyle() {
            try {
                userStyle.style.display = "none";
                userField.style.display = "none";
                conStyle.style.display = "";
                conField.style.display = "none";
                extendStyle.style.display = "none";
            }
            catch (e) {
            }
        }
        function UserStyle() {
            conStyle.style.display = "none";
            try {
                conField.style.display = "none";
            }
            catch (e) {
            }
            userStyle.style.display = "";
            userField.style.display = "";
            extendStyle.style.display = "none";
        }
        function CustomField() {
            conStyle.style.display = "none";
            try {
                conField.style.display = "";
            }
            catch (e) {
            }
            userStyle.style.display = "none";
            userField.style.display = "none";
            extendStyle.style.display = "none";
        }
        var menuHit = 0;
        function ShowModelList() {
            if (menuHit == 0) {
                modelMenuList.style.display = "";
                menuHit = menuHit + 1;
            }
            else {
                modelMenuList.style.display = "none";
                menuHit = menuHit - 1;
            }
        }
        function showMenu() {
            modelMenuList.style.display = "";
            menuHit = 1;
        }
        function OpenWindow() {
            var modelId =<%=isShowTr %>
    if (modelId == "0") {
            alert("当前选择的是通用样式，无法选择扩展字段。");
            return;
        }
        var jq = jQuery.noConflict();
        jQuery.dialog({
            id: 'txtSelectColumn',
            lock: true,
            resize: true,
            title: '扩展字段',
            content: "url:SelectColumn.aspx?modelId=<%=isShowTr%>",
            width: 350,
            height: 500
        });
            extendStyle.style.display = "";
            userStyle.style.display = "none";
            userField.style.display = "none";
        }
    </script>
</head>

<body onmousemove="dragmove();" onmouseup="dragclear()" onload="GetSysFieldList()">
    <form id="form1" runat="server">
        <div>
            <table cellspacing="1" cellpadding="0" class="wzdh" align="center">
                <tr>
                    <td class="wzlist">
                        <img src="../Images/Skin/Default/you.gif" align="absmiddle" />
                        您现在的位置：<a href="../SystemInfo.aspx">后台管理</a> &gt;&gt; <a href="../Template/CreateFolder.aspx">标签&模板管理</a> &gt;&gt; <a href="StyleManager.aspx">样式管理</a> &gt;&gt; 创建样式
					</td>
                </tr>
            </table>
            <table cellpadding="0" cellspacing="1" class="border" align="center">
                <tr>
                    <td class="wzlist">
						<span style="float: left;">
							<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="StyleManager.aspx">样式管理首页</asp:HyperLink> | <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="AddStyleType.aspx">新增样式分类</asp:HyperLink> | <a href="#" onclick="javascript:window.history.back();">返回</a>
						</span>
                        <span style="float: right;">
                            <asp:DropDownList ID="ddlRedirectPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlRedirectPage_SelectedIndexChanged">
                                <asp:ListItem>跳转类型至…</asp:ListItem>
                                <asp:ListItem Value="StyleManager.aspx">样式管理</asp:ListItem>
                                <asp:ListItem Value="LabelManager.aspx">标签管理</asp:ListItem>
                                <asp:ListItem Value="../Template/CreateFolder.aspx">模板管理</asp:ListItem>
                            </asp:DropDownList>
                        </span>
					</td>
                </tr>
            </table>
            <table cellpadding="0" cellspacing="1" class="border" align="center">
                <tbody>
                    <tr>
                        <td class="bqleft">样式名称：</td>
                        <td class="bqright">
                            <asp:TextBox ID="txtTypeName" runat="server" Width="40%" MaxLength="200"></asp:TextBox>
                            <asp:DropDownList ID="ddlStyleType" runat="server"></asp:DropDownList>
						</td>
                    </tr>
                    <tr>
                        <td class="bqleft">选择样式：</td>
                        <td class="bqright">
                            <div style="float: left; background: url(../Images/Skin/Default/sitelist.png) no-repeat; width: 100px; line-height: 26px; padding-left: 12px; font-weight: bold; display: inline;"><a href="#" onclick="ContentStyle()">通用字段</a></div>
                            <div style="float: left; background: url(../Images/Skin/Default/sitelist.png) no-repeat; width: 100px; line-height: 26px; padding-left: 12px; font-weight: bold; display: inline;"><a href="#" onclick="CustomField()">自定义字段</a></div>
                            <div style="float: left; background: url(../Images/Skin/Default/sitelist.png) no-repeat; width: 100px; line-height: 26px; padding-left: 12px; font-weight: bold; display: inline;"><a href="#" onclick="OpenWindow()">扩展字段</a></div>
                            <div style="float: left; background: url(../Images/Skin/Default/sitelist.png) no-repeat; width: 100px; line-height: 26px; padding-left: 12px; font-weight: bold; display: inline;"><a href="#" onclick="ShowModelList()">用户字段</a></div>
                        </td>
                    </tr>
                    <tr id="conStyle">
                        <td class="bqleft">系统字段：</td>
                        <td class="bqright">
                            <div id="sysFieldShow"></div>
                        </td>
                    </tr>
                    <%if (isShowTr != 1 && isShowTr != 2 && isShowTr != 3 && isShowTr != 0 && ctmFildCount > 0)
                        { %>
                    <tr id="conField" style="display: none;">
                        <td class="bqleft">自定义字段：</td>
                        <td class="bqright">
                            <div id="customFieldShow"></div>
                        </td>
                    </tr>
                    <%} %>
                    <%if (isShowTr == 1)
                        {%>
                    <tr id="conField" style="display: none;">
                        <td class="bqleft">自定义字段：</td>
                        <td class="bqright">
                            <div id="articleFieldShow"></div>
                        </td>
                    </tr>
                    <%} %>
                    <%if (isShowTr == 2)
                        { %>
                    <tr id="conField" style="display: none;">
                        <td class="bqleft">自定义字段：</td>
                        <td class="bqright">
                            <div id="ImageFieldShow">图片</div>
                        </td>
                    </tr>
                    <%} %>
                    <%if (isShowTr == 3)
                        { %>
                    <tr id="conField" style="display: none;">
                        <td class="bqleft">自定义字段：</td>
                        <td class="bqright">
                            <div id="downloadFieldShow">下载</div>
                        </td>
                    </tr>
                    <%} %>
                    <tr id="userStyle" style="display: none;">
                        <td class="bqleft">系统字段：</td>
                        <td class="bqright">
                            <div id="userSysField"></div>
                        </td>
                    </tr>
                    <tr id="userField" style="display: none;">
                        <td class="bqleft">自定义字段：</td>
                        <td class="bqright">
                            <div id="customUserField"></div>
                        </td>
                    </tr>
                    <tr id="extendStyle" style="display: none;">
                        <td class="bqleft">扩展字段：</td>
                        <td class="bqright">
                            <div id="extendFiled"></div>
                        </td>
                    </tr>
                    <tr>
                        <td class="bqleft">样式内容：</td>
                        <td class="bqright">
                            <textarea id="test" rows="14" cols="80" style="width: 100%;" runat="server" onmouseup="dragend()" onmousemove="movePoint()"></textarea>
						</td>
                    </tr>
                    <tr>
                        <td class="bqleft"></td>
                        <td class="bqright">
                            <asp:Button ID="btnSave" CssClass="btn" runat="server" Text="添加样式" OnClick="btnSave_Click" OnClientClick="return CheckValidate()" />
                            <asp:Button ID="btnReset" CssClass="btn" runat="server" Text="重新填写" OnClick="btnReset_Click" />
						</td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div id="modelMenuList" style="display: none; position: absolute; top: 0px; margin-top: 128px; margin-left: 520px; width: 110px; padding: 0px;" onmouseout="ShowModelList()">
            <table cellpadding="0" cellspacing="1" class="border" style="border: none;" align="center">
                <asp:Repeater runat="server" ID="repUserModelList">
                    <ItemTemplate>
                        <tr class="tdbg">
                            <td style="cursor: hand;" onmouseover="showMenu();javascript:this.style.backgroundColor='#f7f7f7'" onmouseout="showMenu();javascript:style.backgroundColor='#eef6fb'"><a href="#" onclick="UserStyle();ShowModelList();GetUserCustomField(<%# Eval("Id") %>)"><%# Eval("Name")%></a></td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </table>
        </div>
    </form>
</body>
</html>
<script language="javascript" type="text/javascript">
    function SetExtFileStyle(colid) {
        System_Label_SetStyle.GetExtendFiled(colid, ExtendFiled);
    }
    function GetSysFieldList() {
        System_Label_SetStyle.GetSysFieldList('', Callback);
        System_Label_SetStyle.GetArticleList('', CallBackArticle);
        System_Label_SetStyle.GetImageList('', CallBackImage);
        System_Label_SetStyle.GetDownLoadList('', CallBackDownLoad);
        System_Label_SetStyle.GetCustomList('', CallBackCustom);
        System_Label_SetStyle.GetUserSysFieldList('', UserSysField);
        System_Label_SetStyle.GetExtendFiled('0', ExtendFiled);
    }
    function GetUserCustomField(val) {
        System_Label_SetStyle.GetUserModelCustomListDt(val, CallBackUserCustomModel);
    }
    function Callback(result) {
        try {
            $('sysFieldShow').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["FieldName"];
                var fieldValue = result.value.Rows[i]["FieldValue"];
                if (fieldValue != "$search$") {
                    str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                }
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            str += "</tr></table>"
            $('sysFieldShow').innerHTML = str;
        }
        catch (e) { }
    }
    function CallBackArticle(result) {
        try {
            $('articleFieldShow').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%' ><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["FieldName"];
                var fieldValue = result.value.Rows[i]["FieldValue"];
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7 && (totalcount % 7) != 0) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('articleFieldShow').innerHTML = str;
        }
        catch (e) { }
    }
    function CallBackImage(result) {
        try {
            $('ImageFieldShow').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["FieldName"];
                var fieldValue = result.value.Rows[i]["FieldValue"];
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('ImageFieldShow').innerHTML = str;
        }
        catch (e) { }
    }
    function CallBackDownLoad(result) {
        try {
            $('downloadFieldShow').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["FieldName"];
                var fieldValue = result.value.Rows[i]["FieldValue"];
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7 && (totalcount % 7) != 0) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('downloadFieldShow').innerHTML = str;
        }
        catch (e) { }
    }
    function CallBackCustom(result) {
        try {
            $('customFieldShow').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["Alias"];
                if (result.value.Rows[i]["Name"] == "$search$") {
                    var fieldValue = result.value.Rows[i]["Name"];
                }
                else {
                    var fieldValue = "{Qianbo_" + result.value.Rows[i]["Name"] + "}";
                }
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7 && ((totalcount % 7) != 0 || count < 7)) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('customFieldShow').innerHTML = str;
        }
        catch (e) { }
    }
    function UserSysField(result) {
        try {
            $('userSysField').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["FieldName"];
                var fieldValue = result.value.Rows[i]["FieldValue"];
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7 && ((totalcount % 7) != 0 || count < 7)) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('userSysField').innerHTML = str;
        }
        catch (e) { }
    }
    function CallBackUserCustomModel(result) {
        try {
            $('customUserField').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["Alias"];
                if (result.value.Rows[i]["Name"] == "$search$") {
                    var fieldValue = result.value.Rows[i]["Name"];
                }
                else {
                    var fieldValue = "{Qianbo_User_" + result.value.Rows[i]["Name"] + "}";
                }
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7 && ((totalcount % 7) != 0 || count < 7)) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('customUserField').innerHTML = str;
        }
        catch (e) { }
    }
    function ExtendFiled(result) {
        try {
            $('extendFiled').innerHTML = "";
            var count = result.value.Rows.length;
            var str = "<table cellpadding='2' cellspacing='2' border='0' width='80%'><tr>";
            var rowcount = parseInt(count / 7) + 1;
            var totalcount = rowcount * 7;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["Alias"];
                if (result.value.Rows[i]["Name"] == "$search$") {
                    var fieldValue = result.value.Rows[i]["Name"];
                }
                else {
                    var fieldValue = "{Qianbo_" + result.value.Rows[i]["Name"] + "}";
                }
                str += "<td width='14%'>" + FillText(text, fieldValue) + "</td>";
                if (i != 0 && (i + 1) % 7 == 0 && (i + 1) != count) {
                    str += "</tr><tr>"
                }
            }
            if (count < totalcount && count != 7 && ((totalcount % 7) != 0 || count < 7)) {
                for (i = 0; i < (totalcount - count); i++) {
                    str += "<td width='14%'>" + FillText('&nbsp;', '&nbsp;') + "</td>";
                }
            }
            str += "</tr></table>"
            $('extendFiled').innerHTML = str;
        }
        catch (e) { }
    }
    function FillText(val, fieldValue) {
        if (fieldValue != "$search$" && val != "&nbsp;" && fieldValue != "$cart$")
            return "<div id=" + fieldValue + " onmousedown='DragStart()' onclick='SetValue()' style='cursor: hand; border: solid 1px #9c9c9c; width: 99%; height: 99%; text-align: center; background-color: #e1ecee;'>" + val + "</div>"
        else if (fieldValue == "$search$" && val != "&nbsp;" && fieldValue != "$cart$")
            return "<div id='<a href=javascript:showlist(\"<%=Param.ApplicationRootPath %>\",\"{Qianbo_chid}\",\"字段名称\",\"{Qianbo_字段名称}\",\"blank\")>字段值</a>' onmousedown='DragStart()' onclick='SetValue()' style='cursor: hand; border: solid 1px #9c9c9c; width: 99%; height: 99%; text-align: center; background-color: #e1ecee;'>" + val + "</div>";
        else if (fieldValue == "$cart$" && val != "&nbsp;")
            return "<div id='<a href=javascript:BuyCart(\"<%=Param.ApplicationRootPath %>\",\"{Qianbo_chid}\",\"{Qianbo_id}\")><img src=\"/Images/cart.gif\" border=0>放入购物车</a>' onmousedown='DragStart()' onclick='SetValue()' style='cursor: hand; border: solid 1px #9c9c9c; width: 99%; height: 99%; text-align: center; background-color: #e1ecee;'>" + val + "</div>";
        else
            return "<div></div>"
    }
    var labelStr;
    function DragStart() {
        dragclear();
        window.drag = 1;
        dragspan = document.createElement('div');
        dragspan.style.position = "absolute";
        dragspan.className = "tips2";
        var mousePos = mouseCoords(window.event);
        dragspan.style.left = mousePos.x + 20;
        dragspan.style.top = mousePos.y + 10;
        labelStr = window.event.srcElement.id;
        dragspan.appendChild(document.createTextNode(window.event.srcElement.innerHTML));
        document.body.appendChild(dragspan);
    }
    function SetValue() {
        document.all.test.focus();
        var tarobj = document.selection.createRange();
        tarobj.text = labelStr;
        if (window.drag) {
            window.drag = 0;
            window.event.returnValue = true;
        }
    }
    function dragend() {
        if (window.drag) {
            document.body.removeChild(dragspan);
            SetValue();
        }
    }
    function mouseCoords(ev) {
        if (ev.pageX || ev.pageY) {
            return { x: ev.pageX, y: ev.pageY };
        }
        return {
            x: ev.clientX + document.documentElement.scrollLeft - document.body.clientLeft,
            y: ev.clientY + document.documentElement.scrollTop - document.body.clientTop
        };
    }
    function dragclear() {
        if (window.drag) {
            document.body.removeChild(dragspan);
            window.drag = 0;
            window.event.returnValue = true;
        }
    }
    function dragmove() {
        if (window.drag) {
            var ev = ev || window.event;
            var mousePos = mouseCoords(ev);
            ev.returnValue = false;
            dragspan.style.left = mousePos.x + 10;
            dragspan.style.top = mousePos.y + 8;
        }
    }
    function movePoint() {
        if (window.drag) {
            var rng = event.srcElement.createTextRange();
            rng.moveToPoint(event.x, event.y);
            rng.select();
        }
    }
</script>