<!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">
                <div class="row mb-4">
                    <h4 class="col-md-11">修改资源</h4>
                    <a th:href="@{'/source/oper/del/'+${source.getSid()}}" class="btn btn-outline-danger col-md-1">删除资源</a>
                </div>
                <form class="needs-validation" th:action="@{/source/oper/update}" enctype="multipart/form-data" method="post">
                    <input type="hidden" id="sid" name="sid" th:value="${source.getSid()}">

                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="title">资源标题</label>
                            <input type="text" name="sourceName" class="form-control" id="title" th:value="${source.getSourceName()}" required>
                        </div>
                        <div class="form-group col-md-8">
                            <label for="enName">英文名</label>
                            <input type="text" name="enName" class="form-control" id="enName" th:value="${source.getEnName()}" 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:selected="${source.getCategoryId() == category.getId()}"
                                        th:value="${category.getId()}" th:text="${category.getCategory()}">
                                </option>
                            </select>
                        </div>

                        <div class="form-group col-md-12">
                            <label for="subContent">简介</label>
                            <textarea name="detail" class="form-control" id="subContent" th:text="${source.getDetail()}" 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 th:selected="${source.getSourceType() != 'OSS'}" value="BAIDU">百度云</option>
                                <option th:selected="${source.getSourceType() == 'OSS'}" value="OSS" >服务器</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" th:value="${source.getSourceType()} == 'OSS' ? '' : ${source.getSourceLink()}" />
                        </div>

                        <div id="uploadData" style="display: none" class="form-group col-md-12">
                            <label for="uploadDataDiv" style="color: darkgreen">注意:如果没有修改文件，则无需重复上传!</label>
                            <input type="file" class="btn" name="file" id="uploadDataDiv" value="选择本地文件" />
                        </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="sourceContent" style="display: none;" th:text="${source.getSourceContent()}"></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>
<div th:replace="~{common/footer::footer}"></div>

<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">
    $(function() {// 初始化内容
        const jSourceType = $('#sourceType').val();
        if (jSourceType == 'OSS') {
            $("#uploadData").show();
        }else {
            $("#baiduSourceTypeDiv").show();
        }
    });

    $("#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>
