forked from mirrors/bookwyrm
trigger reading status modals from move button
- unhide reading status shelves - trigger modals when moving to a read status shelf - force page refresh when using move button
This commit is contained in:
parent
ec39346e67
commit
9ffe4d340e
8 changed files with 68 additions and 7 deletions
|
@ -90,6 +90,11 @@ let StatusCache = new class {
|
|||
trigger.removeAttribute('disabled');
|
||||
})
|
||||
.then(response => {
|
||||
if (response.headers.get("forceReload")) {
|
||||
BookWyrm.addRemoveClass(form, 'is-processing', true);
|
||||
trigger.setAttribute('disabled', null);
|
||||
return location.reload();
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error();
|
||||
}
|
||||
|
|
|
@ -161,13 +161,9 @@
|
|||
{% for shelf in user_shelfbooks %}
|
||||
<li class="box">
|
||||
{% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}<a href="{{ path }}">{{ shelf_name }}</a>{% endblocktrans %}
|
||||
{% if shelf.shelf.editable %}
|
||||
<div class="mb-3">
|
||||
{% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" %}
|
||||
</div>
|
||||
{% else %}
|
||||
{% include 'snippets/shelve_button/shelve_button.html' %}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -13,6 +13,7 @@ Finish "<em>{{ book_title }}</em>"
|
|||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||
<input type="hidden" name="reading_status" value="read">
|
||||
<input type="hidden" name="shelf" value="{{ move_from }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block reading-dates %}
|
||||
|
|
|
@ -11,6 +11,7 @@ Start "<em>{{ book_title }}</em>"
|
|||
{% block modal-form-open %}
|
||||
<form name="start-reading" action="{% url 'reading-status' 'start' book.id %}" method="post" class="submit-status">
|
||||
<input type="hidden" name="reading_status" value="reading">
|
||||
<input type="hidden" name="shelf" value="{{ move_from }}">
|
||||
{% csrf_token %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ Want to Read "<em>{{ book_title }}</em>"
|
|||
{% block modal-form-open %}
|
||||
<form name="shelve" action="{% url 'reading-status' 'want' book.id %}" method="post" class="submit-status">
|
||||
<input type="hidden" name="reading_status" value="to-read">
|
||||
<input type="hidden" name="shelf" value="{{ move_from }}">
|
||||
{% csrf_token %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{% extends 'components/dropdown.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block dropdown-trigger %}
|
||||
<span>{% trans "Move book" %}</span>
|
||||
|
@ -8,7 +9,16 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block dropdown-list %}
|
||||
{% with book.id|uuid as uuid %}
|
||||
{% active_shelf book as active_shelf %}
|
||||
{% for shelf in user_shelves %}
|
||||
<!-- TODO:
|
||||
#1 work out logic to both trigger the relevant modal for reading status ✅
|
||||
#2 AND REMOVE FROM CURRENT SHELF ✅
|
||||
#3 AND TRIGGER RELOAD even when readthrough shelf ✅
|
||||
|
||||
#4 disable if book is shelved on this shelf
|
||||
-->
|
||||
{% if shelf.editable %}
|
||||
<li role="menuitem" class="dropdown-item p-0">
|
||||
<form name="shelve" action="/shelve/" method="post">
|
||||
|
@ -19,6 +29,31 @@
|
|||
<button class="button is-fullwidth is-small shelf-option is-radiusless is-white" type="submit" {% if shelf.identifier == current.identifier %}disabled{% endif %}><span>{{ shelf.name }}</span></button>
|
||||
</form>
|
||||
</li>
|
||||
{% else%}
|
||||
{% with button_class="is-fullwidth is-small shelf-option is-radiusless is-white" %}
|
||||
<li role="menuitem" class="dropdown-item p-0">
|
||||
{% if shelf.identifier == 'reading' %}
|
||||
|
||||
{% trans "Start reading" as button_text %}
|
||||
{% url 'reading-status' 'start' book.id as fallback_url %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="start_reading" controls_uid=uuid focus="modal_title_start_reading" disabled=is_current fallback_url=fallback_url %}
|
||||
|
||||
|
||||
{% elif shelf.identifier == 'read' %}
|
||||
|
||||
{% trans "Read" as button_text %}
|
||||
{% url 'reading-status' 'finish' book.id as fallback_url %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="finish_reading" controls_uid=uuid focus="modal_title_finish_reading" disabled=is_current fallback_url=fallback_url %}
|
||||
|
||||
{% elif shelf.identifier == 'to-read' %}
|
||||
|
||||
{% trans "Want to read" as button_text %}
|
||||
{% url 'reading-status' 'want' book.id as fallback_url %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="want_to_read" controls_uid=uuid focus="modal_title_want_to_read" disabled=is_current fallback_url=fallback_url %}
|
||||
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<li class="navbar-divider" role="separator"></li>
|
||||
|
@ -30,4 +65,14 @@
|
|||
<button class="button is-fullwidth is-small is-radiusless is-danger is-light" type="submit">{% trans "Remove" %}</button>
|
||||
</form>
|
||||
</li>
|
||||
|
||||
{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book controls_text="want_to_read" controls_uid=uuid move_from=current.id %}
|
||||
|
||||
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book controls_text="start_reading" controls_uid=uuid move_from=current.id %}
|
||||
|
||||
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid move_from=current.id readthrough=readthrough %}
|
||||
|
||||
{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book controls_text="progress_update" controls_uid=uuid move_from=current.id readthrough=readthrough %}
|
||||
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -9,6 +9,7 @@ from django.views import View
|
|||
from django.views.decorators.http import require_POST
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.views.shelf.shelf_actions import unshelve
|
||||
from .status import CreateStatus
|
||||
from .helpers import get_edition, handle_reading_status, is_api_request
|
||||
from .helpers import load_date_in_user_tz_as_utc
|
||||
|
@ -85,12 +86,20 @@ class ReadingStatus(View):
|
|||
if request.POST.get("post-status"):
|
||||
# is it a comment?
|
||||
if request.POST.get("content"):
|
||||
# BUG: there is a problem posting statuses for finishing
|
||||
# check whether it existed before.
|
||||
return CreateStatus.as_view()(request, "comment")
|
||||
privacy = request.POST.get("privacy")
|
||||
handle_reading_status(request.user, desired_shelf, book, privacy)
|
||||
|
||||
if bool(request.POST.get("shelf")):
|
||||
if current_status_shelfbook is None:
|
||||
return unshelve(request, referer=referer, book_id=book_id)
|
||||
return HttpResponse(headers={"forceReload" : "true"})
|
||||
|
||||
if is_api_request(request):
|
||||
return HttpResponse()
|
||||
|
||||
return redirect(referer)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
""" shelf views """
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http.response import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
|
@ -91,13 +92,15 @@ def shelve(request):
|
|||
|
||||
@login_required
|
||||
@require_POST
|
||||
def unshelve(request):
|
||||
def unshelve(request, referer=None, book_id=False):
|
||||
"""remove a book from a user's shelf"""
|
||||
book = get_object_or_404(models.Edition, id=request.POST.get("book"))
|
||||
id = book_id if book_id else request.POST.get("book")
|
||||
book = get_object_or_404(models.Edition, id=id)
|
||||
shelf_book = get_object_or_404(
|
||||
models.ShelfBook, book=book, shelf__id=request.POST["shelf"]
|
||||
)
|
||||
shelf_book.raise_not_deletable(request.user)
|
||||
|
||||
shelf_book.delete()
|
||||
if bool(referer):
|
||||
return HttpResponse(headers={"forceReload" : "true"})
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
|
Loading…
Reference in a new issue