<!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 :: summernote-css"/>
</head>
<body>
<form class="form-horizontal m" id="form-add-notice">
    <input class="form-control required" type="hidden" id="id" th:value="${infoNode.tsHelpinfoId}">
    <div class="col-md-12">
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-9">
                <input class="form-control required" type="text" id="title" th:value="${infoNode.title}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">内容：</label>
            <div class="col-sm-9">
                <div class="ibox float-e-margins">
                    <div class="ibox-content no-padding">
                        <div class="summernote required" id="content"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: summernote-js"/>
<script>
    var prefix = ctx + "system/touchscreen/helpinfo";
    var content = "[[${infoNode.content}]]";
    $(document).ready(function () {
        $('.summernote').summernote({
            lang: 'zh-CN',
            height: 300,
            minHeight: null,
            maxHeight: null,
        });
        $('#content').summernote('code', HTMLDecode(content));
    });
    $("#form-add-notice").validate({
        onkeyup: false,
        rules: {
            title: {
                minlength: 1,
            },
        },
        focusCleanup: true
    });

    function HTMLDecode(text) {
        var temp = document.createElement("div");
        temp.innerHTML = text;
        var output = temp.innerText || temp.textContent;
        temp = null;
        return output;
    }

    function submitHandler() {
        if ($.validate.form()) {
            var title = $('#title').val();
            var content = $('#content').summernote('code');
            var id = $('#id').val();
            if (content.length > 1) {
                var data = $("#form-add-notice").serializeArray();
                data.push({"name": "tsHelpinfoId", "value": id});
                data.push({"name": "title", "value": title});
                data.push({"name": "content", "value": content});
                console.log(content);
                $.operate.save(prefix + "/edit", data);
            } else {
                alert('请填写介绍');
            }
        }
    }
</script>
</body>
</html>
