<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<!--[if lt IE 7 ]><html lang="en" class="ie6 ielt7 ielt8 ielt9"><![endif]--><!--[if IE 7 ]><html lang="en" class="ie7 ielt8 ielt9"><![endif]--><!--[if IE 8 ]><html lang="en" class="ie8 ielt9"><![endif]--><!--[if IE 9 ]><html lang="en" class="ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> 
<html lang="en"><!--<![endif]--> 
	<head>
		<%@include file="/WEB-INF/navigation/JsAndCss.jsp" %>
    <link href="/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="/umeditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/umeditor/umeditor.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/umeditor/lang/zh-cn/zh-cn.js"></script>
		<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
		<style type="text/css">
		
			#uploadPreview {
    		width: 168px;
   		 	height: 168px;                         
    		background-position: center center;
    		background-size: cover;
    		border: 4px solid #fff;
    		-webkit-box-shadow: 0 0 1px 1px rgba(0, 0, 0, .3);
    		display: inline-block;
		</style>
		<script type="" src="/js/ajaxfileupload.js"></script>
		<script type="text/javascript">		
		function isNull(obj){
			if(obj.value!=null&&obj.value!=""&&obj.value!=undefined){
				return true;
			}else{
				return false;
			}
		}
		
		function checkNull(){
			var flag = true;
			if(!isNull($('#title')[0])){
				alert("标题不能为空");
				flag=false;
			}
			if(flag){
				$('#new-project')[0].submit();
			}
		}
		
			function getNewsType(){
				var newsType=$("#select1").val();
				$.post("findNewsTypeByPid.do",{"newsType":newsType},function(data){
					var obj = document.form.select2;
					obj.length=1;
					if(data != null){	
						for(i=0;i<data.length;i++){							
							obj[i+1]=new Option(data[i].title, data[i].subclassId);
						}
					}
					
				});
			}
			
			function ajaxFileUpload() {  
	            $.ajaxFileUpload  
	        (  
	            {  
	                url: '/imageUp.jsp',  
	                secureuri: false,  
	                fileElementId: 'thumbnailFile',  
	                dataType: 'json',  
	                beforeSend: function() {  
	                    $("#loading").show();  
	                },  
	                complete: function() {  
	                    $("#loading").hide();  
	                },  
	                success: function(data, status) {  
	                	//alert(data.url);
	                    $('#thumbnail').val(data.url);
	                    $('#th').attr('src',"/"+data.url);
	                },  
	                error: function(data, status, e) {  
	                    alert(e);  
	                }  
	            }  
	        )  
	            return false;  
	        }  
			
			function ajaxFileUploads() {  
	            $.ajaxFileUpload  
	        (  
	            {  
	                url: '/mthumbnailImageUp.jsp',  
	                secureuri: false,  
	                fileElementId: 'mthumbnailFile',  
	                dataType: 'json',  
	                beforeSend: function() {  
	                    $("#loading").show();  
	                },  
	                complete: function() {  
	                    $("#loading").hide();  
	                },  
	                success: function(data, status) {  
	                	//alert(data.url);
	                    $('#mthumbnail').val(data.url);
	                    $('#m').attr('src',data.url);
	                },  
	                error: function(data, status, e) {  
	                    alert(e);  
	                }  
	            }  
	        )  
	            return false;  
	        }  
			
			function attachmentUpload() {  
	            $.ajaxFileUpload  
	        (  
	            {  
	                url: '/AttachmentUp.jsp',  
	                secureuri: false,  
	                fileElementId: 'attachmentFile',  
	                dataType: 'json',  
	                beforeSend: function() {  
	                    $("#loading").show();  
	                },  
	                complete: function() {  
	                    $("#loading").hide();  
	                },  
	                success: function(data, status) {  
	                	//alert(data.url);
	                    $('#uri').val("/"+data.url);
	                    $('#orginUri').val(data.physicalPath);
	                    var t = data.originalName;
	                    var title=t.substring(0,t.lastIndexOf("."));
	                    $('#label3').html("\(已上传附件\)");
	                    $('#attachmentTitle').val(title);
                },  
                error: function(data, status, e) {  
                    alert(e);  
                }  
            }  
        );
            return false;  
        }  
		</script>
	</head>
	<body>
		<div class="container">
			<div class="navbar">
				<div class="navbar-inner">
					<%@include file="../navigation/menu.jsp"%>
					</div>
				</div>
			
			<div class="row">
					<%@include file="../navigation/navigation.jsp"%>
				<div class="span9">
					<h1>
						资讯发布
					</h1>
					<form id="new-project" method="post" action="pubNews.do" name="form">
					<fieldset>
							<legend>发布资讯</legend>
							<div class="control-group">
								<label class="control-label" for="input00">资讯标题</label>
								<div class="controls">
									<input type="text" class="input-xlarge" id="title" name="title"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="input01">作者</label>
								<div class="controls">
									<input type="text" class="input-xlarge" id="author" name="author"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="input02">关键字</label>
								<div class="controls">
									<input type="text" class="input-xlarge" id="keyword" name="keyword"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="input02">摘要</label>
								<div class="controls">
									<textarea type="text" class="input-xlarge" id="summary" name="summary"></textarea>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="uploadPreview">封面</label>
								<div class="controls">
									<input id="thumbnailFile" type="file" name="thumbnailFile" class="fimg1"/>
									<input id="thumbnail" type="hidden" name="thumbnail"/>
									<img id="th" style="max-width:100px;"/>
									<button type="button" class="btn btn-primary" onclick="return ajaxFileUpload();">上传图片</button>
								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label" for="uploadPreview">移动端封面</label>
								<div class="controls">
									<input id="mthumbnailFile" type="file" name="mthumbnailFile" class="fimg1"/>
									<input id="mthumbnail" type="hidden" name="mthumbnail"/>
									<img id="m"  style="max-width:100px;"/>
									<button type="button" class="btn btn-primary" onclick="return ajaxFileUploads();">上传图片</button>
								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label" for="uploadPreview">上传附件</label>
								<div class="controls">
									<input id="attachmentFile" type="file" name="attachmentFile" class="fimg1"/>
									<button type="button" class="btn btn-primary" onclick="return attachmentUpload();">上传附件</button>
									<label id="label3"></label>
								</div>
							</div>
							
								<input id="uri" name="uri" type="hidden" />
								<input id="orginUri" name="orginUri" type="hidden" />
								<input id="attachmentTitle" name="attachmentTitle" type="hidden" />
							
							<div class="control-group">
								<label class="control-label" for="select1">父类型</label>
								<div class="controls">
								 <select id="select1" name="select1" onchange="getNewsType()"> <option value="0">-- 选择类型 --</option> 
									<c:forEach items="${newsType}" var="t">
									  <option value="${t.subclassId}">${t.title}</option>
									</c:forEach>
									</select> 
									<select id="select2" name="select2"> <option value="0">-- 选择子类型 --</option> 
									
									</select> 
								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label" for="myEditor">资讯内容</label>
								<div class="controls">
								<script type="text/plain" id="myEditor" style="width:800px;height:240px;"></script>
                                 <div>
                                   <h3 id="focush2"></h3>
                                  </div>
                                 <script type="text/javascript">
                                          //实例化编辑器
                                          var um = UM.getEditor('myEditor');
                                 </script>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="select01">新闻推荐</label>
								<div class="controls">
									<select id="select01" name="rmd">
										<option value="0">不推荐</option>
										<option value="1">推荐到首页</option>
									</select>
								</div>
							</div>
							<div class="form-actions">
								<button class="btn btn-primary" onclick="checkNull();" type="button" >发布</button> 
								<button class="btn" onclick="history.back();" type="reset" >取消</button>
							</div>
						</fieldset>
					</form>
				</div>
			</div>
		</div>
</body>
</html>
