{{extends "/admin/common/base_content"}}

{{block title()}}添加文章 - Doak CMS{{end}}

{{block body()}}

<style>
.form-text {
    color: #b7bbbf;
}
</style>

<div class="container-fluid pt-4 px-4">
    <div class="row g-4">
        <div class="col-sm-12 col-xl-12">
            <div class="bg-light rounded h-100 p-4">
                <h6 class="mb-4">
                    添加文章
                    
                    <a href='{{ adminUrl("art") }}' class="ms-1" title="返回列表">
                        <i class="fa fa-arrow-circle-left"></i>
                    </a>
                </h6>
                
                <form class="profile-form">
                    <div class="mb-3">
                        <label for="cateidSelect" 
                            class="form-label"
                        >
                            所属分类
                        </label>
                        <select class="form-select" 
                            name="cate_id"
                            id="cateidSelect"
                            aria-label="cateidHelp"
                        >
                            {{ range index, value := cates }} 
                                <option value="{{ value.Id }}">{{ value.Name }}</option>
                                
                                {{if len(value.Children) > 0}}
                                    {{ range i2, v2 := value.Children }}
                                        <option value="{{ v2.Id }}">└{{ v2.Name }}</option>
                                    
                                        {{if len(v2.Children) > 0}}
                                            {{ range i3, v3 := v2.Children }}
                                                <option value="{{ v3.Id }}">└{{ v3.Name }}</option>
                                            {{end}}
                                        {{end}}
                                    {{end}}
                                {{end}}
                            {{ end }}
                        </select>
                        <div id="cateidHelp" class="form-text">
                            选择文章对应的分类
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="titleInput" class="form-label">
                            标题
                        </label>
                        <input type="text" 
                            name="title" 
                            value="" 
                            class="form-control" 
                            id="titleInput" 
                            aria-describedby="titleHelp">
                        <div id="titleHelp" class="form-text">
                            文章标题
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">文章状态</label>
                        <div class="form-control">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" 
                                    type="radio" 
                                    name="status" 
                                    checked=""
                                    id="inlineRadioStatus1" 
                                    value="y">
                                <label class="form-check-label" 
                                    for="inlineRadioStatus1">启用</label>
                            </div>
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" 
                                    type="radio" 
                                    name="status" 
                                    id="inlineRadioStatus2" 
                                    value="n">
                                <label class="form-check-label" 
                                    for="inlineRadioStatus2">禁用</label>
                            </div>
                        </div>
                        <div class="form-text">
                            文章是否开启或者关闭
                        </div>
                    </div>
                    
                    <button type="button" 
                        class="btn btn-primary js-save-button"
                    >
                        确认添加
                    </button>
                </form>
            </div>

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

{{end}}

{{block script_after()}}
<script type="3029259e35d7bc1c98cd40a8-text/javascript">
(function($) {
    "use strict";
    
    $(".sidebar-art-index").addClass("active");
    
    // 保存
    $(".js-save-button").click(function(e) {
        e.stopPropagation;
        e.preventDefault;

        var cate_id = $("[name=cate_id]").val();
        var title = $("[name=title]").val();
        var status = $("[name=status]:checked").val();

        var url = '{{ adminUrl("art/add") }}';
        $.post(url, {
            cate_id: cate_id,
            title: title,
            status: status,
        }, function(data) {
            if (data.code == 0) {
                layer.msg("添加成功");
                
                setTimeout(function() {
                    window.location.reload();
                }, 1500);
            } else {
                layer.msg(data.message);
            }
        }).fail(function (xhr, status, info) {
            layer.msg("请求失败");
        });
    });

})(jQuery);
</script>
{{end}}