<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
<script src="sys/js/jquery.validate.min.js" th:src="@{/static/sys/js/jquery.validate.min.js}"></script>
<script src="sys/js/jquery-validation/messages_zh.js" th:src="@{/static/sys/js/jquery-validation/messages_zh.js}"></script>
<script src="sys/js/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>

<script type="text/javascript" src="https://t.sharingschool.com/dcui/tools/ueditor/ueditor.config.js?version=1811271348"></script>
<script type="text/javascript" src="https://t.sharingschool.com/dcui/tools/ueditor/ueditor.all.min.js?version=1812061808"></script>
<script type="text/javascript" src="https://t.sharingschool.com/dcui/tools/ueditor/lang/zh-cn/zh-cn.js?version=1811271348"></script>

 <style>
    	.clearfix:after {
			visibility: hidden;
			display: block;
			font-size: 0;
			content: " ";
			clear: both;
			height: 0;
		}
		.clearfix { display: inline-table; }
		* html .clearfix { height: 1%; }
		.clearfix { display: block; }
		.fl{display:inline;float:left}
		clearfix >control-label-error{display:inline;float:left;marign-left:10px}
		 label.control-label-error {
  				color: Red;
             }
          .lispan {line-height: 34px;}   
          
          .select1{
   		    width:100%;
		    height: 32px;
		    line-height: 32px;
		    border-top: solid 1px #a7b5bc;
		    border-left: solid 1px #a7b5bc;
		    border-right: solid 1px #ced9df;
		    border-bottom: solid 1px #ced9df;
		    opacity:1;
	        margin-bottom: 10px;
    	}
    	
    	textarea{
    	width: 382px;
    	}
    </style>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
		<li><a href="#">系统管理</a></li>
		<li><a th:href="@{/sys/message/messsageList.html}">系统消息添加</a></li>
	</ul>
</div>
<div class="formbody">
	<div class="formtitle"><span th:text="${ws.id} ? '修改消息' :'新增消息'">新增消息</span></div>
	<form id="submitFrom"   method="post" class="form-horizontal form-validate">
		     <input type="hidden" name="id" th:if="${ws.id}" th:value="${ws.id}"/>
		<ul class="forminfo">
			<li class="clearfix">
				<label>标题：<b>*</b></label>
				<input type="text" id="captions" name="captions" class="dfinput fl" th:value="${ws.captions}">
			</li>
			<li class="clearfix">
				<input type="hidden" name="coverUrl" id="coverUrl" th:value="${ws.coverUrl}"/>
				<label class="upload-file">封面图片：</label>
				<img id="imgImg" th:src=" ${ws.coverUrl} !=null  ? (${ws.coverUrl} !='' ? ${imgUrl}+''+${ws.coverUrl}+'?x-oss-process=image/resize,m_lfit,h_100,w_120' : '' ) :'' "  style="width:200px;height:140px; margin-left: 109px;" />
				<input type="file" id="upfile">
			</li>

			<li class="clearfix">
				<label>推送端：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 346px">
					<!--<select class="select1" name="type">
						<option th:each="sort:${push_terminal}"   th:value="${sort.code}" th:text="${sort.name}"></option>
					</select>-->
					<select class="select1" name="type">
						<option  value="0"  th:selected="${ws.type =='0'}" >全部</option>
						<option  value="1" th:selected="${ws.type=='1'}" >学生端</option>
						<option  value="2" th:selected="${ws.type=='2'}" >家长端</option>
						<option  value="3" th:selected="${ws.type=='3'}" >老师端</option>
						<option  value="4" th:selected="${ws.type=='4'}" >校长端</option>
					</select>
				</div>
			</li>
			<!--<li class="clearfix" >
				<label>发布时间：<b>*</b></label>
				<input type="text" id="publishDate" class="dfinput fl" name="publishDate"
					   th:value="${#calendars.format(ws.publishDate,'yyyy-MM-dd HH:mm:ss')}"
					   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" />

			</li>-->
			<li class="clearfix">
				<label>摘要：<b>*</b></label>
				<input type="text" id="summary" name="summary" class="dfinput fl" th:value="${ws.summary}">
			</li>
            <li class="clearfix">
                <label>内容：</label>
            	<!--<textarea rows="10" id="contents" name="contents" class="textinput" cols="10">[[${ws.contents}]]</textarea>-->
                <!-- 加载编辑器的容器 -->
                <script id="container" name="contents" type="text/plain" style="width:80%;height:300px;margin-left: 100px"></script>
				<div hidden id="contents">[[${ws.contents}]]</div>
			</li>
			<li>
				<label>&nbsp;</label>
				<button type="submit" class="btn">保存</button>
				<button type="button" class="btn" onclick="window.history.go(-1);">取消</button>
			</li>
		</ul>
	</form>
</div>
</body>
<script th:include="sys/common/fileUpload" th:remove="tag"></script> 
<script type="text/javascript">

$(function(){
    var ue = UE.getEditor('container');

    //对编辑器的操作最好在编辑器ready之后再做
    ue.ready(function() {
        //var contents =  "${param.ws.contents}";
        //console.info(document.getElementsById("ws"));
        var contents=$("#contents").text();

        //contents = 'hello';
        //设置编辑器的内容
        ue.setContent(contents);
        //获取html内容，返回: <p>hello</p>
        var html = ue.getContent();
        //获取纯文本内容，返回: hello
        var txt = ue.getContentTxt();
    });
	$("#submitFrom").validate({
		ignore:"",
		rules : {
			captions : {
				required : true,
				maxlength: 100
			},
            type: {
                required : true
			},
            summary : {
                required : true
			}
		},
		messages: {
            captions : {
				required : "标题不能为空",
				maxlength : "最多100个字符"
			},
            type: {
                required : "推送端不能为空"
            },
            summary : {
                required : "摘要不能为空"
            }
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
	
});
function roleFrom(){
	var url="[[${sysUrl}]]/sys/message/messageSave";
	var params = $("#submitFrom").serialize();
	$.post(url,params,function(data){
		if(data != null){
				if(data.meta.success){
					parent.layer.msg("操作成功!",{icon:1});
			    	setTimeout(function(){
			    		window.location.href ='[[${sysUrl}]]/sys/message/messageList.html';
					},1000);
				}else{
					parent.layer.msg(data.meta.message,{icon:11});
				}
		}
		
	});
}

$(function(){
	initUpload(uploadOptions("upfile","上传图片"),"coverUrl","imgImg");
});

//附件上传
function uploadFile(){
	$("#upfile").uploadify("upload", "*");
}

</script>
</html>