use one html only

This commit is contained in:
qilinz 2023-07-15 16:39:11 +02:00 committed by Henri Dickson
parent d5e55d8842
commit 4404c44d67
4 changed files with 38 additions and 119 deletions

View file

@ -24,28 +24,41 @@
<ul class="log-list">
{% for log in mark.logs %}
<li>
<span class="log-info">{{ log.timestamp|date }}</span>
<span class="log-info">{{ log.action_label }}</span>
<form id="mark_log_delete_{{ log.id }}"
action="{% url 'journal:mark_log' item.uuid log.id %}"
method="post">
{% csrf_token %}
<span class="log-info">{{ log.timestamp|date }}</span>
<span class="log-info">{{ log.action_label }}</span>
<input type="hidden" name="delete" value="1">
<input type="hidden" name="log_id" id="{{ log.id }}">
{% if editing %}
<a href="javascript:$('#mark_log_delete_{{ log.id }}').submit()"
class="delete">
<i class="fa-solid fa-square-xmark"></i>
</a>
{% endif %}
</form>
</li>
{% endfor %}
</ul>
{% if mark.logs %}
<footer class="log-command">
<span class="action">
<footer class="log-command">
<span class="action">
{% if not editing %}
<a href="{% url 'journal:mark_history_edit' item.uuid %}">{% trans '编辑' %}</a>
</span>
<span class="action">
<form id="mark_delete"
action="{% url 'journal:mark' mark.item.uuid %}"
method="post">
{% csrf_token %}
<input type="hidden" name="delete" value="1">
<input type="hidden" name="silence" value="True">
<a href="#" onclick="deleteLog(event)">清空标记历史</a>
</form>
</span>
</footer>
{% endif %}
{% endif %}
</span>
<span class="action">
<form id="mark_delete"
action="{% url 'journal:mark' mark.item.uuid %}"
method="post">
{% csrf_token %}
<input type="hidden" name="delete" value="1">
<input type="hidden" name="silence" value="True">
<a href="#" onclick="deleteAllLog(event)">清空标记历史</a>
</form>
</span>
</footer>
</article>
{% endif %}
<br>
@ -61,7 +74,7 @@
})
</script>
<script>
function deleteLog(event) {
function deleteAllLog(event) {
event.preventDefault(); // Prevent the default link behavior
const confirmation = confirm('确认清空标记历史?当前标记也会一并删除');

View file

@ -1,82 +0,0 @@
{% load static %}
{% load i18n %}
{% load admin_url %}
{% load mastodon %}
{% load oauth_token %}
{% load truncate %}
{% load thumb %}
<!DOCTYPE html>
<html lang="zh" class="content-page">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {{ item.title }} - {% trans '标记历史' %}</title>
{% include "common_libs.html" with jquery=0 v2=1 %}
<style type="text/css">#id_visibility, #id_visibility li {padding-left:0; margin-bottom:0; display: inline-block !important;}</style>
</head>
<body>
{% include "_header.html" %}
<main>
<div>
<h3>标记历史</h3>
{% if mark.logs %}
<article>
<ul class="log-list">
{% for log in mark.logs %}
<li>
<form id="mark_log_delete_{{ log.id }}"
action="{% url 'journal:mark_log' item.uuid log.id %}"
method="post">
{% csrf_token %}
<span class="log-info">{{ log.timestamp|date }}</span>
<span class="log-info">{{ log.action_label }}</span>
<input type="hidden" name="delete" value="1">
<input type="hidden" name="log_id" id="{{ log.id }}">
<a href="javascript:$('#mark_log_delete_{{ log.id }}').submit()"
class="delete">
<i class="fa-solid fa-square-xmark"></i>
</a>
</form>
</li>
{% endfor %}
</ul>
<footer class="log-command">
<span class="action">
<form id="mark_delete"
action="{% url 'journal:mark' mark.item.uuid %}"
method="post">
{% csrf_token %}
<input type="hidden" name="delete" value="1">
<input type="hidden" name="silence" value="True">
<a href="#" onclick="deleteLog(event)">清空标记历史</a>
</form>
</span>
</footer>
</article>
{% endif %}
<br>
<a href="{% url 'catalog:retrieve' item.url_path item.uuid %}">返回条目</a>
</div>
<aside>
{% include "_sidebar_item.html" with item=item %}
</aside>
</main>
<script>
$(".spoiler").on('click', function(){
$(this).toggleClass('revealed');
})
</script>
<script>
function deleteLog(event) {
event.preventDefault(); // Prevent the default link behavior
const confirmation = confirm('确认清空标记历史?当前标记也会一并删除');
if (confirmation) {
const form = document.getElementById('mark_delete');
form.submit(); // Submit the form
}
}
</script>
{% include "_footer.html" %}
</body>
</html>

View file

@ -24,9 +24,7 @@ urlpatterns = [
path("comment/<str:item_uuid>", comment, name="comment"),
path("mark_log/<str:item_uuid>/<str:log_id>", mark_log, name="mark_log"),
path("mark_history/<str:item_uuid>", mark_history, name="mark_history"),
path(
"mark_history/edit/<str:item_uuid>", mark_history_edit, name="mark_history_edit"
),
path("mark_history/edit/<str:item_uuid>", mark_history, name="mark_history_edit"),
path(
"add_to_collection/<str:item_uuid>", add_to_collection, name="add_to_collection"
),

View file

@ -278,6 +278,10 @@ def mark_log(request, item_uuid, log_id):
def mark_history(request, item_uuid):
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
mark = Mark(request.user, item)
editing = False
if request.path.startswith("/mark_history/edit/"):
editing = True
if request.method == "GET":
return render(
request,
@ -285,21 +289,7 @@ def mark_history(request, item_uuid):
{
"item": item,
"mark": mark,
},
)
@login_required
def mark_history_edit(request, item_uuid):
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
mark = Mark(request.user, item)
if request.method == "GET":
return render(
request,
"mark_history_edit.html",
{
"item": item,
"mark": mark,
"editing": editing,
},
)