<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ include file="/common/taglibs.jsp"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<!-- bootstrap 3.0.2 -->
<link href="<c:url value='/styles/lib/bootstrap.min.css'/>" rel="stylesheet" type="text/css" />
<!-- font Awesome -->
<link href="<c:url value='/styles/lib/font-awesome.min.css'/>" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href='<c:url value='/styles/lib/ionicons.min.css' />' rel="stylesheet" type="text/css" />
<!-- DATA TABLES -->
<link href="<c:url value='/styles/lib/datatables/dataTables.bootstrap.css' />" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="<c:url value='/styles/AdminLTE.css'/>" rel="stylesheet" type="text/css" />
<script src="${ctx }/scripts/lib/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="${ctx }/scripts/swfupload-jquery-plugin-master/src/jquery.swfupload.js"></script>
<script type="text/javascript" src="${ctx }/scripts/swfupload-jquery-plugin-master/vendor/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<c:url value='/scripts/kindeditor/kindeditor-min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/kindeditor/lang/zh_CN.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/loading/jquery.blockUI.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/loading/loading.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/My97DatePicker/WdatePicker.js'/>" ></script>
</head>
<script type="text/javascript">
	var editor;
	$(document).ready(function() {
		var resultMsg=$("#resultMsg").val();
		if(resultMsg!=null&&resultMsg!=""){
			alert(resultMsg);
		}
		
		KindEditor.ready(function(K) {
			editor = K.create('textarea[name="noticeContent"]', {
              	uploadJson : "<c:url value='/uploadTemplate/uploadImgFile' />",
              	allowFileManager : true,
				resizeType : 1,
				minWidth:'95%',
				width:'95%',
				height:'340px',
				allowPreviewEmoticons : false,
				items : [
					'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
					'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
					'insertunorderedlist', '|', 'image', 'link','|','fullscreen'],
			});
		});
		
		var id = "pic1";
		$(("#div1")).swfupload({
				upload_url: "<c:url value='/uploadTemplate/upload' />",
				file_size_limit : "10240",
				file_types : "*.jpg;*.png",
				file_post_name: "Filedata",  
				file_types_description : "图片文件",
				file_upload_limit : "0",
				button_text:'上传图片',
				flash_url : "${ctx}/scripts/swfupload-jquery-plugin-master/vendor/swfupload/swfupload.swf",
				button_image_url : '${ctx}/scripts/swfupload-jquery-plugin-master/vendor/swfupload/XPButtonUploadText2_61x22.png',
				button_width : 61,
				button_height : 22,
				button_placeholder : $(("#pic1"))[0],
				debug: false
			}).bind('uploadSuccess', function(event, file, serverData){
				alert("上传成功!");
				$("#div1").show();
				$("#imgs").show();
				$(this).empty();
				$(this).append("<input type='hidden' name='noticePictureUrl' value='"+ ($.parseJSON(serverData).url)+"'/>");
				$(this).append('<img  src="'+($.parseJSON(serverData).preview)+'" width="60px" height="50px">');
		})
		.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
			$(this).swfupload('startUpload');
		})
		.bind('uploadError', function(event, file, errorCode, message){
			alert('上传失败，'+message+errorCode);
		});
	});
	
  	function checkValidate(type){
 	 	var noticeContent = editor.html();
 	 	var organizationId=$("#organizationId").val();
 	 	var introduction=$("#introduction").val();
		if($("#title").val()==""){
			alert("标题不能为空！");
			return false;
		}
		else if(organizationId==""||organizationId==undefined){
			alert("请选择所属高校！");
			return false;
		}
		else if(noticeContent==""){
			alert("内容不能为空！");
			return false;
		}
		else if(introduction==""){
			alert("简介不能为空！");
			$("#introduction").focus();
			return false;
		}
		
		var timerSendTime=$("#timerSendTime").val();
		if(timerSendTime!=""){
			 var d1 = new Date(timerSendTime.replace(/\-/g, "\/"));  
			 var currentDate=new Date();
			 if(d1<currentDate){
				alert("定时群发时间不能小于当前时间！");
				$("#timerSendTime").focus();
				return false;
			 }
		}
		
		if("1"==type){
			$("#isGroupNotifyFlag").val("true");
		}
		
		editor.sync();//将编辑器的内容设置到原来的textarea控件里
		showBlock();
	}
  	
  	//删除图片
  	function deleteImg(id){
  		$("#div1").hide();
  		$("#noticePictureUrl").val('');
  		$.ajax({
			type : 'POST',
			url : '${ctx}'+'/announcement/deleteImg',
			data:{"id":id},
			dataType : 'json',// 返回值类型 一般设置为json
			success : function(data) // 服务器成功响应处理函数
			{
				if(data.code == '0'){
					alert(data.msg);
					$("#imgs").hide();
				}else{
					alert(data.msg);
				}
			}
		});
  	}
