<?php /*a:4:{s:80:"E:\phpstudy_pro\WWW\data\hkcms\template\admin\adminlte\appcenter\edit_theme.html";i:1715617489;s:74:"E:\phpstudy_pro\WWW\data\hkcms\template\admin\adminlte\common\default.html";i:1715617489;s:71:"E:\phpstudy_pro\WWW\data\hkcms\template\admin\adminlte\common\meta.html";i:1715617489;s:73:"E:\phpstudy_pro\WWW\data\hkcms\template\admin\adminlte\common\script.html";i:1715617489;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta name="csrf-token" content="<?php echo token(); ?>">

    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="never">
<meta name="renderer" content="webkit">
<title><?php echo $site['title']; ?> - <?php echo lang("Backstage panel"); ?></title>

<link rel="Shortcut Icon" href="<?php echo $site['favicon']; ?>?v=<?php echo env('APP_DEBUG')?time():$site['version']; ?>" type="image/x-icon" />

<!-- Font Awesome 5.13.0 字体图标库 -->
<link rel="stylesheet" href="/static/libs/fontawesome-free/css/all.min.css">
<!-- AdminLTE v3.2.0 | Bootstrap v4.6.0 CSS框架 -->
<link rel="stylesheet" href="/static/module/admin/adminlte/css/adminlte.css?v=<?php echo env('APP_DEBUG')?time():$site['version']; ?>">
<link rel="stylesheet" href="/static/module/admin/adminlte/css/common.css?v=<?php echo env('APP_DEBUG')?time():$site['version']; ?>">

<script type="text/javascript">
    window.Config = <?php echo json_encode($site); ?>;
    window.Lang = <?php echo json_encode($tempLang); ?>;
    window.Tpl = <?php echo json_encode($Tpl); ?>;
</script>

    <style>
        html,body,.wrapper {
            height: 100% !important;
        }
        .content {
            min-height: 100%;
            height: auto;
            padding-bottom: 20px;
            background-color: #f2f3f5;
        }
        .operatePage .card-footer {
            width: 100%;
            position: fixed;
            bottom: 0;
            z-index: 99;
        }
    </style>

    {__STYLE__}

</head>
<body class="sidebar-mini layout-top-nav overlayScrollbars" >

    <?php if(empty($popup)): ?>
    <!-- 子页 -->
    <div class="wrapper">
        <div class="content">
            <div class="container-fluid" style="padding-top: 16px">
                {block:style}
<link rel="stylesheet" href="/static/libs/codemirror/lib/codemirror.css">
<style>
    .operatePage,.card-tabs {
        height: 100%;
    }
    .J-jstree {
        width: 100%;
        height: 100%;
        overflow: hidden;
        overflow-y: auto;
    }
    .table tr th,.table tr td {
        text-align: center;
        vertical-align: middle;
    }
    .jstree-default .jstree-anchor {
        font-size: 13px;
        margin-bottom: 4px;
    }
</style>
{/block:style}

<div class="card card-tabs m-0">
    <div class="card-header">
        <ul class="nav nav-tabs" id="custom-tabs-three-tab" role="tablist">
            <li class="nav-item">
                <a class="nav-link <?php if($type=='tpl' || empty($type)): ?>active<?php endif; ?>" href="<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'tpl','popup'=>1]); ?>"><?php echo __('Template file'); ?></a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?php if($type=='static'): ?>active<?php endif; ?>" href="<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'static','popup'=>1]); ?>"><?php echo __('Static file'); ?></a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?php if($type=='lang'): ?>active<?php endif; ?>" href="<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'lang','popup'=>1]); ?>"><?php echo __('Language'); ?></a>
            </li>
            <?php if(get_addons_config('template',$name,'index')): ?>
            <li class="nav-item">
                <a class="nav-link" href="#!" data-toggle="open" data-title="<?php echo __('Theme configuration'); ?>" data-url="<?php echo url('/appcenter/setConfig',['name'=>$name,'type'=>'template','module'=>'index']); ?>" ><?php echo __('Theme configuration'); ?></a>
            </li>
            <?php endif; ?>
        </ul>
    </div>
    <div class="card-body config-row">
        <div class="tab-content" id="custom-tabs-three-tabContent" style="height: 100%;">
            <?php if($type=='tpl' || $type=='static'): ?>
            <div class="tab-pane fade active show fileman" id="pane-group-tab" role="tabpanel" style="height: 100%;">
                <div class="row" style="height: 100%;overflow:hidden;">
                    <div class="col-md-3" style="height: 100%;">
                        <div><span><i class="fas fa-folder"></i> <?php echo $name; ?></span> <a href="#" class="btn btn-xs btn-primary float-right btn-add"><?php echo __('Create file'); ?></a></div>
                        <div class="J-jstree"></div>
                    </div>
                    <div class="col-md-9" style="height: 100%">
                        <form role="form" action="" class="frm-operate" method="post" style="height: 100%">
                            <input type="hidden" name="name" value="<?php echo $name; ?>">
                            <input type="hidden" name="t" value="<?php echo $type; ?>">
                            <input type="hidden" name="old" value="" id="old">
                            <input type="hidden" name="old_path" value="" id="old_path">
                            <div class="row">
                                <div class="col-sm-5">
                                    <div class="form-group mb-2">
                                        <label for="path"><?php echo __("Directory"); ?>: </label>
                                        <input type="text" class="form-control" id="path" required name="path">
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group mb-2">
                                        <label for="filename"><?php echo __("Filename"); ?>: </label>
                                        <input type="text" class="form-control" id="filename" required name="filename" placeholder="支持html,json,ini后缀的文件">
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="form-group mb-2">
                                        <label for="filename">&nbsp;</label>
                                        <div class="mt-1">
                                            <input type="button" class="btn btn-danger btn-sm btn-delete" value="<?php echo __('Delete'); ?>">
                                            <input type="submit" class="btn btn-primary btn-sm ml-2 btn-savefile" value="<?php echo __('Save'); ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <p class="m-0 text-muted"><?php echo __('Path'); ?>：<span class="real"></span></p>
                            <div class="row" style="height: calc(100% - 100px)">
                                <div class="col-md-12">
                                    <textarea id="textarea1" class="d-none" name="content"><?php echo __('Please click the file list on the left or click the Create File button to create a new file'); ?></textarea>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <?php else: ?>
            <div class="tab-pane fade active show" id="pane-group-tab" role="tabpanel">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom: 20px">
                        <div style="width: 100%;display: flex;align-items: center">
                            <div class="d-flex align-items-center">
                                <label for="lang-list" class="m-0"><?php echo __('language pack'); ?>：</label>
                                <select class="form-control form-control-sm" id="lang-list" style="width: 150px">
                                    <?php if(is_array($langs) || $langs instanceof \think\Collection || $langs instanceof \think\Paginator): $i = 0; $__LIST__ = $langs;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $vo; ?>" <?php if($curLf==$vo): ?>selected<?php endif; ?>><?php echo $vo; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                            <div><a href="#" class="btn btn-primary btn-sm ml-3 btn-save"><?php echo __('Save'); ?></a></div>
                        </div>
                    </div>

                    <div class="col-md-12">
                        <form action="" method="post" class="frm-operate">
                            <table class="table table-bordered table-hover table-striped">
                                <thead>
                                <tr>
                                    <th><?php echo __('Key name'); ?></th>
                                    <th><?php echo __('Value'); ?></th>
                                    <th><?php echo __("Template call"); ?></th>
                                    <th><?php echo __("Operate"); ?></th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php if(is_array($langArr) || $langArr instanceof \think\Collection || $langArr instanceof \think\Paginator): $i = 0; $__LIST__ = $langArr;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                <tr>
                                    <td class="lang-key">
                                        <textarea class="form-control" name="row[]" required><?php echo $key; ?></textarea>
                                    </td>
                                    <td>
                                        <textarea class="form-control" name="row[]" required><?php echo $vo; ?></textarea>
                                    </td>
                                    <td><a href="#" class="btn btn-info btn-copy btn-xs"><?php echo __('Copy'); ?></a></td>
                                    <td>
                                        <input type="button" class="btn btn-danger btn-xs btn-delete-row" value="<?php echo __('Delete'); ?>">
                                    </td>
                                </tr>
                                <?php endforeach; endif; else: echo "" ;endif; ?>
                                </tbody>
                            </table>
                            <p align="center">
                                <a href="#" class="btn btn-info btn-sm btn-add-row"><?php echo __('Append'); ?></a>
                                <a href="#" class="btn btn-primary btn-sm ml-3 btn-save"><?php echo __('Save'); ?></a>
                            </p>
                        </form>
                    </div>
                </div>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

{block:script}
<script>
    require(['admin','jstree','layer','/static/libs/codemirror/lib/codemirror.js','/static/libs/codemirror/mode/htmlmixed/htmlmixed.js'], function (admin, undefined, undefined, CodeMirror) {
        $(function (e) {
            if ($('.fileman').length==1) {
                var editor;
                var curSelect;
                var JstreeNode;
                Util.ajax({
                    url:'<?php echo url("/appcenter/getThemeFiles"); ?>?name=<?php echo $name; ?>&t=<?php echo $type; ?>'
                },'',function (data) {

                    $('.J-jstree').jstree("destroy");
                    $('.J-jstree').jstree({ "core":{"data":data,"multiple":false},"state":{"opened":true}}).on('loaded.jstree', function(e, data){
                        // var inst = data.instance;
                        // inst.select_node(checked);
                    });

                    // 文件选择
                    $('.J-jstree').on('changed.jstree', function (e, data) {
                        isadd = true;
                        var arr = data.instance.get_node(data.selected[0]);
                        if (!arr || arr.data.isdir) { // 跳过目录选择
                            return false;
                        }
                        JstreeNode = data;
                        $('#filename').val(arr.data.org_text);
                        $('#old').val(arr.data.org_text);
                        curSelect = arr;
                        // 拼接目录
                        var pare = arr.parents[0];
                        var parentDir = [];
                        while (pare!='#') {
                            var tmp = data.instance.get_node(pare)
                            parentDir.push(tmp.data.org_text);
                            pare = tmp.parents[0];
                        }
                        parentDir = parentDir ? parentDir.reverse() : parentDir;
                        $('#path').val('/'+parentDir.join('/'));
                        $('#old_path').val('/'+parentDir.join('/'));
                        $('.real').html('<?php echo $template; ?>'+(parentDir.length?parentDir.join('/')+'/':'')+arr.data.org_text);

                        hkcms.api.ajax({
                            type: 'post',
                            url:'<?php echo url("/appcenter/getThemeFiles"); ?>?name=<?php echo $name; ?>&t=<?php echo $type; ?>',
                            data:{fn:arr.data.org_text,dir:parentDir}
                        },'',function (data,res) {
                            editor.toTextArea();
                            $('#textarea1').val(data.content);
                            editor = CodeMirror.fromTextArea(document.getElementById('textarea1'), {
                                lineNumbers: true,
                                mode: 'htmlmixed',
                                lineWrapping: true, //代码折叠
                            });
                            $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                        });
                    });

                    editor = CodeMirror.fromTextArea(document.getElementById('textarea1'), {
                        lineNumbers: true,
                        mode: 'htmlmixed',
                        lineWrapping: true, //代码折叠
                    });
                    $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                });

                $(window).resize(function () {
                    $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                });

                // 新建文件
                var isadd = true;
                $('.btn-add').click(function (e) {
                    editor.toTextArea();
                    $('#textarea1').val('新的文件');
                    editor = CodeMirror.fromTextArea(document.getElementById('textarea1'), {
                        lineNumbers: true,
                        mode: 'htmlmixed',
                        lineWrapping: true, //代码折叠
                    });
                    $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                    $('.J-jstree').jstree('deselect_all');
                    $('#path').val('/');
                    $('#old_path').val('');
                    $('#filename').val('<?php echo $type=="tpl" ? "newfile.html" : "new.js"; ?>');
                    $('#old').val('');
                    $('.real').html('');
                    isadd = false;
                    curSelect = null;
                })

                // 删除文件
                $('.btn-delete').click(function (e) {
                    if (!curSelect) {
                        layer.msg("请选择文件");
                        return false;
                    }
                    layer.confirm("确认删除吗？",{
                        btn: ['<?php echo __("Confirm"); ?>', '<?php echo __("Cancel"); ?>']
                    }, function (index) {
                        // 拼接目录
                        var pare = curSelect.parents[0];
                        var parentDir = [];
                        while (pare!='#') {
                            var tmp = JstreeNode.instance.get_node(pare)
                            parentDir.push(tmp.data.org_text);
                            pare = tmp.parents[0];
                        }
                        parentDir = parentDir ? parentDir.reverse() : parentDir;
                        Util.ajax({
                            type: "post",
                            url: "<?php echo url('/appcenter/delThemeFiles',['t'=>$type,'name'=>$name]); ?>",
                            data: {dir:parentDir,file:curSelect.data.org_text}
                        },'',function (data,res) {
                            layer.msg(res.msg,{time:1000},function () {
                                window.location.reload();
                            })
                        })
                    });
                })

                // 保存文件
                $('.btn-savefile').click(function (e) {
                    if (!curSelect && isadd) {
                        layer.msg("请选择文件");
                        return false;
                    }
                    if ($('#path').val().length==0) {
                        layer.msg("请填写路径");
                        return false;
                    }
                    if ($('#filename').val().length==0) {
                        layer.msg("请填写文件名");
                        return false;
                    }

                    editor.save();
                    Util.ajax({
                        type: "post",
                        url: "<?php echo url('/appcenter/editTheme'); ?>",
                        data: $('.frm-operate').serializeArray()
                    },'',function (data,res) {
                        layer.msg(res.msg,{time:1000},function () {
                            if (!isadd) { // 新增刷新
                                window.location.reload();
                            }
                        })
                    })
                    return false;
                })
            } else {
                // 删除行
                $(document).on('click','.btn-delete-row',function (e) {
                    $(this).parent().parent().remove();
                });
                // 新增行
                $('.btn-add-row').click(function (e) {
                    $('.table tbody').append('<tr>\n' +
                        '     <td class="lang-key">\n' +
                        '         <textarea class="form-control" name="row[]" required></textarea>\n' +
                        '     </td>\n' +
                        '     <td>\n' +
                        '         <textarea class="form-control" name="row[]" required></textarea>\n' +
                        '     </td><td><a href="#" class="btn btn-info btn-copy btn-xs"><?php echo __('Copy'); ?></a></td>\n' +
                        '     <td>\n' +
                        '         <input type="button" class="btn btn-danger btn-xs btn-delete-row" value="<?php echo __('Delete'); ?>">\n' +
                        '     </td>\n' +
                        '</tr>');

                    e.preventDefault();
                });
                // 新建文件
                $('.btn-add').click(function (e) {
                    Util.ajax({
                        type:'post',
                        url:"<?php echo url('/appcenter/addLang',['name'=>$name]); ?>",
                    },'',function (data,res) {
                        layer.msg(res.msg,{time:1000},function () {
                            window.location.reload();
                        })
                    });
                })
                // 保存
                $('.btn-save').click(function (e) {
                    e.preventDefault();
                    Util.ajax({
                        type:'post',
                        url:"<?php echo url('/appcenter/editLang',['name'=>$name]); ?>&file="+$('#lang-list').val(),
                        data:$('.frm-operate').serializeArray()
                    },'',function (data,res) {
                        layer.msg(res.msg,{time:1000},function () {
                            window.location.reload();
                        })
                    });
                })
                // 语言包切换
                $('#lang-list').change(function (e) {
                    window.location.href = "<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'lang','popup'=>1]); ?>&lf="+$(this).val();;
                });
                // 复制
                $(document).on('click','.btn-copy',function (e) {
                    e.preventDefault();
                    layer.alert("<?php echo __('For more label calls, please go to the manual to learn'); ?>：<br/>{"+":__('"+$(this).parent().parent().find('.lang-key textarea').val()+"')}");
                });
            }
        })
    })
</script>
{/block:script}
            </div>
        </div>
    </div>

    <?php else: ?>
    <div class="operatePage">
        {block:style}
<link rel="stylesheet" href="/static/libs/codemirror/lib/codemirror.css">
<style>
    .operatePage,.card-tabs {
        height: 100%;
    }
    .J-jstree {
        width: 100%;
        height: 100%;
        overflow: hidden;
        overflow-y: auto;
    }
    .table tr th,.table tr td {
        text-align: center;
        vertical-align: middle;
    }
    .jstree-default .jstree-anchor {
        font-size: 13px;
        margin-bottom: 4px;
    }
</style>
{/block:style}

<div class="card card-tabs m-0">
    <div class="card-header">
        <ul class="nav nav-tabs" id="custom-tabs-three-tab" role="tablist">
            <li class="nav-item">
                <a class="nav-link <?php if($type=='tpl' || empty($type)): ?>active<?php endif; ?>" href="<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'tpl','popup'=>1]); ?>"><?php echo __('Template file'); ?></a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?php if($type=='static'): ?>active<?php endif; ?>" href="<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'static','popup'=>1]); ?>"><?php echo __('Static file'); ?></a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?php if($type=='lang'): ?>active<?php endif; ?>" href="<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'lang','popup'=>1]); ?>"><?php echo __('Language'); ?></a>
            </li>
            <?php if(get_addons_config('template',$name,'index')): ?>
            <li class="nav-item">
                <a class="nav-link" href="#!" data-toggle="open" data-title="<?php echo __('Theme configuration'); ?>" data-url="<?php echo url('/appcenter/setConfig',['name'=>$name,'type'=>'template','module'=>'index']); ?>" ><?php echo __('Theme configuration'); ?></a>
            </li>
            <?php endif; ?>
        </ul>
    </div>
    <div class="card-body config-row">
        <div class="tab-content" id="custom-tabs-three-tabContent" style="height: 100%;">
            <?php if($type=='tpl' || $type=='static'): ?>
            <div class="tab-pane fade active show fileman" id="pane-group-tab" role="tabpanel" style="height: 100%;">
                <div class="row" style="height: 100%;overflow:hidden;">
                    <div class="col-md-3" style="height: 100%;">
                        <div><span><i class="fas fa-folder"></i> <?php echo $name; ?></span> <a href="#" class="btn btn-xs btn-primary float-right btn-add"><?php echo __('Create file'); ?></a></div>
                        <div class="J-jstree"></div>
                    </div>
                    <div class="col-md-9" style="height: 100%">
                        <form role="form" action="" class="frm-operate" method="post" style="height: 100%">
                            <input type="hidden" name="name" value="<?php echo $name; ?>">
                            <input type="hidden" name="t" value="<?php echo $type; ?>">
                            <input type="hidden" name="old" value="" id="old">
                            <input type="hidden" name="old_path" value="" id="old_path">
                            <div class="row">
                                <div class="col-sm-5">
                                    <div class="form-group mb-2">
                                        <label for="path"><?php echo __("Directory"); ?>: </label>
                                        <input type="text" class="form-control" id="path" required name="path">
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group mb-2">
                                        <label for="filename"><?php echo __("Filename"); ?>: </label>
                                        <input type="text" class="form-control" id="filename" required name="filename" placeholder="支持html,json,ini后缀的文件">
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="form-group mb-2">
                                        <label for="filename">&nbsp;</label>
                                        <div class="mt-1">
                                            <input type="button" class="btn btn-danger btn-sm btn-delete" value="<?php echo __('Delete'); ?>">
                                            <input type="submit" class="btn btn-primary btn-sm ml-2 btn-savefile" value="<?php echo __('Save'); ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <p class="m-0 text-muted"><?php echo __('Path'); ?>：<span class="real"></span></p>
                            <div class="row" style="height: calc(100% - 100px)">
                                <div class="col-md-12">
                                    <textarea id="textarea1" class="d-none" name="content"><?php echo __('Please click the file list on the left or click the Create File button to create a new file'); ?></textarea>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <?php else: ?>
            <div class="tab-pane fade active show" id="pane-group-tab" role="tabpanel">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom: 20px">
                        <div style="width: 100%;display: flex;align-items: center">
                            <div class="d-flex align-items-center">
                                <label for="lang-list" class="m-0"><?php echo __('language pack'); ?>：</label>
                                <select class="form-control form-control-sm" id="lang-list" style="width: 150px">
                                    <?php if(is_array($langs) || $langs instanceof \think\Collection || $langs instanceof \think\Paginator): $i = 0; $__LIST__ = $langs;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $vo; ?>" <?php if($curLf==$vo): ?>selected<?php endif; ?>><?php echo $vo; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                            <div><a href="#" class="btn btn-primary btn-sm ml-3 btn-save"><?php echo __('Save'); ?></a></div>
                        </div>
                    </div>

                    <div class="col-md-12">
                        <form action="" method="post" class="frm-operate">
                            <table class="table table-bordered table-hover table-striped">
                                <thead>
                                <tr>
                                    <th><?php echo __('Key name'); ?></th>
                                    <th><?php echo __('Value'); ?></th>
                                    <th><?php echo __("Template call"); ?></th>
                                    <th><?php echo __("Operate"); ?></th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php if(is_array($langArr) || $langArr instanceof \think\Collection || $langArr instanceof \think\Paginator): $i = 0; $__LIST__ = $langArr;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                <tr>
                                    <td class="lang-key">
                                        <textarea class="form-control" name="row[]" required><?php echo $key; ?></textarea>
                                    </td>
                                    <td>
                                        <textarea class="form-control" name="row[]" required><?php echo $vo; ?></textarea>
                                    </td>
                                    <td><a href="#" class="btn btn-info btn-copy btn-xs"><?php echo __('Copy'); ?></a></td>
                                    <td>
                                        <input type="button" class="btn btn-danger btn-xs btn-delete-row" value="<?php echo __('Delete'); ?>">
                                    </td>
                                </tr>
                                <?php endforeach; endif; else: echo "" ;endif; ?>
                                </tbody>
                            </table>
                            <p align="center">
                                <a href="#" class="btn btn-info btn-sm btn-add-row"><?php echo __('Append'); ?></a>
                                <a href="#" class="btn btn-primary btn-sm ml-3 btn-save"><?php echo __('Save'); ?></a>
                            </p>
                        </form>
                    </div>
                </div>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

{block:script}
<script>
    require(['admin','jstree','layer','/static/libs/codemirror/lib/codemirror.js','/static/libs/codemirror/mode/htmlmixed/htmlmixed.js'], function (admin, undefined, undefined, CodeMirror) {
        $(function (e) {
            if ($('.fileman').length==1) {
                var editor;
                var curSelect;
                var JstreeNode;
                Util.ajax({
                    url:'<?php echo url("/appcenter/getThemeFiles"); ?>?name=<?php echo $name; ?>&t=<?php echo $type; ?>'
                },'',function (data) {

                    $('.J-jstree').jstree("destroy");
                    $('.J-jstree').jstree({ "core":{"data":data,"multiple":false},"state":{"opened":true}}).on('loaded.jstree', function(e, data){
                        // var inst = data.instance;
                        // inst.select_node(checked);
                    });

                    // 文件选择
                    $('.J-jstree').on('changed.jstree', function (e, data) {
                        isadd = true;
                        var arr = data.instance.get_node(data.selected[0]);
                        if (!arr || arr.data.isdir) { // 跳过目录选择
                            return false;
                        }
                        JstreeNode = data;
                        $('#filename').val(arr.data.org_text);
                        $('#old').val(arr.data.org_text);
                        curSelect = arr;
                        // 拼接目录
                        var pare = arr.parents[0];
                        var parentDir = [];
                        while (pare!='#') {
                            var tmp = data.instance.get_node(pare)
                            parentDir.push(tmp.data.org_text);
                            pare = tmp.parents[0];
                        }
                        parentDir = parentDir ? parentDir.reverse() : parentDir;
                        $('#path').val('/'+parentDir.join('/'));
                        $('#old_path').val('/'+parentDir.join('/'));
                        $('.real').html('<?php echo $template; ?>'+(parentDir.length?parentDir.join('/')+'/':'')+arr.data.org_text);

                        hkcms.api.ajax({
                            type: 'post',
                            url:'<?php echo url("/appcenter/getThemeFiles"); ?>?name=<?php echo $name; ?>&t=<?php echo $type; ?>',
                            data:{fn:arr.data.org_text,dir:parentDir}
                        },'',function (data,res) {
                            editor.toTextArea();
                            $('#textarea1').val(data.content);
                            editor = CodeMirror.fromTextArea(document.getElementById('textarea1'), {
                                lineNumbers: true,
                                mode: 'htmlmixed',
                                lineWrapping: true, //代码折叠
                            });
                            $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                        });
                    });

                    editor = CodeMirror.fromTextArea(document.getElementById('textarea1'), {
                        lineNumbers: true,
                        mode: 'htmlmixed',
                        lineWrapping: true, //代码折叠
                    });
                    $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                });

                $(window).resize(function () {
                    $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                });

                // 新建文件
                var isadd = true;
                $('.btn-add').click(function (e) {
                    editor.toTextArea();
                    $('#textarea1').val('新的文件');
                    editor = CodeMirror.fromTextArea(document.getElementById('textarea1'), {
                        lineNumbers: true,
                        mode: 'htmlmixed',
                        lineWrapping: true, //代码折叠
                    });
                    $('.CodeMirror').css('height',$('.frm-operate').height()-90+'px');
                    $('.J-jstree').jstree('deselect_all');
                    $('#path').val('/');
                    $('#old_path').val('');
                    $('#filename').val('<?php echo $type=="tpl" ? "newfile.html" : "new.js"; ?>');
                    $('#old').val('');
                    $('.real').html('');
                    isadd = false;
                    curSelect = null;
                })

                // 删除文件
                $('.btn-delete').click(function (e) {
                    if (!curSelect) {
                        layer.msg("请选择文件");
                        return false;
                    }
                    layer.confirm("确认删除吗？",{
                        btn: ['<?php echo __("Confirm"); ?>', '<?php echo __("Cancel"); ?>']
                    }, function (index) {
                        // 拼接目录
                        var pare = curSelect.parents[0];
                        var parentDir = [];
                        while (pare!='#') {
                            var tmp = JstreeNode.instance.get_node(pare)
                            parentDir.push(tmp.data.org_text);
                            pare = tmp.parents[0];
                        }
                        parentDir = parentDir ? parentDir.reverse() : parentDir;
                        Util.ajax({
                            type: "post",
                            url: "<?php echo url('/appcenter/delThemeFiles',['t'=>$type,'name'=>$name]); ?>",
                            data: {dir:parentDir,file:curSelect.data.org_text}
                        },'',function (data,res) {
                            layer.msg(res.msg,{time:1000},function () {
                                window.location.reload();
                            })
                        })
                    });
                })

                // 保存文件
                $('.btn-savefile').click(function (e) {
                    if (!curSelect && isadd) {
                        layer.msg("请选择文件");
                        return false;
                    }
                    if ($('#path').val().length==0) {
                        layer.msg("请填写路径");
                        return false;
                    }
                    if ($('#filename').val().length==0) {
                        layer.msg("请填写文件名");
                        return false;
                    }

                    editor.save();
                    Util.ajax({
                        type: "post",
                        url: "<?php echo url('/appcenter/editTheme'); ?>",
                        data: $('.frm-operate').serializeArray()
                    },'',function (data,res) {
                        layer.msg(res.msg,{time:1000},function () {
                            if (!isadd) { // 新增刷新
                                window.location.reload();
                            }
                        })
                    })
                    return false;
                })
            } else {
                // 删除行
                $(document).on('click','.btn-delete-row',function (e) {
                    $(this).parent().parent().remove();
                });
                // 新增行
                $('.btn-add-row').click(function (e) {
                    $('.table tbody').append('<tr>\n' +
                        '     <td class="lang-key">\n' +
                        '         <textarea class="form-control" name="row[]" required></textarea>\n' +
                        '     </td>\n' +
                        '     <td>\n' +
                        '         <textarea class="form-control" name="row[]" required></textarea>\n' +
                        '     </td><td><a href="#" class="btn btn-info btn-copy btn-xs"><?php echo __('Copy'); ?></a></td>\n' +
                        '     <td>\n' +
                        '         <input type="button" class="btn btn-danger btn-xs btn-delete-row" value="<?php echo __('Delete'); ?>">\n' +
                        '     </td>\n' +
                        '</tr>');

                    e.preventDefault();
                });
                // 新建文件
                $('.btn-add').click(function (e) {
                    Util.ajax({
                        type:'post',
                        url:"<?php echo url('/appcenter/addLang',['name'=>$name]); ?>",
                    },'',function (data,res) {
                        layer.msg(res.msg,{time:1000},function () {
                            window.location.reload();
                        })
                    });
                })
                // 保存
                $('.btn-save').click(function (e) {
                    e.preventDefault();
                    Util.ajax({
                        type:'post',
                        url:"<?php echo url('/appcenter/editLang',['name'=>$name]); ?>&file="+$('#lang-list').val(),
                        data:$('.frm-operate').serializeArray()
                    },'',function (data,res) {
                        layer.msg(res.msg,{time:1000},function () {
                            window.location.reload();
                        })
                    });
                })
                // 语言包切换
                $('#lang-list').change(function (e) {
                    window.location.href = "<?php echo url('/appcenter/editTheme',['name'=>$name,'t'=>'lang','popup'=>1]); ?>&lf="+$(this).val();;
                });
                // 复制
                $(document).on('click','.btn-copy',function (e) {
                    e.preventDefault();
                    layer.alert("<?php echo __('For more label calls, please go to the manual to learn'); ?>：<br/>{"+":__('"+$(this).parent().parent().find('.lang-key textarea').val()+"')}");
                });
            }
        })
    })
</script>
{/block:script}
    </div>
    <?php endif; ?>

    <script src="/static/libs/require/require.js"></script>
<script src="/static/module/admin/adminlte/js/main.js?v=<?php echo env('APP_DEBUG')?time():$site['version']; ?>"></script>

<!-- // 加载插件JS-->
<?php echo load_js(); ?>



    {__SCRIPT__}
    
</body>
</html>