




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>诊断报告</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simplemde@1.11.2/dist/simplemde.min.css">
    <script src="https://cdn.jsdelivr.net/npm/simplemde@1.11.2/dist/simplemde.min.js"></script>

</head>
<body>
    {% extends 'admin/base_site.html' %}
    <!-- {% block title %}
    {{ admin_site.site_title }} - {{ user.username }}'s Profile
    {% endblock %} -->

    {% block branding %}
    <h1 id="site-name"><a href="{% url 'admin:index' %}">诊断应用后台</a></h1>
    {% endblock %}
    
    {% block content %}
        <p>{{ obj.user.name }} 的诊断报告，该报告的类型为 {{ obj.diagnose_type }}, 报告生成时间：{{ obj.updated_at }}
            uuid: {{ obj.uuid }}
        </p>
        <button id="save-button" style="margin: 10px 5px;">保存修改</button>
        <div id="editor-container">
            <textarea id="markdown-editor"></textarea>
        </div>
        <script>
            const simplemde = new SimpleMDE({ element: document.getElementById("markdown-editor") });
            simplemde.value(`{{ md_content }}`);  // 将文件内容加载到编辑器中
            document.getElementById("save-button").addEventListener("click", () => {
                const updatedContent = simplemde.value();
                fetch('/diagnose/report_update/{{ report_id }}/', {  // 这里是你的后台 API 路径
                    method: 'POST',
                    body: new URLSearchParams({ 'md_new_content': updatedContent }),
                })
                .then(response => response.json())
                .then(data => {
                    if (data.message) {
                        alert("File saved successfully!");
                    } else {
                        alert("Failed to save content");
                    }
                });
            });
        </script>
    {% endblock %}
</body>
</html>
