<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -->
<!DOCTYPE html>
<html> 
  <head> 
  	 <%@ include file="../../include/lib.jsp" %>
 	 <%@ include file="../../include/editor.jsp"%>
  </head>
     
<body>
	<!-- 添加文章 -->
  	<div id="saveArticle"  title="添加文章" data-options="iconCls:'icon-save'" > 
		<form name="form"  id="contentSave" method="post" action="articleSave">
			<div id="article_left">
		  		<div class="space">文章标题：&nbsp;&nbsp;<input class="easyui-validatebox articletitle" data-options="required:true,missingMessage:'标题不为空',invalidMessage:'标题长度为3-180个字符'" type="text" name="article_title_save" id="article_title_save"/></div>
	   			<div class="smallSpace"></div>
	   			<div>
	   			自定义属性：
	   				<input type="radio" style="width: 22px;" name="articleProperty" value="o" checked="checked">普通[默认]
					<input type="radio" style="width: 27px;" name="articleProperty" value="c">推荐[c]
					<input type="radio" style="width: 27px;" name="articleProperty" value="f">幻灯[f]
	   			</div>
	   			<div class="underContentSpace"></div>
	   			<div class="demo-info" style="background-color: transparent;">
	   				<div class="type">文章栏目：</div>
					<input id="articleType" style="width:252px; _width:270px;" class="easyui-combotree select" data-options="url:'${base_url}/admin/treeArticle?type=json'"/>
				</div>
				<div class="smallSpace"></div>
				<div class="height">
					<ul style="height:23px;">
		    			<li class="name">缩略图：</li>
		    			<li class="select"><input id="fileupload" type="file" name="files[]" data-options="required:true" multiple/></li>
		    		</ul>
	    		</div>
    		</div>
    		
   			<!-- 显示所上传的缩略图 -->
    		<div id="article_right"><img class="img" id="showImage" src=""/><input type="hidden" name="article_img_save" value=""/></div>
    		<div id="files" class="files"></div>
		    		
			<div class="smallSpace2"></div>
   			<div class="content">内容：</div>
   			<div class="underContentSpace"></div>
			<textarea name="articleContentSave" id="articleContentSave"></textarea>
			<div class="space"></div>
			<div class="author">
				<ul>
					 <li class="left"> 作者：<input class="easyui-validatebox title" type="text" name="article_author_save" /></li>
				</ul>
			</div> 
			<div class="space"></div>
			<div class="author">
				<ul>
					  <li class="left"> 来源：<input class="title" style="width: 420px;" type="text" name="artilce_source_save" /></li>
			    </ul>
			</div> 
			
			
			<div class="space"></div>
			<div class="foot">
			 	<div class="button">
			 		<a href="javascript:void(0)" class="easyui-linkbutton l-btn left" onclick="submitArticleSave(this)">确定</a>
			 		<a href="javascript:void(0)" class="easyui-linkbutton l-btn right" onclick="clearForm('#contentSave')">重置</a>
				</div>
			 </div>
			 <input type="hidden" id="articleTypeId" name="articleTypeId">
  		</form> 
  	</div> 
  	
  	<script type="text/javascript">
  		
  		var img;
  		/*点击上传缩略图时请求UploadImgServlet,并将文件保存路径返回*/
		$('#fileupload').fileupload({
			url:BASE_URL+"/uploadImg",
			dataType: 'json',
	    	done: function (e, data) {
	            $("#article_right img").attr("src",BASE_URL+data.result.files.url);
	            $("#article_right input").attr("value",data.result.files.url);
	        }
		});
  	
  		//加载编辑器
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('#articleContentSave', {
					uploadJson : "${base_url}/editor/upload/upload_json.jsp",
					fileManagerJson : "${base_url}/upload/file_manager_json.jsp",
					allowFileManager : true
				});
			});

	
	  	//全局变量 0代表不为封面 1 为封面 2为频道栏目列表
  		var temp = 0;
  		$('#articleType').combotree({
  			onClick: function(){
				//获取文章类型 
				var  art = $('#articleType').combotree('getValue');
				//利用隐藏输入框接收文章类型
				$('#articleTypeId').val(art);
				var articTypeId = $('#articleTypeId').val();
				//获取栏目名称 用于判断是否含有"(封面)","频道列表"等字段
				var n = $('#articleType').combotree('tree');
				var b =n.tree('getSelected');
				var text = b.text;
				if(text.indexOf("(封面)")!=-1){
					temp=1;
					showFormMsg(SYSTEM_TITLE,"此类型为封面模版只存在一篇文章，可以通过栏目管理进行相应的操作!");
				}else if(text.indexOf("(频道栏目列表)")!=-1){
					temp=2;
					showFormMsg(SYSTEM_TITLE,"此类型为频道栏目列表不可以增加文章!");
				}else{
					temp=0;
				}
			}
		});
  	
		//提交按钮 提交form 表单内容   	
  		function submitArticleSave(obj){
				var artTitle = $('#article_title_save').val().replace(/[ ]/g,""); 
				//编辑器内容进行赋值
				$("#articleContentSave").val(editor.html());
				//获取栏目类型名称 去除空格影响 
				var artType = $('#articleTypeId').val().replace(/[ ]/g,"");
				var artContent = $("#articleContentSave").val().replace(/[ ]/g,"");
				if(temp==0){
					if(artTitle==""||artTitle.length>180){
						showFormMsg(SYSTEM_TITLE,"文章标题不为空，且长度在180个字符以内!");
					}else if(artType==""||artType==null){
						showFormMsg(SYSTEM_TITLE,"请先选择文章的类型!");
					}else if(artContent.length<30){
						showFormMsg(SYSTEM_TITLE,"文章内容长度不少于30个字符 !");
					}else{
						$.post("articleSave", $("#contentSave").serialize());
						showMessagerCenter(SYSTEM_TITLE,"文章增加成功,点击文章管理的刷新按钮可见 !");
					}
				}else if(temp==2){
					showFormMsg(SYSTEM_TITLE,"此类型为频道栏目列表不可以增加文章!");
				}else if(temp==1){
					showFormMsg(SYSTEM_TITLE,"此类型为封面模版只存在一篇文章，可以通过栏目管理进行相应的操作!");
				}
		}
			
  	</script>
</body>
</html>
