<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'}">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="assets/js/vendor/codemirror/codemirror.css">
    <link rel="stylesheet" href="assets/js/vendor/codemirror/theme/dracula.css">
    <style>
        .resource-img, .resource-img-path {text-align: center}
        .layui-btn-container .layui-btn {margin-bottom: 0px}
        .layui-table {width: auto;}
    </style>
</head>
<body>
<div class="layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 0">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <textarea id="formXml" name="formXml" style="display: none;"></textarea>
            </form>
        </div>
    </div>
</div>
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
<script src="assets/js/vendor/codemirror/codemirror.js"></script>
<script src="assets/js/vendor/codemirror/mode/xml/xml.js"></script>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$;
        var win = $(window)
        var laytpl = layui.laytpl;
        var processDefinitionId = top.restAjax.params(window.location.href).processDefinitionId;
        var codeMirrorConfig = {
            lineNumbers: true,
            theme: 'dracula',
            matchBrackets: true,
            indentUnit : 4,
            tabSize : 4,
            extraKeys: {
                'Shift-Tab': function (cm) {
                    if (cm.somethingSelected()) {
                        cm.indentSelection('subtract');
                    } else {
                        cm.indentLine(cm.getCursor().line, "subtract");
                    }
                    return;
                },
            }
        };

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        function initFormXml(value) {
            codeMirrorConfig.mode = 'application/xml';
            var editor = CodeMirror.fromTextArea(document.getElementById('formXml'), codeMirrorConfig);
            editor.setValue(value);
            editor.setSize('100%', win.height());
            editor.on('change', function(self, changeValue) {
                $('#formXml').val(self.getValue());
            });
        }

        // 初始化
        function initData() {
            var loadLayerIndex;
            top.restAjax.get(top.restAjax.path('api/activiti/model/get-process-xml/{processDefinitionId}', [processDefinitionId]), {}, null, function(code, data) {
                initFormXml(data.data);
            }, function(code, data) {
                top.dialog.msg(data.msg);
            }, function() {
                loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
            }, function() {
                top.dialog.close(loadLayerIndex);
            });
        }
        initData();

        $('.close').on('click', function() {
            closeBox();
        });
    });
</script>
</body>
</html>