{template "header.html"}


<link href="{THEME_PATH}assets/global/plugins/codemirror/lib/codemirror.css" rel="stylesheet" type="text/css" />
<link href="{THEME_PATH}assets/global/plugins/codemirror/theme/neat.css" rel="stylesheet" type="text/css" />

<script src="{THEME_PATH}assets/global/plugins/codemirror/lib/codemirror.js" type="text/javascript"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/{$file_js}" type="text/javascript"></script>

<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/xml/xml.js" type="text/javascript"></script>


<script type="text/javascript">
    jQuery(document).ready(function() {
        var myTextArea = document.getElementById('file_code');
        var myCodeMirror = CodeMirror.fromTextArea(myTextArea, {
            lineNumbers: true,
            matchBrackets: true,
            styleActiveLine: true,
            theme: "neat",
            mode: '{$file_ext}'
        });
        $('#my_submit').click(function () {

            url = '{dr_now_url()}';

            var loading = layer.load(2, {
                shade: [0.3,'#fff'], //0.1透明度的白色背景
                time: 1000
            });

            $("#html_result").html(' ... ');

            $.ajax({
                type: "POST",
                dataType: "json",
                url: url,
                data: {cname:$("#cname").val(), code: myCodeMirror.getValue(), {csrf_token()}: "{csrf_hash()}"},
                success: function(json) {
                    layer.close(loading);
                    if (json.code == 1) {
                        dr_tips(1, json.msg);
                        setTimeout("window.location.reload(true)", 2000)
                    } else {
                        dr_tips(0, '{dr_lang('模板语法解析错误')}');
                        $("#html_result").html('<div class="alert alert-danger">'+json.msg+'</div>');
                    }
                },
                error: function(HttpRequest, ajaxOptions, thrownError) {
                    dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError);
                }
            });
        });
    });

</script>

<div class="note note-danger">
    <p>{dr_safe_replace_path($path)}</p>
</div>

<form action="" class="form-horizontal" method="post" name="myform" id="myform">
    {dr_form_hidden()}
    <div class="row myfbody">
        <div class="col-md-12">

            <div class="portlet light bordered">
                <div class="portlet-title">
                    <div class="caption">
                        <span class="caption-subject font-green">{$name}</span>
                    </div>

                    <div class="actions">
                        {if $backups}
                        <div class="btn-group">
                            <a class="btn green-haze btn-outline btn-circle btn-sm" href="javascript:;" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                {dr_lang('历史文件')}
                                <i class="fa fa-angle-down"></i>
                            </a>
                            <ul class="dropdown-menu pull-right">
                                <li>
                                    <a href="{$backups_url}"> {dr_lang('查看当前文件')}</a>
                                </li>
                                <li class="divider"> </li>
                                {loop $backups $i}
                                <li>
                                    <a href="{$backups_url}&bfile={$i}"> {dr_date($i)}</a>
                                </li>
                                {/loop}
                                <li class="divider"> </li>
                                <li>
                                    <a href="javascript:dr_load_ajax('{dr_lang('确定要删除吗？')}', '{$backups_del}', 1);"> {dr_lang('清空历史文件')}</a>
                                </li>
                            </ul>
                        </div>
                        {/if}
                        <div class="btn-group">
                            <a class="btn" href="{$reply_url}"> <i class="fa fa-mail-reply"></i> {dr_lang('返回列表')}</a>
                        </div>
                    </div>
                </div>
                <div class="portlet-body">
                    <div class="form-body">

                        <div class="form-group">
                            <label class="col-xs-1 control-label ">{dr_lang('文件别名')}</label>
                            <div class="col-xs-3">
                                <input type="text" class="form-control" id="cname" name="cname" value="{htmlspecialchars($cname)}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-1 control-label ">{dr_lang('内容编辑')}</label>
                            <div class="col-xs-10">
                                <textarea id="file_code" name="code">{$code}</textarea>
                            </div>
                        </div>

                        <div class="form-group" style="padding-top:30px">
                            <label class="col-xs-1 control-label "> </label>
                            <div class="col-xs-10"  id="html_result">
                            </div>
                        </div>


                    </div>
                </div>
            </div>



        </div>
    </div>

    <div id=view></div>
    <div class="portlet-body form myfooter">
        <div class="form-actions text-center">
            <button type="button" id="my_submit" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存内容')}</button>
        </div>
    </div>
</form>

{template "footer.html"}