<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改通知公告')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-notice-edit" th:object="${tbNotice}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">通知标题：</label>
                <div class="col-sm-8">
                    <input name="noticeTitle" th:field="*{noticeTitle}" class="form-control" type="text" required>
                </div>
            </div>
            <input type="hidden" id="noticeType" th:field="*{noticeType}">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">通知类型：</label>
                <div class="col-sm-8">
                    <select id="noticeType1" class="form-control select2-multiple" required>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">个人的id：</label>
                <div class="col-sm-8">
                    <input name="userId" th:field="*{userId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">通知内容：</label>
                <div class="col-sm-8">
                    <script id="editor" name="noticeContent" type="text/plain" style="height: 300px;"></script>
                    <textarea id="noticeContent" style="display: none;">[[*{noticeContent}]]</textarea>
                </div>
            </div>
            <input type="hidden" th:field="*{status}" id="status">
            <div class="form-group">
                <label class="col-sm-3 control-label">通知状态：</label>
                <div class="col-sm-8">
                    <select id="status1" class="form-control select2-multiple" required>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ueditor-js" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/notice";
        $("#form-notice-edit").validate({
            focusCleanup: true
        });

        $(function () {
            var text = $("#noticeContent").text();
            var ue = UE.getEditor('editor');
            ue.ready(function () {
                ue.setContent(text);
            });
        })

        function getContentTxt() {
            return UE.getEditor('editor').getContentTxt();
        }

        $(document).ready(function() {
            var vSele1=$("#status").val();
            $("#status1").append("<option value='1'>正常</option>");
            $("#status1").append("<option value='2'>关闭</option>");
            $("#status1").find("option").each(function(){
                if($(this).val() == vSele1)	{
                    $(this).attr("selected",true);
                }
            });

            var var2=$("#noticeType").val();
            $("#noticeType1").append("<option value='1'>系统通知</option>");
            $("#noticeType1").append("<option value='2'>个人通知</option>");
            $("#noticeType1").find("option").each(function(){
                if($(this).val() == var2)	{
                    $(this).attr("selected",true);
                }
            });
        });

        $('#status1').on('select2:select', function (e) {
            var a=$('#status1').val();
            $("#status").val(a);
        });

        $('#status1').on('change', function (e) {
            var a=$('#status1').val();
            $("#status").val(a);
        });

        $('#noticeType1').on('select2:select', function (e) {
            var a=$('#noticeType1').val();
            $("#noticeType").val(a);
        });

        $('#noticeType1').on('change', function (e) {
            var a=$('#noticeType1').val();
            $("#noticeType").val(a);
        });

        function submitHandler() {
            if ($.validate.form()) {
                var text = getContentTxt();
                if (text == '' || text.length == 0) {
                    $.modal.alertWarning("请输入通知内容！");
                    return;
                }
                $.operate.save(prefix + "/edit", $('#form-notice-edit').serialize());
            }
        }
    </script>
</body>
</html>