<?xml version="1.0" encoding="UTF-8"?>
<h:screen xmlns:h="http://www.hand-china.com/hap">
    <!--<link href="${base.contextPath}/resources/css/WECHAT/weChatPushNoticce.css" rel="stylesheet" type="text/css"/>-->
    <link href="${base.contextPath}/resources/hls/imgPreview/image-preview.css" rel="stylesheet" type="text/css"/>
    <script src="${base.contextPath}/resources/hls/imgPreview/image-preview.js"></script>
    <link rel="stylesheet" href="styles/kendo.common.min.css"/>
    <link rel="stylesheet" href="styles/kendo.default.min.css"/>
    <link rel="stylesheet" href="styles/kendo.default.mobile.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.all.min.js"></script>

    <style>
        .k-upload {
            position: relative;
            margin-left: -10px;
        }

        #insertPic {
            position: absolute;
            width: 26px;
            height: 26px;
            top: 221px;
            left: 1135px;
            border-color: #ccc;
            border-width: 1px;
            border-style: solid;
            background-color: #FFF;
        }

        #insertPic:hover {
            background-color: transparent;
        }

        #insertPic > img:hover {
            filter: invert(100%);
        }

        #deletePic {
            position: absolute;
            width: 62px;
            height: 32px;
            top: 105px;
            left: 1079px;
            text-align: center;
            line-height: 30px;
            cursor: pointer;
            border-color: #ccc;
            border-width: 1px;
            border-style: solid;
            background-color: #FFF;
        }

        #deletePic:hover {
            background-color: transparent;
        }

        #deletePic > img:hover {
            filter: invert(100%);
        }
    </style>

    <script type="text/x-kendo-template" id="backgroundColor-template">
        <label for='templateTool' style='vertical-align:middle;'>行间距:</label>
        <select id='templateTool' style='width:90px'>
            <option value='100%'>1倍</option>
            <option value='125%'>1.25倍</option>
            <option value='300%'>3倍</option>
            <option value='500%'>5倍</option>
        </select>
    </script>


    <form id="attForm" style="border: none">
        <!-- 定义一些隐藏的input框，用户对信息做一个存储，以便于下面上传的时候获取 -->
        <input type="hidden" id="picUrl2" name="picUrl2"/>

    </form>

    <script id="scriptA"><![CDATA[

    var wxRecoverId = "${RequestParameters.wxRecoverId!'0'}";

    var saveStatus = "update";

    var content = '';

    var picResponse = '';

    var viewModel = kendo.observable({
        editable: getFlag(),
        isEitable: false,
        data: {}
    });

    var currentRole;
    $(document).ready(function () {
        if (currentRole == 'QUERY_ADMIN') {
            $('#save').hide();
            $("#files").hide();
            $("#deletePic").hide();
        }

        if (wxRecoverId != 0 && wxRecoverId != "undefined") {
            $.ajax({
                type: 'POST',
                url: '${base.contextPath}/wx/auto/recover/seq/query',
                data: JSON.stringify({wxRecoverId: wxRecoverId}),
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                async: false,
                success: function (datas) {
                    if (datas.rows.length == 0) {
                        saveStatus = "add";
                    } else {
                        status = "update";
                        viewModel.data.set("content2", datas.rows[0].content);
                        viewModel.data.set("seq", datas.rows[0].seq);
                        viewModel.data.set("content", datas.rows[0].reContent);
                        viewModel.data.set("title", datas.rows[0].title);
                        viewModel.data.set("description", datas.rows[0].description);
                        //content = datas.rows[0].reContent;
                    }
                }
            });
        } else {
            wxRecoverId = null;
            saveStatus = "add";
        }

        //定义文件上传
        $("#files").kendoUpload({
            async: {
                saveUrl: "${base.contextPath}/message/upload/wesite/picture?${_csrf.parameterName}=${_csrf.token}",
            },
            showFileList: true,
            upload: onUpload,
            success: onSuccess
        });

        $("#files").siblings()[0].innerHTML = "选择图片上传";

    });

    function getFlag() {
        var flag = true;
        $.ajax({
            url: '${base.contextPath}/get/roleCode/by/roleId',
            data: {roleId: ${Session.roleId}},
            async: false,
            success: function (json) {
                if (json.success) {
                    for (var i = 0; i < json.total; i++) {
                        if (json.rows[i].roleId == ${Session.roleId}) {
                            currentRole = json.rows[i].roleCode;
                            if (currentRole == 'QUERY_ADMIN') {
                                flag = false;
                            }
                            return false;
                            break;
                        }
                    }
                }
            }
        });
        return flag;
    }

    //回调函数
    function onSuccess(e) {
        kendo.ui.showInfoDialog({
            title: '提示信息',
            message: '上传成功'
        });
        $("#picUrl2").val(e.response);
        picResponse = e.response;
    }

    function onUpload(e) {
        var files = e.files;
        $.each(files, function () {
        });
        e.data = {}
    }

    ]]></script>

    <h:hlsForm title="上传图片">
        <input style="border:none;background: #ffffff" type="file" name="file" id="files"/>
        <div id="uploadPic" style="display: none">
            <input style="border:none; display:none;" type="file" name="file" id="files2"/>
        </div>
    </h:hlsForm>

    <h:hlsForm title="修改内容">
        <h:hlsHBox>
            <h:hlsTextArea id="seq" name="seq"
                           bind="enabled: editable, value:data.seq"
                           style="width:600%;height:30px "
                           promptColspan="1" prompt="序号"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsTextArea id="content2" name="content2"
                           bind="enabled: editable, value:data.content2"
                           style="width:600%;height:30px "
                           promptColspan="1" prompt="关键词"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsTextArea id="title" name="title"
                           bind="enabled: editable, value:data.title"
                           style="width:600%;height:30px "
                           promptColspan="1" prompt="标题"/>
        </h:hlsHBox>
        <!--<h:hlsHBox>
            <span style="position: absolute;top: 250px;left: 74px;">正文</span>
            <div id="content_text" style="margin-left: 112px">
                <textarea id="content" bind="enabled: editable,value:data.content"
                          style="height:350px;width:1040px;"></textarea>

            </div>

        </h:hlsHBox>-->
        <h:hlsHBox>
            <h:hlsTextArea id="content" name="content"
                           bind="enabled: enabled, value:data.content"
                           style="width:600%;margin-bottom:10px;height:150px"
                           promptColspan="1" prompt="正文"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsTextArea id="description" name="description"
                           bind="enabled: enabled, value:data.description"
                           style="width:600%;margin-bottom:20px"
                           promptColspan="1" prompt="描述"/>
        </h:hlsHBox>
        <h:hlsToolBar>
            <h:hlsButton id="save" text="保存"></h:hlsButton>
        </h:hlsToolBar>
    </h:hlsForm>
    <script>
        /*$(function () {
            var str1 = content.replace("&lt;", "");
            str1 = str1.replace("&gt;", "");
            $("#content").siblings(".k-content")[0].contentWindow.document.body.innerHTML = str1;
        })*/
    </script>

    <script>
        /*$(function () {
            var str1 = content.replace("&lt;", "");
            str1 = str1.replace("&gt;", "");
            $("#content").siblings(".k-content")[0].contentWindow.document.body.innerHTML = str1;
        })*/
    </script>

    <script id="scriptB"><![CDATA[

    function g() {

        $("#content").data("kendoEditor").body.style.background = "rgba(255, 255, 255, 0)";
    }

    $("#save").click(function () {
        //var content = $("#content").siblings(".k-content")[0].contentWindow.document.body.innerHTML;
        var content = $("#content").val();
        var content2 = $("#content2").val();
        var seq = $("#seq").val();
        var title = $("#title").val();
        var description = $("#description").val();
        $.ajax({
            url: '${base.contextPath}/wx/auto/recover/submit',
            type: "POST",
            dataType: "json",
            contentType: "application/json",
            data: kendo.stringify([{
                "seq": seq,
                "content": content2,
                "reContent": content,
                "__status": saveStatus,
                "wxRecoverId": wxRecoverId,
                "title": title,
                "description": description,
                "picUrl": picResponse
            }]),
            success: function (args) {
                kendo.ui.showInfoDialog({
                    title: '成功',
                    message: '提交成功!'
                }).done(function (event) {
                    window.parent.$("#" + "${RequestParameters.hlsWindowId!}").data("kendoWindow").close();
                });
            }
        });
    });
    ]]></script>
</h:screen>
