<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Admin/AdminMain.Master" Inherits="System.Web.Mvc.ViewPage<MvcEnterprise.Models.DataSet1+ProductRow>" %>

<asp:Content ID="Content0" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Admin.js" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Content/fckeditor/fckeditor.js")%>" type="text/javascript"></script>
    <%Html.EnableClientValidation(); %>
	<style type="text/css">
		#SelectThumb {
			position: absolute;
			display: none;
			border: 1px solid #666;
			background: #E7EBEF;
			line-height: 1.5em;
			background: #436888;
			color:#CCC;
		}
		#SelectThumb select {
			color:#000;
			border: none;
			background: #E7EBEF;
		}
	</style>
    <script type="text/javascript">
		var labelwidth;
    	$(document).ready(function () {
			<%if (!string.IsNullOrEmpty(Request.QueryString["SortPath"])) {%>
			$("#SortPath").val('<%= Request.QueryString["SortPath"] %>');
			<%} %>
            $("#SortID").val(GetSortID());
            $("#SortPath").change(function () {
                $("#SortID").val(GetSortID());
            });
			labelwidth=$("span[class='editor-label']:first").width();

			var SelectThumb = $("#SelectThumb");
			var SmallPic=$("#SmallPic");
			SelectThumb.css({left:SmallPic.offset().left});
			SmallPic.focus(function () {
				var BigPicItem=$("input[rel='BigPicItem']");
				var html;
				var size=2; //小于2时select为DropDownList样式
				BigPicItem.each(function () {
					var imgurl=this.value;
					if ($.trim(imgurl)=="") return;
					if (imgurl.toLowerCase().substring(0,4) != "http") {
						var offset=imgurl.lastIndexOf(".");
						strstart=imgurl.substring(0,offset);
						strend=imgurl.substr(offset);
						imgurl=strstart+"_thumb"+strend;
					}
					html+=("<option value='"+imgurl+"'");
					if (imgurl==SmallPic.val()) html+=" selected";
					html+=(">"+imgurl+"</option>");
					size++;
				});
				if (size > 2) {
					size = size == 3 ? size-1 : size-2;
					SelectThumb.html("<div>从大图生成的略图中选择：</div><select onchange='SetSmallPic(this.value);' size='"+size+"'>"+html+"</select>");
				}
				else {
					return;
				}
				SelectThumb.css("display","block");
			}).blur(function(){
				SelectThumb.css("display","none");
			});
        });
		function SetSmallPic(text){
			$("#SmallPic").val(text);
		}
        function GetSortID() {
            var sortID = $("#SortPath").val();
            sortID = sortID.substring(0, sortID.length - 1);
            sortID = sortID.substring(sortID.lastIndexOf(",") + 1);
            return sortID;
        }
        function AddImg(e,inputName) {
			var inputImg = "<span><%= Html.TextBoxFileUrlFor(t=>string.Empty, "Image", new { rel = "BigPicItem" }).ToHtmlString().Replace(Environment.NewLine," ").Replace("\"","\\\"").Replace("</script>","\"+\"</sc\"+\"ript>") %><input type=\"button\" onclick=\"RemoveImg(this);return false;\" value=\"删除\" /><br /></span>";
            $("#AddImgContent").append(inputImg.replace(/Empty/g,inputName));
        }
        function RemoveImg(e) {
            $(e).parent().remove();
        }
        function GenBigPic() {
            var imgs="";
            $("input[rel='BigPicItem']").each(function(){
                imgs+=$(this).val()+"|";
            });
            $("#BigPic").val(imgs);
        }
	</script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    编辑产品
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <%= Html.ActionLink("返回列表","ProductList") %></div>
    <hr />
    <% using (Html.BeginForm("ProductEdit", "Admin", FormMethod.Post, new { onsubmit="return GenBigPic();" }))
       {%>
    <div>
        <%--产品名称--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.ProductName)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.ProductName)%> <%= Html.DisplayToolTipFor(model => model.ProductName)%> <%= Html.ValidationMessageFor(model => model.ProductName)%></span>
		<%--发布--%>
        <span><%= Html.LabelFor(model => model.ViewFlag)%>：<%= Html.CheckBoxFor(model => model.ViewFlag)%>
            <%= Html.DisplayToolTipFor(model => model.ViewFlag)%></span></div>
	<div style = "display: none">
		<%--品牌--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.ProductBrandsID)%>：</span>
        <span class="editor-field"><%= Html.DropDownListFor(model => model.ProductBrandsID, new SelectList(new ProductBrandsService().GetAll().Select(m => new { m.BrandName, m.ID }), "ID", "BrandName", Model.ProductBrandsID))%> <%= Html.DisplayToolTipFor(model => model.ProductBrandsID)%> <%= Html.ValidationMessageFor(model => model.ProductBrandsID)%></span>
	</div>
    <div>
        <%--所属类别ID--%>
        <span class="editor-field"><%= Html.HiddenFor(model => model.SortID, new { value = 0 })%> <%= Html.DisplayToolTipFor(model => model.SortID)%> <%= Html.ValidationMessageFor(model => model.SortID)%></span></div>
    <div>
        <%--类别路径--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.SortPath)%>：</span>
        <span class="editor-field"><%= Html.DropDownListFor(model => model.SortPath, new SelectList(new CategoryService<DataSet1.ProductSortRow, DataSet1.ValidationProductSort>(new ProductSortService()).CategoryList(0), "SortPath", "SortName"))%> <%= Html.DisplayToolTipFor(model => model.SortPath)%> <%= Html.ValidationMessageFor(model => model.SortPath)%></span></div>
    <div>
        <%--产品编号--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.ProductNo)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.ProductNo)%> <%= Html.DisplayToolTipFor(model => model.ProductNo)%> <%= Html.ValidationMessageFor(model => model.ProductNo)%></span></div>
    <div>
        <%--产品型号--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.ProductModel)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.ProductModel)%> <%= Html.DisplayToolTipFor(model => model.ProductModel)%> <%= Html.ValidationMessageFor(model => model.ProductModel)%></span></div>
    <div>
        <%--产品价格--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.Price)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.Price)%> <%= Html.DisplayToolTipFor(model => model.Price)%> <%= Html.ValidationMessageFor(model => model.Price)%></span></div>
	<div>
        <%--推荐--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.CommendFlag)%>：</span>
        <span class="editor-field"><%= Html.CheckBoxFor(model => model.CommendFlag)%> <%= Html.DisplayToolTipFor(model => model.CommendFlag)%> <%= Html.ValidationMessageFor(model => model.CommendFlag)%></span>
	</div>
	<div>
        <%--特价--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.SpecialsFlag)%>：</span>
        <span class="editor-field"><%= Html.CheckBoxFor(model => model.SpecialsFlag)%> <%= Html.DisplayToolTipFor(model => model.SpecialsFlag)%> <%= Html.ValidationMessageFor(model => model.SpecialsFlag)%></span>
	</div>
    <div>
        <%--会员组别--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.GroupID)%>：</span>
        <span class="editor-field"><%= Html.DropDownListFor(model => model.GroupID, new SelectList(new MemGroupService().GetAll(), "ID", "GroupName"))%></span><label><%= Html.RadioButtonFor(model => model.Exclusive, ">=")%>隶属</label>
        <label><%= Html.RadioButtonFor(model => model.Exclusive, "=")%>专属</label>
        <%= Html.DisplayToolTip("隶属：权限值≥可查看，专属：权限值＝可查看")%></div>
    <div>
        <%--显示顺序--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.Sequence) %>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.Sequence)%> <%= Html.DisplayToolTipFor(model => model.Sequence) %>
            <%= Html.ValidationMessageFor(model => model.Sequence)%></span>
    </div>
    <div>
        <%--产品主图--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.BigPic)%>：</span>
		<span class="editor-field">
            <%
        var imgs = Model.BigPic.Split('|');
        for (int i = 0; i < imgs.Length; i++)
        {
			if (!string.IsNullOrEmpty(imgs[i]))
            {
                        %>
						<span>
                        <%= Html.TextBoxFileUrlFor(t => imgs[i], "Image", new { rel = "BigPicItem" }).ToString().Replace("imgs[" + i.ToString() + "]", "imgs" + i.ToString()).Replace("imgs_" + i.ToString() + "_", "imgs" + i.ToString())%>
                        <%
        if (i == 0)
        {
                                %>
                                <input type="button" onclick="AddImg(this,Math.random());return false;" value="增加" />
                                <%
        }
        else
        {
                                %>
                                <input type="button" onclick="RemoveImg(this);return false;" value="删除" />
                                <%
        }
                        %>
						<br />
						</span>
                        <%
        }
        }
            %>
            <%
        if (string.IsNullOrEmpty(Model.BigPic.Replace("|", string.Empty).Trim()))
        {
               %>
			   <span>
               <%= Html.TextBoxFileUrlFor(t => string.Empty, "Image", new { rel = "BigPicItem" })%>
               <input type="button" onclick="AddImg(this,Math.random());return false;" value="增加" />
			   <br />
			   </span>
               <%
        }
        Response.Write(Html.HiddenFor(model => model.BigPic));
            %>
			<span id="AddImgContent"></span>
            <%= Html.DisplayToolTipFor(model => model.BigPic)%> <%= Html.ValidationMessageFor(model => model.BigPic)%>
		</span>
    </div>
    <div>
        <%--产品略图--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.SmallPic)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFileUrlFor(model => model.SmallPic)%> <%= Html.DisplayToolTipFor(model => model.SmallPic)%> <%= Html.ValidationMessageFor(model => model.SmallPic)%></span>
	</div>
	<div id="SelectThumb"></div>
    <div>
        <%--添加时间--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.AddTime)%>：</span>
        <span class="editor-field"><%= Html.TextBoxCalendarFor(model => model.AddTime, new { style = "width:140px" })%> <%= Html.DisplayToolTipFor(model => model.AddTime)%> <%= Html.ValidationMessageFor(model => model.AddTime)%></span></div>
    <div>
        <%--点击次数--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.ClickNumber)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.ClickNumber, new { value = 0 })%> <%= Html.DisplayToolTipFor(model => model.ClickNumber)%> <%= Html.ValidationMessageFor(model => model.ClickNumber)%></span></div>
	<%
		   if (!string.IsNullOrEmpty(Model.CustomFields) && Model.CustomFields.Contains("|ffcms.com|") && Model.CustomFields.Contains(":ffcms.com:"))
		   {
			   var cf = Model.CustomFields.Split(new string[] { "|ffcms.com|" }, StringSplitOptions.RemoveEmptyEntries);
			   foreach (var item in cf)
			   {
				   var field = item.Split(new string[] { ":ffcms.com:" }, StringSplitOptions.None);
			 %>
	<div>
		<span class="editor-label"><label for="<%= field[0] %>"><%= field[0]%></label></span>
		<span class="editor-field"><input type="text" id="<%= field[0] %>" name="<%= field[0] %>" value="<%= field[1] %>" /></span>
	</div>
			<%
			   }
		   }
		   else
		   {
			   var table = CustomFields.Context.XPathSelectElement("/table[@name='" + Model.Table.TableName + "']");
				var fields = table.Elements();
			   foreach (var field in fields)
			   {
				   var fieldName = field.Attribute("name").Value;
				   var defaultvalue = field.Attribute("defaultvalue").Value;
				   %>
	<div>
		<span class="editor-label"><label for="<%= fieldName %>"><%= fieldName %></label></span>
		<span class="editor-field"><input type="text" id="<%= fieldName %>" name="<%= fieldName %>" value="<%= defaultvalue %>" /></span>
	</div>
				   <%
			   }
		   }
	 %>
    <div>
        <%--页面标题--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.PageTitle)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.PageTitle)%> <%= Html.DisplayToolTipFor(model => model.PageTitle)%> <%= Html.ValidationMessageFor(model => model.PageTitle)%></span></div>
    <div>
        <%--页面关键字--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.PageKeywords)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.PageKeywords)%> <%= Html.DisplayToolTipFor(model => model.PageKeywords)%> <%= Html.ValidationMessageFor(model => model.PageKeywords)%></span></div>
    <div>
        <%--页面描述--%>
        <span class="editor-label"><%= Html.LabelFor(model => model.PageDescription)%>：</span>
        <span class="editor-field"><%= Html.TextBoxFor(model => model.PageDescription)%> <%= Html.DisplayToolTipFor(model => model.PageDescription)%> <%= Html.ValidationMessageFor(model => model.PageDescription)%></span></div>
    <div>
        <%--详细内容--%>
        <%= Html.FckEditorFor(model => model.Content)%> <%= Html.ValidationMessageFor(model => model.Content)%></div>
    <div>
        <%----%> <%= Html.HiddenFor(model => model.ID)%></div>
    <p><input type="submit" value="保 存" /> <input type="submit" value="另存为" onclick="$('#ID').val('');" /></p>
    <% } %>
</asp:Content>