<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>资源-Quinn</title>
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/wangedit/css/wang.style.css}"/>
    <link rel="stylesheet" th:href="@{/css/backgroud.css}">
    <style>
        input[type="file"] {
            　　width: 100%;
            　　height: 100%;
            　　opacity: 0;
            　　position: absolute;
            　　top: 0;
            　　left: 0;
        }
    </style>

</head>
<body>
<main role="main" class="container mt-3 p-3 bg-white rounded">
    <div class="row">
        <div class="col-md-12 blog-main">
            <div class="col-md-12 order-md-1">
                <h4 class="mb-3">发布新资源</h4>
                <form class="needs-validation" th:action="@{/source/oper}" enctype="multipart/form-data" method="post">
                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="title">资源标题</label>
                            <input type="text" name="title" class="form-control" id="title" value="" required>
                        </div>

                        <div class="form-group col-md-8">
                            <label for="enName">英文名</label>
                            <input type="text" name="enName" class="form-control" id="enName" value="" required>
                        </div>

                        <div class="form-group col-md-4">
                            <label for="sType">资源标签</label>
                            <select name="categoryId" class="custom-select d-block w-100" id="sType">
                                <option th:each="category:${categoryList}"
                                        th:value="${category.getId()}" th:text="${category.getCategory()}">
                                </option>
                            </select>
                        </div>

                        <div class="form-group col-md-12">
                            <label for="subContent">简介</label>
                            <textarea name="subContent" class="form-control" id="subContent" required></textarea>
                        </div>

                        <div class="form-group col-md-6">
                            <label for="sourceType">下载方式</label>
                            <select name="sourceType" class="custom-select d-block w-100" id="sourceType" required>
                                <option value="">请选择...</option>
                                <option value="BAIDU">百度云</option>
                                <option value="OSS" >服务器<span class="badge badge-pill badge-danger">(这个程序员还很穷!文件请不要大于20M)</span></option>
                            </select>
                        </div>

                        <div id="baiduSourceTypeDiv" style="display: none" class="form-group col-md-6">
                            <label for="sourceLink">百度云URL</label>
                            <input type="text" name="sourceLink" class="form-control" id="sourceLink" />
                        </div>

                        <div id="uploadData" style="display: none" class="form-group col-md-12">
                            <input type="file" id="toUploadFile" class="alert alert-dark" name="file" />
                        </div>

                        <div class="col-md-12 mb-3">
                            <hr/>
                            <div id="blog-content">
                                <div id="editor-toolbar"></div>
                                <div id="editor-text-area" style="height: 600px;border: 1px solid lightgrey"></div>
                                <textarea id="content-textarea" name="content" style="display: none;"></textarea>
                                <textarea id="contentText-textarea" name="contentJson" style="display: none;"></textarea>
                            </div>
                        </div>
                    </div>
                    <button class="btn btn-primary btn-lg btn-block" type="submit" onclick="this.disabled=true; this.form.submit();">发布资源</button>
                </form>
            </div>
        </div>
    </div>
</main>

<a class="to-top badge badge-light">返回顶部</a>
<script th:src="@{/js/jquery-3.5.1.min.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap.bundle.min.js}"></script>
<script th:src="@{/js/toTop.js}"></script>
<script th:src="@{/js/jquery-ui.min.js}"></script>
<script th:src="@{/live/js/addlive2d.js}"></script>

<script th:src="@{/wangedit/js/wang.min.js}"></script>
<script th:src="@{/wangedit/js/wang.init.js}"></script>
<script th:src="@{/layer/mobile/layer.js}"></script>
<script type="text/javascript">
    $("#sourceType").change(function(){
        const jSourceType = $('#sourceType').val();
        if (jSourceType == 'BAIDU') {
            $("#uploadData").hide();
            $("#baiduSourceTypeDiv").show();
        }
        if (jSourceType == 'OSS') {
            $("#baiduSourceTypeDiv").hide();
            $("#uploadData").show();
        }
        if (jSourceType != 'OSS' && jSourceType != 'BAIDU'){
            $("#baiduSourceTypeDiv").hide();
            $("#uploadData").hide();
        }
    });
</script>


</body>
</html>
