<%@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>
		<style type="text/css">
		.current_page{border:solid 1px;padding:0 3px;}
		</style>
		<script type="" src="/js/ajaxfileupload.js"></script>
		<script type="text/javascript">
		function getNewsType(){
			var newsType=$("#newsTypePid").val();
			$.post("findNewsTypeByPid.do",{"newsType":newsType},function(data){
				var obj = document.form.newsType;
				obj.length=0;
				
				if(data != null&&data!=""){	
				$('#newsType').show();
					for(i=0;i<data.length;i++){							
						obj[i]=new Option(data[i].title, data[i].subclassId);
					}
				}else {
				   $('#newsType').hide();
				}
				
			});
		}
		
		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) {  
                    $('#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 method="post" action="updateNews.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="input00" name="title" value="${news.title}"/>
									<input id="newsId" type="hidden" name="newsId" value="${news.newsId}"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="input01">作者</label>
								<div class="controls">
									<input type="text" class="input-xlarge" id="input01" name="author" value="${news.author}"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="input02">关键字</label>
								<div class="controls">
									<input type="text" class="input-xlarge" id="input02" name="keyword" value="${news.keyword}"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="input03">摘要</label>
								<div class="controls">
									<textarea type="text" class="input-xlarge" id="input03" name="summary" style="300px;" cols="60">${news.summary}</textarea>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="uploadPreview">封图</label>
								<div class="controls">
									<input id="thumbnailFile" type="file" value="0" name="thumbnailFile" class="fimg1"/>
									<input id="thumbnail" type="hidden" name="thumbnail" value="${news.thumbnail}"/>
									<img src="${news.thumbnail}" 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" value="1" class="fimg1"/>
									<input id="mthumbnail" type="hidden" name="mthumbnail" value="${news.mthumbnail}"/>
									<img src="${news.mthumbnail}" 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="newsTypePid">类型</label>
								<div class="controls">
								 <select id="newsTypePid" name="newsTypePid" onchange="getNewsType();"> <option value="0">-- 选择类型 --</option> 
									<c:forEach items="${newsType}" var="t">
									<c:if test="${ t.pid == null || t.pid == 0 }">
									  <option value="${t.subclassId}" <c:if test="${pid==t.subclassId}">selected</c:if>>${t.title}</option>
									</c:if>
									</c:forEach>
								</select> 
								<select id="newsType" name="newsType"> <option value="0">-- 选择子分类 --</option> 
									<c:forEach items="${newsType}" var="t">
									<c:if test="${t.pid == pid }">
									  <option value="${t.subclassId}" <c:if test="${news.newsType==t.subclassId}">selected</c:if>>${t.title}</option>
									</c:if>
									</c:forEach>
								</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:600px;height:240px;">${news.content}</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="input04">是否有效</label>
								<div class="controls">
									<input type="checkbox" class="input-xlarge" id="input04" name="status" 
									<c:if test="${news.status==1}">checked</c:if> value="1"
									/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="select01">新闻推荐</label>
								<div class="controls">
									<select id="select01" name="rmd">
										<option value="0"  <c:if test="${news.rmd==0 }">selected</c:if>  >不推荐</option>
										<option value="1"  <c:if test="${news.rmd==1 }">selected</c:if>  >推荐到首页</option>
									</select>
								</div>
							</div>
							<div class="form-actions">
								<button type="submit" class="btn btn-primary">确定</button> 
								<button class="btn" onclick="history.back();">取消</button>
							</div>
						</fieldset>
				</div>
			</div>
		</div>
	</body>
</html>
