<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="<%= path %>/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="<%= path %>/common/admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="<%= path %>/common/admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="<%= path %>/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<script charset="utf-8" src="<%= path %>/common/other/kingedit/kindeditor.js"></script>
<script charset="utf-8" src="<%= path %>/common/other/kingedit/lang/zh_CN.js"></script> 
<script type="text/javascript">
KindEditor.ready(function(K) {
    window.editor = K.create('#imagetextContext',{
        uploadJson : '<%= path %>/common/other/kingedit/jsp/upload_json.jsp',
		showRemote : false,
        afterBlur: function(){this.sync();},
        width : '450px',
        filterMode:true,
        htmlTags: {
            font : ['color', 'size', 'face', '.background-color'],
            span : [
                    '.color', '.background-color', '.font-size', '.font-family', '.background',
                    '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
            ],
            div : [
                    'align', '.border', '.margin', '.padding', '.text-align', '.color',
                    '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
                    '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
            ],
            table: [
                    'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
                    '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
                    '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
                    '.width', '.height', '.border-collapse'
            ],
            'td,th': [
                    'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
                    '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
                    '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
            ],
            a : ['href', 'target', 'name'],
            embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
            img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
            'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
                    'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
                    '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
            ],
            pre : ['class'],
            hr : ['class', '.page-break-after'],
            'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : []
   	 	},
        allowImageRemote:false,
   	 	pasteType : 2,
   	 	useContextmenu : false, 
   	 	allowFlashUpload : false,
   	 	allowFileUpload : false, 
   	 	allowFileManager : false, 
        items:[
               'undo', 'redo', '|', 'preview', 'cut', 'copy', 'paste',
               'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
               'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
               'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
               'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
               'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image'
               , 'table', 'hr', 'emoticons', 'pagebreak',
               'anchor']
     });
});
</script>	
<!--[if IE 6]>
<script type="text/javascript" src="<%= path %>/common/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>新增新闻</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 官网管理 <span class="c-gray en">&gt;</span> 添加新闻 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
<c:choose>
	<c:when test="${!(empty obj)}">
		<form action="<%= path %>/admin/www/news/update" method="post" class="form form-horizontal" id="form-product-add">
		<input type="hidden" value="${obj.newsId }" name="newsId">
	</c:when>
	<c:otherwise>
		<form action="<%= path %>/admin/www/news/add" method="post" class="form form-horizontal" id="form-product-add">
	</c:otherwise>
