diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index f08f6739..69ac202d 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -18,7 +18,7 @@ background-color: hsl(171, 100%, 41%); color: white; } -.hide-active[aria-pressed=true] { +.hide-active[aria-pressed=true], .hide-active { display: none; } diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index e7b87dd8..f4b9a588 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -60,13 +60,14 @@ function toggleAction(e) { if (targetId) { var target = document.getElementById(targetId); - if (pressed) { - removeClass(target, 'hidden'); - addClass(target, 'is-active'); - } else { - addClass(target, 'hidden'); - removeClass(target, 'is-active'); - } + addRemoveClass(target, 'hidden', !pressed); + addRemoveClass(target, 'is-active', pressed); + } + + // show/hide container + var container = document.getElementById('hide-' + targetId); + if (!!container) { + addRemoveClass(container, 'hidden', pressed); } // set checkbox, if appropriate @@ -82,13 +83,23 @@ function toggleAction(e) { } } +function addRemoveClass(el, classname, bool) { + if (bool) { + addClass(el, classname) + } else { + removeClass(el, classname) + } +} function addClass(el, classname) { el.className = el.className.split(' ').concat(classname).join(' '); } function removeClass(el, className) { - var classes = el.className.split(' '); + var classes = [] + if (el.className) { + var classes = el.className.split(' '); + } const idx = classes.indexOf(className); if (idx > -1) { classes.splice(idx, 1); diff --git a/bookwyrm/templates/snippets/components/modal.html b/bookwyrm/templates/snippets/components/modal.html new file mode 100644 index 00000000..63db1168 --- /dev/null +++ b/bookwyrm/templates/snippets/components/modal.html @@ -0,0 +1,23 @@ + + diff --git a/bookwyrm/templates/snippets/delete_readthrough_modal.html b/bookwyrm/templates/snippets/delete_readthrough_modal.html new file mode 100644 index 00000000..1456cc76 --- /dev/null +++ b/bookwyrm/templates/snippets/delete_readthrough_modal.html @@ -0,0 +1,13 @@ +{% extends 'snippets/components/modal.html' %} +{% block modal-title %}Delete this read-though?{% endblock %} + +{% block modal-footer %} +
+ {% csrf_token %} + + + {% include 'snippets/toggle/toggle_button.html' with text="Cancel" controls_text="delete-readthrough" controls_uid=readthrough.id %} +
+{% endblock %} diff --git a/bookwyrm/templates/snippets/finish_reading_modal.html b/bookwyrm/templates/snippets/finish_reading_modal.html index cce89092..10af1162 100644 --- a/bookwyrm/templates/snippets/finish_reading_modal.html +++ b/bookwyrm/templates/snippets/finish_reading_modal.html @@ -1,45 +1,46 @@ -{% load bookwyrm_tags %} - -{% include 'snippets/start_reading_modal.html' with book=active_shelf.book %} -{% include 'snippets/finish_reading_modal.html' with book=active_shelf.book %} + +{% include 'snippets/start_reading_modal.html' with book=active_shelf.book controls_text="start-reading" controls_uid=uuid %} + +{% latest_read_through book request.user as readthrough %} +{% include 'snippets/finish_reading_modal.html' with book=active_shelf.book controls_text="finish-reading" controls_uid=uuid readthrough=readthrough %} + {% endwith %} {% endif %} diff --git a/bookwyrm/templates/snippets/start_reading_modal.html b/bookwyrm/templates/snippets/start_reading_modal.html index 267c70f7..50724e11 100644 --- a/bookwyrm/templates/snippets/start_reading_modal.html +++ b/bookwyrm/templates/snippets/start_reading_modal.html @@ -1,36 +1,38 @@ -