Merge pull request #1736 from bookwyrm-social/new-modals-bright-futures

Switch old modals to new modals
This commit is contained in:
Mouse Reeve 2022-01-04 13:31:56 -08:00 committed by GitHub
commit e5c5dd8f98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 219 additions and 184 deletions

View file

@ -41,6 +41,7 @@ let BookWyrm = new (class {
document document
.querySelectorAll("[data-duplicate]") .querySelectorAll("[data-duplicate]")
.forEach((node) => node.addEventListener("click", this.duplicateInput.bind(this))); .forEach((node) => node.addEventListener("click", this.duplicateInput.bind(this)));
document document
.querySelectorAll("details.dropdown") .querySelectorAll("details.dropdown")
.forEach((node) => .forEach((node) =>
@ -60,6 +61,9 @@ let BookWyrm = new (class {
.querySelectorAll('input[type="file"]') .querySelectorAll('input[type="file"]')
.forEach(bookwyrm.disableIfTooLarge.bind(bookwyrm)); .forEach(bookwyrm.disableIfTooLarge.bind(bookwyrm));
document.querySelectorAll("[data-copytext]").forEach(bookwyrm.copyText.bind(bookwyrm)); document.querySelectorAll("[data-copytext]").forEach(bookwyrm.copyText.bind(bookwyrm));
document
.querySelectorAll(".modal.is-active")
.forEach(bookwyrm.handleActiveModal.bind(bookwyrm));
}); });
} }
@ -405,7 +409,7 @@ let BookWyrm = new (class {
} }
/** /**
* Handle the modal component. * Handle the modal component with a button trigger.
* *
* @param {Event} event - Event fired by an element * @param {Event} event - Event fired by an element
* with the `data-modal-open` attribute * with the `data-modal-open` attribute
@ -416,6 +420,7 @@ let BookWyrm = new (class {
* for information about using the modal. * for information about using the modal.
*/ */
handleModalButton(event) { handleModalButton(event) {
const { handleFocusTrap } = this;
const modalButton = event.currentTarget; const modalButton = event.currentTarget;
const targetModalId = modalButton.dataset.modalOpen; const targetModalId = modalButton.dataset.modalOpen;
const htmlElement = document.querySelector("html"); const htmlElement = document.querySelector("html");
@ -427,6 +432,8 @@ let BookWyrm = new (class {
// Helper functions // Helper functions
function handleModalOpen(modalElement) { function handleModalOpen(modalElement) {
event.preventDefault();
htmlElement.classList.add("is-clipped"); htmlElement.classList.add("is-clipped");
modalElement.classList.add("is-active"); modalElement.classList.add("is-active");
modalElement.getElementsByClassName("modal-card")[0].focus(); modalElement.getElementsByClassName("modal-card")[0].focus();
@ -455,42 +462,48 @@ let BookWyrm = new (class {
modalButton.focus(); modalButton.focus();
} }
function handleFocusTrap(event) {
if (event.key !== "Tab") {
return;
}
const focusableEls = event.currentTarget.querySelectorAll(
[
"a[href]:not([disabled])",
"button:not([disabled])",
"textarea:not([disabled])",
'input:not([type="hidden"]):not([disabled])',
"select:not([disabled])",
"details:not([disabled])",
'[tabindex]:not([tabindex="-1"]):not([disabled])',
].join(",")
);
const firstFocusableEl = focusableEls[0];
const lastFocusableEl = focusableEls[focusableEls.length - 1];
if (event.shiftKey) {
/* Shift + tab */ if (document.activeElement === firstFocusableEl) {
lastFocusableEl.focus();
event.preventDefault();
}
} /* Tab */ else {
if (document.activeElement === lastFocusableEl) {
firstFocusableEl.focus();
event.preventDefault();
}
}
}
// Open modal // Open modal
handleModalOpen(modal); handleModalOpen(modal);
} }
/**
* Handle the modal component when opened at page load.
*
* @param {Element} modalElement - Active modal element
* @return {undefined}
*
*/
handleActiveModal(modalElement) {
if (!modalElement) {
return;
}
const { handleFocusTrap } = this;
modalElement.getElementsByClassName("modal-card")[0].focus();
const closeButtons = modalElement.querySelectorAll("[data-modal-close]");
closeButtons.forEach((button) => {
button.addEventListener("click", function () {
handleModalClose(modalElement);
});
});
document.addEventListener("keydown", function (event) {
if (event.key === "Escape") {
handleModalClose(modalElement);
}
});
modalElement.addEventListener("keydown", handleFocusTrap);
function handleModalClose(modalElement) {
modalElement.removeEventListener("keydown", handleFocusTrap);
history.back();
}
}
/** /**
* Display pop up window. * Display pop up window.
* *

View file

@ -92,10 +92,11 @@
{% trans "View on OpenLibrary" %} {% trans "View on OpenLibrary" %}
</a> </a>
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
{% with controls_text="ol_sync" controls_uid=author.id %} <button class="button is-small" type="button" data-modal-open="openlibrary_sync">
{% include 'snippets/toggle/toggle_button.html' with text=button_text focus="modal_title_ol_sync" class="is-small" icon_with_text="download" %} <span class="icon icon-download" title="{{ button_text }}"></span>
{% include "author/sync_modal.html" with source="openlibrary.org" source_name="OpenLibrary" %} <span class="is-sr-only-mobile">{{ button_text }}</span>
{% endwith %} </button>
{% include "author/sync_modal.html" with source="openlibrary.org" source_name="OpenLibrary" id="openlibrary_sync" %}
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}
@ -107,10 +108,11 @@
</a> </a>
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
{% with controls_text="iv_sync" controls_uid=author.id %} <button class="button is-small" type="button" data-modal-open="inventaire_sync">
{% include 'snippets/toggle/toggle_button.html' with text=button_text focus="modal_title_iv_sync" class="is-small" icon_with_text="download" %} <span class="icon icon-download" title="{{ button_text }}"></span>
{% include "author/sync_modal.html" with source="inventaire.io" source_name="Inventaire" %} <span class="is-sr-only-mobile">{{ button_text }}</span>
{% endwith %} </button>
{% include "author/sync_modal.html" with source="inventaire.io" source_name="Inventaire" id="inventaire_sync" %}
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}

View file

@ -19,12 +19,8 @@
{% endblock %} {% endblock %}
{% block modal-footer %} {% block modal-footer %}
<button class="button is-primary" type="submit"> <button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
<span>{% trans "Confirm" %}</span> <button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
</button>
{% trans "Cancel" as button_text %}
{% include 'snippets/toggle/toggle_button.html' with text=button_text %}
{% endblock %} {% endblock %}
{% block modal-form-close %}</form>{% endblock %} {% block modal-form-close %}</form>{% endblock %}

View file

@ -63,7 +63,11 @@
<div class="column is-one-fifth"> <div class="column is-one-fifth">
{% if not book.cover %} {% if not book.cover %}
{% if user_authenticated %} {% if user_authenticated %}
<button type="button" data-controls="add_cover_{{ book.id }}" data-focus-target="modal_title_add_cover_{{ book.id }}" aria-pressed="false" class="cover-container no-cover is-h-m-mobile"> <button
type="button"
class="cover-container no-cover is-h-m-mobile"
data-modal-open="add_cover_{{ book.id }}"
>
<img <img
class="book-cover" class="book-cover"
src="{% static "images/no_cover.jpg" %}" src="{% static "images/no_cover.jpg" %}"
@ -78,7 +82,8 @@
{% trans "Click to add cover" %} {% trans "Click to add cover" %}
</span> </span>
</button> </button>
{% include 'book/cover_add_modal.html' with book=book controls_text="add_cover" controls_uid=book.id %} {% join "add_cover" book.id as modal_id %}
{% include 'book/cover_add_modal.html' with id=modal_id %}
{% if request.GET.cover_error %} {% if request.GET.cover_error %}
<p class="help is-danger">{% trans "Failed to load cover" %}</p> <p class="help is-danger">{% trans "Failed to load cover" %}</p>
{% endif %} {% endif %}
@ -117,23 +122,30 @@
{% trans "Load data" as button_text %} {% trans "Load data" as button_text %}
{% if book.openlibrary_key %} {% if book.openlibrary_key %}
<p> <p>
<a href="{{ book.openlibrary_link }}" target="_blank" rel="noopener">{% trans "View on OpenLibrary" %}</a> <a href="{{ book.openlibrary_link }}" target="_blank" rel="noopener">
{% trans "View on OpenLibrary" %}
</a>
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
{% with controls_text="ol_sync" controls_uid=book.id %} <button class="button is-small" type="button" data-modal-open="openlibrary_sync">
{% include 'snippets/toggle/toggle_button.html' with text=button_text focus="modal_title_ol_sync" class="is-small" icon_with_text="download" %} <span class="icon icon-download" title="{{ button_text }}"></span>
{% include "book/sync_modal.html" with source="openlibrary.org" source_name="OpenLibrary" %} <span class="is-sr-only-mobile">{{ button_text }}</span>
{% endwith %} </button>
{% include "book/sync_modal.html" with source="openlibrary.org" source_name="OpenLibrary" id="openlibrary_sync" %}
{% endif %} {% endif %}
</p> </p>
{% endif %} {% endif %}
{% if book.inventaire_id %} {% if book.inventaire_id %}
<p> <p>
<a href="{{ book.inventaire_link }}" target="_blank" rel="noopener">{% trans "View on Inventaire" %}</a> <a href="{{ book.inventaire_link }}" target="_blank" rel="noopener">
{% trans "View on Inventaire" %}
</a>
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
{% with controls_text="iv_sync" controls_uid=book.id %} <button class="button is-small" type="button" data-modal-open="inventaire_sync">
{% include 'snippets/toggle/toggle_button.html' with text=button_text focus="modal_title_iv_sync" class="is-small" icon_with_text="download" %} <span class="icon icon-download" title="{{ button_text }}"></span>
{% include "book/sync_modal.html" with source="inventaire.io" source_name="Inventaire" %} <span class="is-sr-only-mobile">{{ button_text }}</span>
{% endwith %} </button>
{% include "book/sync_modal.html" with source="inventaire.io" source_name="Inventaire" id="inventaire_sync" %}
{% endif %} {% endif %}
</p> </p>
{% endif %} {% endif %}

View file

@ -29,8 +29,7 @@
{% block modal-footer %} {% block modal-footer %}
<button class="button is-primary" type="submit">{% trans "Add" %}</button> <button class="button is-primary" type="submit">{% trans "Add" %}</button>
{% trans "Cancel" as button_text %} <button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
{% include 'snippets/toggle/toggle_button.html' with text=button_text %}
{% endblock %} {% endblock %}
{% block modal-form-close %}</form>{% endblock %}
{% block modal-form-close %}</form>{% endblock %}

View file

@ -2,11 +2,17 @@
{% load i18n %} {% load i18n %}
{% block modal-title %}{% trans "Delete these read dates?" %}{% endblock %} {% block modal-title %}{% trans "Delete these read dates?" %}{% endblock %}
{% block modal-body %} {% block modal-body %}
{% if readthrough.progress_updates|length > 0 %} {% if readthrough.progress_updates|length > 0 %}
{% blocktrans with count=readthrough.progress_updates|length %}You are deleting this readthrough and its {{ count }} associated progress updates.{% endblocktrans %} {% blocktrans trimmed with count=readthrough.progress_updates|length %}
You are deleting this readthrough and its {{ count }} associated progress updates.
{% endblocktrans %}
{% else %}
{% trans "This action cannot be un-done" %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block modal-footer %} {% block modal-footer %}
<form name="delete-readthrough-{{ readthrough.id }}" action="/delete-readthrough" method="POST"> <form name="delete-readthrough-{{ readthrough.id }}" action="/delete-readthrough" method="POST">
{% csrf_token %} {% csrf_token %}
@ -14,7 +20,6 @@
<button class="button is-danger" type="submit"> <button class="button is-danger" type="submit">
{% trans "Delete" %} {% trans "Delete" %}
</button> </button>
{% trans "Cancel" as button_text %} <button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="delete_readthrough" controls_uid=readthrough.id %}
</form> </form>
{% endblock %} {% endblock %}

View file

@ -1,6 +1,7 @@
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}
{% load tz %} {% load tz %}
{% load utilities %}
<div class="content"> <div class="content">
<div id="hide_edit_readthrough_{{ readthrough.id }}" class="box is-shadowless has-background-white-bis"> <div id="hide_edit_readthrough_{{ readthrough.id }}" class="box is-shadowless has-background-white-bis">
<div class="columns"> <div class="columns">
@ -10,14 +11,14 @@
{% if readthrough.finish_date or readthrough.progress %} {% if readthrough.finish_date or readthrough.progress %}
<li> <li>
{% if readthrough.finish_date %} {% if readthrough.finish_date %}
{{ readthrough.finish_date | localtime | naturalday }}: {% trans "finished" %} {{ readthrough.finish_date | localtime | naturalday }}: {% trans "finished" %}
{% else %} {% else %}
{% if readthrough.progress_mode == 'PG' %} {% if readthrough.progress_mode == 'PG' %}
{% include 'snippets/page_text.html' with page=readthrough.progress total_pages=book.pages %} {% include 'snippets/page_text.html' with page=readthrough.progress total_pages=book.pages %}
{% else %} {% else %}
{{ readthrough.progress }}% {{ readthrough.progress }}%
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if readthrough.progress %} {% if readthrough.progress %}
@ -47,6 +48,7 @@
{% endif %} {% endif %}
</li> </li>
{% endif %} {% endif %}
{% if readthrough.start_date %} {% if readthrough.start_date %}
<li>{{ readthrough.start_date | localtime | naturalday }}: {% trans "started" %}</li> <li>{{ readthrough.start_date | localtime | naturalday }}: {% trans "started" %}</li>
{% endif %} {% endif %}
@ -60,7 +62,11 @@
</div> </div>
<div class="control"> <div class="control">
{% trans "Delete these read dates" as button_text %} {% trans "Delete these read dates" as button_text %}
{% include 'snippets/toggle/toggle_button.html' with class="is-small" text=button_text icon="x" controls_text="delete_readthrough" controls_uid=readthrough.id focus="modal_title_delete_readthrough" %} <button class="button is-small" type="button" data-modal-open="delete_readthrough_{{ readthrough.id }}">
<span class="icon icon-x" title="{{ button_text }}">
<span class="is-sr-only">{{ button_text }}</span>
</span>
</button>
</div> </div>
</div> </div>
</div> </div>
@ -79,4 +85,5 @@
</div> </div>
</form> </form>
</div> </div>
{% include 'snippets/delete_readthrough_modal.html' with controls_text="delete_readthrough" controls_uid=readthrough.id no_body=True %} {% join "delete_readthrough" readthrough.id as modal_id %}
{% include 'book/delete_readthrough_modal.html' with id=modal_id %}

View file

@ -19,12 +19,8 @@
{% endblock %} {% endblock %}
{% block modal-footer %} {% block modal-footer %}
<button class="button is-primary" type="submit"> <button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
<span>{% trans "Confirm" %}</span> <button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
</button>
{% trans "Cancel" as button_text %}
{% include 'snippets/toggle/toggle_button.html' with text=button_text %}
{% endblock %} {% endblock %}
{% block modal-form-close %}</form>{% endblock %} {% block modal-form-close %}</form>{% endblock %}

View file

@ -1,40 +1,33 @@
{% load i18n %} {% load i18n %}
<div
role="dialog" <div class="modal {% if active %}is-active{% endif %}" id="{{ id }}">
class="modal {% if active %}is-active{% else %}is-hidden{% endif %}" <div class="modal-background" data-modal-close></div>
id="{{ controls_text }}_{{ controls_uid }}" <div class="modal-card" role="dialog" aria-modal="true" tabindex="-1" aria-described-by="{{ id }}_header">
aria-labelledby="modal_card_title_{{ controls_text }}_{{ controls_uid }}" <header class="modal-card-head">
aria-modal="true" <h2 class="modal-card-title mb-0" id="{{ id }}_header">
>
{# @todo Implement focus traps to prevent tabbing out of the modal. #}
<div class="modal-background"></div>
{% trans "Close" as label %}
<div class="modal-card">
<header class="modal-card-head" tabindex="0" id="modal_title_{{ controls_text }}_{{ controls_uid }}">
<h2 class="modal-card-title is-flex-shrink-1" id="modal_card_title_{{ controls_text }}_{{ controls_uid }}">
{% block modal-title %}{% endblock %} {% block modal-title %}{% endblock %}
</h2> </h2>
{% if static %} <button
<a href="/" class="delete">{{ label }}</a> type="button"
{% else %} class="delete"
{% include 'snippets/toggle/toggle_button.html' with label=label class="delete" nonbutton=True %} aria-label="{% trans 'Close' %}"
{% endif %} data-modal-close
></button>
</header> </header>
{% block modal-form-open %}{% endblock %} {% block modal-form-open %}{% endblock %}
{% if not no_body %}
<section class="modal-card-body"> <section class="modal-card-body">
{% block modal-body %}{% endblock %} {% block modal-body %}{% endblock %}
</section> </section>
{% endif %}
<footer class="modal-card-foot"> <footer class="modal-card-foot">
{% block modal-footer %}{% endblock %} {% block modal-footer %}{% endblock %}
</footer> </footer>
{% block modal-form-close %}{% endblock %} {% block modal-form-close %}{% endblock %}
</div> </div>
{% if static %} <button
<a href="/" class="modal-close is-large">{{ label }}</a> type="button"
{% else %} class="modal-close is-large"
{% include 'snippets/toggle/toggle_button.html' with label=label class="modal-close is-large" nonbutton=True %} aria-label="{% trans 'Close' %}"
{% endif %} data-modal-close
></button>
</div> </div>

View file

@ -1,31 +0,0 @@
{% load i18n %}
<div class="modal" id="{{ id }}">
<div class="modal-background" data-modal-close></div>
<div class="modal-card is-thin" role="dialog" aria-modal="true" tabindex="-1">
<header class="modal-card-head">
<h2 class="modal-card-title mb-0">
{% block modal-title %}{% endblock %}
</h2>
<button
type="button"
class="delete"
aria-label="{% trans 'Close' %}"
data-modal-close
></button>
</header>
<section class="modal-card-body">
{% block modal-body %}{% endblock %}
</section>
<footer class="modal-card-foot">
{% block modal-footer %}{% endblock %}
</footer>
</div>
<button
type="button"
class="modal-close is-large"
aria-label="{% trans 'Close' %}"
data-modal-close
></button>
</div>

View file

@ -14,8 +14,7 @@
<button class="button is-danger" type="submit"> <button class="button is-danger" type="submit">
{% trans "Delete" %} {% trans "Delete" %}
</button> </button>
{% trans "Cancel" as button_text %} <button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="delete_group" controls_uid=group.id %}
</form> </form>
{% endblock %} {% endblock %}

View file

@ -9,5 +9,5 @@
<form name="edit-group" method="post" action="{% url 'group' group.id %}"> <form name="edit-group" method="post" action="{% url 'group' group.id %}">
{% include 'groups/form.html' %} {% include 'groups/form.html' %}
</form> </form>
{% include "groups/delete_group_modal.html" with controls_text="delete_group" controls_uid=group.id %} {% include "groups/delete_group_modal.html" with id="delete_group" %}
{% endblock %} {% endblock %}

View file

@ -14,21 +14,20 @@
</div> </div>
</div> </div>
</div> </div>
<div class="columns is-mobile"> <div class="is-flex">
<div class="column">
<div class="field has-addons">
<div class="control">
{% include 'snippets/privacy_select_no_followers.html' with current=group.privacy %}
</div>
<div class="control">
<button type="submit" class="button is-primary">{% trans "Save" %}</button>
</div>
</div>
</div>
{% if group.id %} {% if group.id %}
<div class="column is-narrow"> <div class="is-flex-grow-1">
{% trans "Delete group" as button_text %} <button type="button" data-modal-open="delete_group" class="button is-danger">
{% include 'snippets/toggle/toggle_button.html' with class="is-danger" text=button_text icon_with_text="x" controls_text="delete_group" controls_uid=group.id focus="modal_title_delete_group" %} {% trans "Delete group" %}
</button>
</div> </div>
{% endif %} {% endif %}
<div class="field has-addons">
<div class="control">
{% include 'snippets/privacy_select_no_followers.html' with current=group.privacy %}
</div>
<div class="control">
<button type="submit" class="button is-primary">{% trans "Save" %}</button>
</div>
</div>
</div> </div>

View file

@ -1,4 +1,4 @@
{% extends 'components/new_modal.html' %} {% extends 'components/modal.html' %}
{% load i18n %} {% load i18n %}
{% block modal-title %}{% trans "Delete this list?" %}{% endblock %} {% block modal-title %}{% trans "Delete this list?" %}{% endblock %}

View file

@ -5,7 +5,7 @@
type="number" type="number"
name="progress" name="progress"
class="input" class="input"
id="id_progress_{{ readthrough.id }}{{ controls_uid }}" id="{{ field_id }}"
value="{{ readthrough.progress }}" value="{{ readthrough.progress }}"
{% if progress_required %}required{% endif %} {% if progress_required %}required{% endif %}
> >

View file

@ -1,5 +1,6 @@
{% extends 'snippets/reading_modals/layout.html' %} {% extends 'snippets/reading_modals/layout.html' %}
{% load i18n %} {% load i18n %}
{% load utilities %}
{% block modal-title %} {% block modal-title %}
{% trans "Update progress" %} {% trans "Update progress" %}
@ -12,8 +13,9 @@
{% endblock %} {% endblock %}
{% block reading-dates %} {% block reading-dates %}
<label for="id_progress_{{ readthrough.id }}{{ controls_uid }}" class="label">{% trans "Progress:" %}</label> {% join "id_progress" uuid as field_id %}
{% include "snippets/progress_field.html" with progress_required=True %} <label for="{{ field_id }}" class="label">{% trans "Progress:" %}</label>
{% include "snippets/progress_field.html" with progress_required=True id=field_id %}
{% endblock %} {% endblock %}
{% block form %} {% block form %}

View file

@ -11,7 +11,7 @@ Start "<em>{{ book_title }}</em>"
{% block modal-form-open %} {% block modal-form-open %}
<form name="start-reading-{{ uuid }}" action="{% url 'reading-status' 'start' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}> <form name="start-reading-{{ uuid }}" action="{% url 'reading-status' 'start' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}>
<input type="hidden" name="reading_status" value="reading"> <input type="hidden" name="reading_status" value="reading">
<input type="hidden" name="shelf" value="{{ move_from }}"> <input type="hidden" name="shelf" value="{{ move_from }}">
{% csrf_token %} {% csrf_token %}
{% endblock %} {% endblock %}

View file

@ -1,4 +1,6 @@
{% load i18n %} {% load i18n %}
{% load utilities %}
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="id" value="{{ readthrough.id }}"> <input type="hidden" name="id" value="{{ readthrough.id }}">
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
@ -10,10 +12,11 @@
</div> </div>
{# Only show progress for editing existing readthroughs #} {# Only show progress for editing existing readthroughs #}
{% if readthrough.id and not readthrough.finish_date %} {% if readthrough.id and not readthrough.finish_date %}
<label class="label" for="id_progress_{{ readthrough.id }}{{ controls_uid }}"> {% join "id_progress" readthrough.id as field_id %}
<label class="label" for="{{ field_id }}">
{% trans "Progress" %} {% trans "Progress" %}
</label> </label>
{% include "snippets/progress_field.html" %} {% include "snippets/progress_field.html" with id=field_id %}
{% endif %} {% endif %}
<div class="field"> <div class="field">
<label class="label" for="id_finish_date_{{ readthrough.id }}"> <label class="label" for="id_finish_date_{{ readthrough.id }}">

View file

@ -3,9 +3,15 @@
{% with 0|uuid as report_uuid %} {% with 0|uuid as report_uuid %}
{% trans "Report" as button_text %} {% join "report" report_uuid as modal_id %}
{% include 'snippets/toggle/toggle_button.html' with class="is-danger is-light is-small is-fullwidth" text=button_text controls_text="report" controls_uid=report_uuid focus="modal_title_report" disabled=is_current %} <button
class="button is-small is-danger is-light is-fullwidth"
{% include 'snippets/report_modal.html' with user=user reporter=request.user controls_text="report" controls_uid=report_uuid %} type="button"
data-modal-open="{{ modal_id }}"
{% if is_current %}disabled{% endif %}
>
{% trans "Report" %}
</button>
{% include 'snippets/report_modal.html' with user=user reporter=request.user id=modal_id %}
{% endwith %} {% endwith %}

View file

@ -21,8 +21,12 @@
<section class="content"> <section class="content">
<p>{% blocktrans with site_name=site.name %}This report will be sent to {{ site_name }}'s moderators for review.{% endblocktrans %}</p> <p>{% blocktrans with site_name=site.name %}This report will be sent to {{ site_name }}'s moderators for review.{% endblocktrans %}</p>
<label class="label" for="id_{{ controls_uid }}_report_note">{% trans "More info about this report:" %}</label> <div class="control">
<textarea class="textarea" name="note" id="id_{{ controls_uid }}_report_note"></textarea> <label class="label" for="id_{{ controls_uid }}_report_note">
{% trans "More info about this report:" %}
</label>
<textarea class="textarea" name="note" id="id_{{ controls_uid }}_report_note"></textarea>
</div>
</section> </section>
{% endblock %} {% endblock %}
@ -31,9 +35,9 @@
{% block modal-footer %} {% block modal-footer %}
<button class="button is-success" type="submit">{% trans "Submit" %}</button> <button class="button is-success" type="submit">{% trans "Submit" %}</button>
{% trans "Cancel" as button_text %} <button type="button" class="button" data-modal-close>{% trans "Cancel" %}</button>
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="report" controls_uid=report_uuid class="" %}
{% endblock %} {% endblock %}
{% block modal-form-close %}</form>{% endblock %} {% block modal-form-close %}</form>{% endblock %}

View file

@ -88,11 +88,14 @@
</li> </li>
{% endif %} {% endif %}
{% 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 refresh=True class="" %} {% join "want_to_read" uuid as modal_id %}
{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book id=modal_id move_from=current.id refresh=True class="" %}
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book controls_text="start_reading" controls_uid=uuid move_from=current.id refresh=True class="" %} {% join "start_reading" uuid as modal_id %}
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id refresh=True class="" %}
{% 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 refresh=True class="" %} {% join "finish_reading" uuid as modal_id %}
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
{% endwith %} {% endwith %}
{% endblock %} {% endblock %}

View file

@ -0,0 +1,10 @@
{% load utilities %}
<form name="fallback_form_{{ 0|uuid }}" method="GET" action="{{ fallback_url }}" autocomplete="off">
<button
type="submit"
class="button {{ class }}"
data-modal-open="{{ modal_id }}"
>
{{ button_text }}
</button>
</form>

View file

@ -6,7 +6,7 @@
{% with book.id|uuid as uuid %} {% with book.id|uuid as uuid %}
{% active_shelf book as active_shelf %} {% active_shelf book as active_shelf %}
{% latest_read_through book request.user as readthrough %} {% latest_read_through book request.user as readthrough %}
<div class="field has-addons mb-0" data-shelve-button-book="{{ book.id }}"> <div class="field has-addons mb-0 has-text-weight-normal" data-shelve-button-book="{{ book.id }}">
{% if switch_mode and active_shelf.book != book %} {% if switch_mode and active_shelf.book != book %}
<div class="control"> <div class="control">
{% include 'snippets/switch_edition_button.html' with edition=book size='is-small' %} {% include 'snippets/switch_edition_button.html' with edition=book size='is-small' %}
@ -19,13 +19,17 @@
{% endif %} {% endif %}
</div> </div>
{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book controls_text="want_to_read" controls_uid=uuid %} {% join "want_to_read" uuid as modal_id %}
{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book id=modal_id class="" %}
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book controls_text="start_reading" controls_uid=uuid %} {% join "start_reading" uuid as modal_id %}
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book id=modal_id class="" %}
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid readthrough=readthrough %} {% join "finish_reading" uuid as modal_id %}
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id readthrough=readthrough class="" %}
{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book controls_text="progress_update" controls_uid=uuid readthrough=readthrough %} {% join "progress_update" uuid as modal_id %}
{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book id=modal_id readthrough=readthrough class="" %}
{% endwith %} {% endwith %}
{% endif %} {% endif %}

View file

@ -16,19 +16,22 @@
{% trans "Start reading" as button_text %} {% trans "Start reading" as button_text %}
{% url 'reading-status' 'start' book.id as fallback_url %} {% url 'reading-status' 'start' book.id as fallback_url %}
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="start_reading" controls_uid=button_uuid focus="modal_title_start_reading" disabled=is_current fallback_url=fallback_url %} {% join "start_reading" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'read' %} {% elif shelf.identifier == 'read' %}
{% trans "Read" as button_text %} {% trans "Read" as button_text %}
{% url 'reading-status' 'finish' book.id as fallback_url %} {% url 'reading-status' 'finish' book.id as fallback_url %}
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="finish_reading" controls_uid=button_uuid focus="modal_title_finish_reading" disabled=is_current fallback_url=fallback_url %} {% join "finish_reading" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'to-read' %} {% elif shelf.identifier == 'to-read' %}
{% trans "Want to read" as button_text %} {% trans "Want to read" as button_text %}
{% url 'reading-status' 'want' book.id as fallback_url %} {% url 'reading-status' 'want' book.id as fallback_url %}
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="want_to_read" controls_uid=button_uuid focus="modal_title_want_to_read" disabled=is_current fallback_url=fallback_url %} {% join "want_to_read" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.editable %} {% elif shelf.editable %}
@ -47,8 +50,9 @@
{% if readthrough and active_shelf.shelf.identifier != 'read' %} {% if readthrough and active_shelf.shelf.identifier != 'read' %}
<li role="menuitem" class="dropdown-item p-0" data-extra-options> <li role="menuitem" class="dropdown-item p-0" data-extra-options>
{% trans "Update progress" as button_text %} <button type="submit" class="button {{ class }}" data-modal-open="progress_update_{{ button_uuid }}">
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="progress_update" controls_uid=button_uuid focus="modal_title_progress_update" %} {% trans "Update progress" %}
</button>
</li> </li>
{% endif %} {% endif %}

View file

@ -23,19 +23,22 @@
{% trans "Start reading" as button_text %} {% trans "Start reading" as button_text %}
{% url 'reading-status' 'start' book.id as fallback_url %} {% url 'reading-status' 'start' book.id as fallback_url %}
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="start_reading" controls_uid=button_uuid focus="modal_title_start_reading" fallback_url=fallback_url %} {% join "start_reading" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'read' %} {% elif shelf.identifier == 'read' %}
{% trans "Finish reading" as button_text %} {% trans "Finish reading" as button_text %}
{% url 'reading-status' 'finish' book.id as fallback_url %} {% url 'reading-status' 'finish' book.id as fallback_url %}
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="finish_reading" controls_uid=button_uuid focus="modal_title_finish_reading" fallback_url=fallback_url %} {% join "finish_reading" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'to-read' %} {% elif shelf.identifier == 'to-read' %}
{% trans "Want to read" as button_text %} {% trans "Want to read" as button_text %}
{% url 'reading-status' 'want' book.id as fallback_url %} {% url 'reading-status' 'want' book.id as fallback_url %}
{% include 'snippets/toggle/toggle_button.html' with class=class text=button_text controls_text="want_to_read" controls_uid=button_uuid focus="modal_title_want_to_read" fallback_url=fallback_url %} {% join "want_to_read" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.editable %} {% elif shelf.editable %}

View file

@ -17,6 +17,12 @@ def get_uuid(identifier):
return f"{identifier}{uuid4()}" return f"{identifier}{uuid4()}"
@register.simple_tag(takes_context=False)
def join(*args):
"""concatenate an arbitary set of values"""
return "_".join(str(a) for a in args)
@register.filter(name="username") @register.filter(name="username")
def get_user_identifier(user): def get_user_identifier(user):
"""use localname for local users, username for remote""" """use localname for local users, username for remote"""