</c:choose>
	<form action="<%= path %>/admin/www/news/add" method="post" class="form form-horizontal" id="form-product-add">
		<input type="hidden" value="${token }" name="addNewsToken">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>新闻标题：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="${obj.newsTitle }" errormsg="请输入6-30位的新闻标题!" datatype="s6-30" nullmsg="新闻标题不能为空" placeholder="" id="newsTitle" name="newsTitle">
			</div>
			<div class="col-2"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>新闻简介：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" errormsg="请输入4-100位的新闻简介!" datatype="s4-100" nullmsg="新闻简介不能为空" value="${obj.newsDesc }" placeholder="" id="newsDesc" name="newsDesc">
			</div>
			<div class="col-2"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>作者：</label>
			<div class="formControls col-2">
				<input type="text" class="input-text" datatype="s1-9" errormsg="请输入1-9位的新闻作者!" nullmsg="新闻作者不能为空" value="${obj.newsAuthor }" placeholder="" id="newsAuthor" name="newsAuthor">
			</div>
			<div class="col-2"> </div>
			<label class="form-label col-2"><span class="c-red">*</span>新闻封面图：</label>
			<div class="col-offset-3 col-4">
				<div id="productPicImgDiv" class="uploader-list">
					<c:if test="${!(empty obj)}">
						<span><img style='width:80px;height: 80px;margin-left:10px' src='${obj.newsImage }'/><input type='hidden' id='newsImage-input' name='newsImage' class='user-images-p' value='${obj.newsImage }'></span>
					</c:if>
				</div>
				<div class="ml-10">
					<a id="startUploadPicBtn" href="javascript:;" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 开始上传简介图</a>
				</div>
			</div>
			<div class="col-2"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-2 bulik-label"><span class="c-red">*</span>来源：</label>
			<div class="formControls col-2 bulik-label">
				<input type="text" class="input-text" datatype="s1-9" errormsg="请输入1-9位的新闻来源!" nullmsg="新闻来源不能为空" value="${obj.newsSource }" placeholder="" id="newsSource" name="newsSource">
			</div>
			<label class="form-label col-4 bulik-label"><span class="c-red">*</span>来源链接(没有则填#)：</label>
			<div class="formControls col-2 bulik-label">
				<input type="text" class="input-text" datatype="*1-200" errormsg="请输入1-200位的来源链接!" nullmsg="来源链接不能为空" value="${obj.newsSourceUrl }" placeholder="" id="newsSourceUrl" name="newsSourceUrl">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>新闻内容：</label>
			<div class="formControls col-10">
				<textarea id="imagetextContext" name="newsContexts" class="textarea">${obj.newsContexts }</textarea>
			</div>
			<div class="col-2"> </div>
		</div> 
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button class="btn btn-primary radius" id="butSub" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存并提交新闻信息</button>
				<button class="btn btn-default radius" id="btn_reset" type="button">&nbsp;&nbsp;清空&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="<%= path %>/common/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="<%= path %>/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="<%= path %>/common/admin/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="<%= path %>/common/admin/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="<%= path %>/common/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="<%= path %>/common/admin/js/H-ui.js"></script> 
<script type="text/javascript" src="<%= path %>/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="<%= path %>/common/admin/lib/select2/select2.min.js"></script>
<script type="text/javascript" src="<%= path %>/common/admin/lib/select2/zh-CN.js"></script>
<script type="text/javascript" src="<%= path %>/common/admin/lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript">
var imageLen = 0;
var isRebate = true;
var isBulk = true;
$(function(){
	$("#form-product-add").Validform({
		btnSubmit:"#butSub",
		btnReset:"#btn_reset",
		tiptype:function(msg,o,cssctl){
		    if (o.type == 3) {
				layer.msg(msg,{icon:2,time:1500});
		    }
		},
		ignoreHidden: true,
		beforeSubmit:function(curform){
			
			// 封面图
			var productIntroduceImg = $("#newsImage-input").val();
			if (productIntroduceImg == null || productIntroduceImg == "") {
				layer.msg('请选择新闻封面图!',{icon:2,time:1500});
				return false;
			}
			
			// 新闻内容
			var imagetextContext = $("#imagetextContext").val();
			if (imagetextContext == null || imagetextContext == "") {
				layer.msg('请填写新闻内容!',{icon:2,time:1500});
				return false;
			}
		}
	});
});
addBtnEvent("startUploadPicBtn", "", "productPicImgDiv", "<i class='Hui-iconfont'>&#xe600;</i>更换新闻封面图");
function addBtnEvent(id, handlerId, showDivId, showBtnText){
	KindEditor.ready(function(K) {
		var editor = K.editor({
            uploadJson : '<%= path %>/common/other/kingedit/jsp/upload_json.jsp',
			allowFileManager : false
		});
		K('#'+id).click(function() {
			editor.loadPlugin('image', function() {
				editor.plugin.imageDialog({
					showRemote : false,
					fileUrl : "",
					clickFn : function(url, title) {
						/* if (location.port == "80") {
							url = location.protocol + "//" + location.hostname + url;
						} else {
							url = location.protocol + "//" + location.hostname + ":" + location.port + url;
						} */
						$("#" + handlerId).val(url);
						if (id == "productIntroduceImgBtn") {
							$('#' + showDivId).html("<img style='width:80px;height: 80px;' src='" + url + "'/>");	
						} else {
							imageLen = imageLen + 1;
							$('#' + showDivId).html("<span ><img style='width:80px;height: 80px;margin-left:10px' src='" + url + "'/><input type='hidden' id='newsImage-input' name='newsImage' class='user-images-p' value='" + url + "'></span>");
						}
						$("#" + id).html(showBtnText);
						editor.hideDialog();
					}
				});
			});
		}); 
		
	});
}
</script>
</body>
</html>