fix(postcard): mark-sent also uses fetch+reload, stays on current page
This commit is contained in:
+3
-3
@@ -919,7 +919,7 @@ async def mark_delivered(
|
||||
|
||||
|
||||
@router.post("/postcards/{postcard_id}/mark-sent")
|
||||
def mark_sent(
|
||||
async def mark_sent(
|
||||
postcard_id: int,
|
||||
user: User = Depends(get_current_user_web),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -932,12 +932,12 @@ def mark_sent(
|
||||
.first()
|
||||
)
|
||||
if not pc:
|
||||
return _redirect("/profiles")
|
||||
return JSONResponse({"ok": False}, status_code=404)
|
||||
pc.status = "sent"
|
||||
if not pc.send_time:
|
||||
pc.send_time = datetime.now()
|
||||
db.commit()
|
||||
return _redirect(f"/postcards/{postcard_id}")
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
# ---------- Image Upload ----------
|
||||
|
||||
@@ -10,9 +10,7 @@
|
||||
<div class="detail-actions">
|
||||
<a href="/postcards/{{ postcard.id }}/edit" class="btn">{{ 'pc_detail.edit'|t(user.language) }}</a>
|
||||
{% if postcard.status == 'pending' %}
|
||||
<form method="post" action="/postcards/{{ postcard.id }}/mark-sent" class="inline">
|
||||
<button type="submit" class="btn btn-primary" onclick="return confirm('{{ 'pc_detail.confirm_sent'|t(user.language) }}')">{{ 'pc_detail.mark_sent'|t(user.language) }}</button>
|
||||
</form>
|
||||
<button type="button" class="btn btn-primary" onclick="if(confirm('{{ 'pc_detail.confirm_sent'|t(user.language) }}'))fetch('/postcards/{{ postcard.id }}/mark-sent',{method:'POST'}).then(function(){location.reload();})">{{ 'pc_detail.mark_sent'|t(user.language) }}</button>
|
||||
{% elif postcard.status == 'sent' %}
|
||||
<button type="button" class="btn btn-primary" onclick="if(confirm('{{ 'pc_detail.confirm_delivered'|t(user.language) }}'))fetch('/postcards/{{ postcard.id }}/mark-delivered',{method:'POST'}).then(function(){location.reload();})">{{ 'pc_detail.mark_delivered'|t(user.language) }}</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -56,9 +56,7 @@
|
||||
{% if pc.notes %}<span class="postcard-row-notes">{{ pc.notes[:50] }}{% if pc.notes|length > 50 %}…{% endif %}</span>{% endif %}
|
||||
<div class="postcard-row-action">
|
||||
{% if pc.status == 'pending' %}
|
||||
<form method="post" action="/postcards/{{ pc.id }}/mark-sent" onclick="event.preventDefault();event.stopPropagation();if(confirm('{{ 'pc_list.confirm_sent'|t(user.language) }}'))this.submit();">
|
||||
<button type="submit" class="btn btn-sm btn-primary">{{ 'pc_list.mark_sent'|t(user.language) }}</button>
|
||||
</form>
|
||||
<button type="button" class="btn btn-sm btn-primary" onclick="event.preventDefault();event.stopPropagation();if(confirm('{{ 'pc_list.confirm_sent'|t(user.language) }}'))fetch('/postcards/{{ pc.id }}/mark-sent',{method:'POST'}).then(function(){location.reload();})">{{ 'pc_list.mark_sent'|t(user.language) }}</button>
|
||||
{% elif pc.status == 'sent' %}
|
||||
<button type="button" class="btn btn-sm btn-primary" onclick="event.preventDefault();event.stopPropagation();if(confirm('{{ 'pc_list.confirm_delivered'|t(user.language) }}'))fetch('/postcards/{{ pc.id }}/mark-delivered',{method:'POST'}).then(function(){location.reload();})">{{ 'pc_list.mark_delivered'|t(user.language) }}</button>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user