<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport"/>
    <title>在线修复</title>
    <script type="text/javascript">
    </script>
</head>
<body>
<div id="wrap">
    <div id="content">
        <div class="wc">
            <link rel="stylesheet" href="/ex_dev_tool/static/lib/codemirror/codemirror.css">
            <script src="/ex_dev_tool/static/lib/codemirror/codemirror.js"></script>
            <script src="/ex_dev_tool/static/lib/codemirror/active-line.js"></script>
            <script src="/ex_dev_tool/static/lib/codemirror/python.js"></script>
            <script src="/ex_dev_tool/static/lib/jquery/jquery.js"></script>


            <style>
                .CodeMirror {
                    height: 90%;
                    border: 1px solid #ddd;
                }

                #result {
                    overflow: hidden;
                    __margin: 30px auto;
                    display: none;
                }

                #output {
                    border: 1px solid #ccc;
                    background: #f6f6f6;
                    padding: 10px;
                }

                .error {
                    color: red;
                    font-size: bold;
                }

                #time {
                    font-size: 12px;
                    color: #999;
                    margin-top: 5px;
                }

                .compiling {
                    background-color: #ccc;
                    border-color: #ccc;
                }

                #loading {
                    text-align: center;
                    font-size: 13px;
                    display: none;
                    line-height: 27px;
                    margin-top: 10px;
                }

            </style>

            <i class="c999">在线修复</i>

            <button id="save" class="btn btn-primary">保存</button>
            <button id="save-restart" class="btn btn-primary">保存并重启</button>

            <label for="validate-code">验证码:</label>
            <input id="validate-code"/>
            <input type="hidden" id="csrf_token" name="csrf_token" value="{{data.csrf_token}}"/>
            <input type="hidden" id="s-name" value="{{data.file_name}}">
            <div style="margin-top:10px;overflow:hidden;">
                <div>
                    <textarea id="code">{{data.content}}</textarea>
                </div>

            </div>

            <script>
                var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
                    lineNumbers: true,
                    styleActiveLine: true,
                    mode: "text/x-python"
                });

                var saveAndRestart = function (code, restart) {
                    $.ajax({
                        url: '/ex/tool/hotfix/save',
                        type: "post",
                        data: {
                            v_code: "python",
                            s_code: code,
                            s_name: $("#s-name").val(),
                            restart: restart,
                            csrf_token: $("#csrf_token").val()
                        },
                        success: function (json) {
                            console.info(json);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.error(textStatus);
                            alert("有错误发生");
                        }
                    });
                }


                $("#save").click(function () {
                    saveAndRestart(editor.getValue(), 0);
                    return false;
                });
                $("#save-restart").click(function () {
                    saveAndRestart(editor.getValue(), 1);
                    return false;
                });
            </script>
        </div>
    </div>

    <div id="footer">

    </div>

</div>
</body>
</html>