</script>
<style>
.td_{text-align:left !important;}
</style>
<body>
<section >
	<input type="hidden" value="${ctx}" id="contextPath">
	<input type="hidden" id="resultMsg" value="${resultMsg }">
	<div class="row">
		<div class="col-xs-12">
			<div class="box" style="margin-top: 5px;">
				<!-- general form elements disabled -->
				<div class="box box-warning">
					<div class="box-body  table-responsive">
						<form action="${ctx}/announcement/form" method="post" enctype="multipart/form-data">
							<input type="hidden" name="annoId" value="${announcement.id }">
							<input type="hidden" name="funcid" value="${funcid}">	
							<input type="hidden" name="actType" value="save">	
							<input type="hidden" name="isGroupNotifyFlag" id="isGroupNotifyFlag" value="false">					
							
							<table class="table table-bordered table-hover">
								<tr>
									<td>微信通知模板<span style="color: red; vertical-align: bottom;">*</span></td>
									<td colspan="3" class="td_">
										<select name="type" style="width: 200px;">
											<c:forEach items="${announcementTypeGroup }" var="obj">
												<c:choose>
													<c:when test="${obj.itemcode==announcement.type }">
													<option value="${obj.itemcode }" selected="selected">${obj.itemname }</option>
													</c:when>
													<c:otherwise>
													<option value="${obj.itemcode }">${obj.itemname }</option>
													</c:otherwise>
												</c:choose>
											</c:forEach>
										</select>
									</td>
								</tr>
								<tr>
									<td>标题<span style="color: red; vertical-align: bottom;">*</span></td>
									<td class="td_">
										<input type="text" id="title" name="title" value="${announcement.title }" style="width:95%" />
									</td>
									<td>通知校区<span style="color: red; vertical-align: bottom;">*</span></td>
									<td class="td_">
										<select name="organizationId" id="organizationId" style="width: 200px;">
											<c:if test="${operateName=='admin' }">
												<option value="0">所有粉丝用户</option>
											</c:if>
											<c:forEach items="${organizationList }" var="obj">
												<c:choose>
													<c:when test="${obj.id==announcement.organizationId }">
													<option value="${obj.id }" selected="selected">${obj.name }</option>
													</c:when>
													<c:otherwise>
													<option value="${obj.id }">${obj.name }</option>
													</c:otherwise>
												</c:choose>
											</c:forEach>
										</select>
									</td>
								</tr>
								<tr>
									<td>地址</td>
									<td class="td_">
										<input type="text" id="address" name="address" value="${announcement.address }" style="width:95%" />
									</td>
									<td>时间</td>
									<td class="td_">
										<input type="text" id="bgTime" name="bgTime" value="${announcement.bgTime }" style="width:95%" />
									</td>
								</tr>
								<tr>
									<td>通知公告简介 <span style="color: red; vertical-align: bottom;">*</span></td>
									<td colspan="3" class="td_">
										<input type="text" id="introduction" name="introduction" value="${announcement.introduction }" style="width:95%" />
									</td>
								</tr>
								<tr>
									<td>通知公告详情<span style="color: red; vertical-align: bottom;">*</span></td>
									<td colspan="3" class="td_">
										<textarea cols="88" rows="3" name="noticeContent" id="noticeContent">${announcement.details}</textarea>
									</td>
								</tr>
								<tr>
									<td>原文链接 </td>
									<td colspan="3" class="td_">
										<input type="text" id="detailUrl" name="detailUrl" value="${announcement.detailUrl }" style="width:95%" />
									</td>
								</tr>
								<tr>
									<td>封面图片</td>
									<td colspan="3" >
										<input type="file" id="pic1" />&nbsp;&nbsp;&nbsp;
										<c:if test="${!empty announcement.coverImageUrl}">
											<input type="button" id="imgs" onclick="deleteImg('${announcement.id}')" value="删除图片" />
										</c:if>
										<div id="div1">
											<c:if test="${!empty announcement.coverImageUrl}">
												<img src="${visitPrefix}${announcement.coverImageUrl}" width="65px" height="60px" />
												<input type="hidden" name="noticePictureUrl" id="noticePictureUrl" value="${announcement.coverImageUrl}" />
											</c:if>
										</div>
										<br>
										<div style="color: red">温馨提示：请上传 800px*600px 的图片。
										推荐使用 <a href="http://se.360.cn/" target="_blank"><sapn style="color:blue">360浏览器</sapn></a> 和
										<a href="http://www.firefox.com.cn/" target="_blank"><span style="color:blue">火狐浏览器</span></a></div>
									</td>
								</tr>
								
								<tr>
									<td>设置定时群发时间 </td>
									<td colspan="3" class="td_">
										<input type="text" name="timerSendTime" id="timerSendTime" value="<fmt:formatDate value='${announcement.timerSendTime}' type='date' pattern='yyyy-MM-dd HH:mm:ss'/>" 
										class="Wdate" onfocus="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
										readonly="true" placeholder="请选择定时群发时间" style="height:26px;width:240px;" />
									</td>
								</tr>
								
								<tr>
									<td colspan="4" align="center">
										<button class="btn btn-primary" onclick="return checkValidate('0');">保存</button>
										<a class="btn btn-back" href="${ctx}/announcement/list?funcid=${funcid}">返回</a>
										<button class="btn btn-primary" style="float:right;" onclick="return checkValidate('1');">保存&群发通知</button>
									</td>
								</tr>
							</table>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>
</body>
</html>