From b28e88b9cd1eb8489f8d0cdd86b7eb46a50a443f Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Mon, 14 Oct 2024 23:20:09 -0300 Subject: [PATCH] feat: add Swal as a hyperscript behavior --- app/templates/account_groups/pages/list.html | 24 +++------- app/templates/accounts/pages/list.html | 24 +++------- app/templates/categories/pages/list.html | 24 +++------- app/templates/currencies/pages/list.html | 24 +++------- app/templates/includes/scripts.html | 1 + .../includes/scripts/hyperscript/swal.html | 22 +++++++++ .../monthly_overview/fragments/list.html | 9 +++- app/templates/tags/pages/list.html | 24 +++------- .../transactions/fragments/item.html | 47 +++++-------------- 9 files changed, 74 insertions(+), 125 deletions(-) create mode 100644 app/templates/includes/scripts/hyperscript/swal.html diff --git a/app/templates/account_groups/pages/list.html b/app/templates/account_groups/pages/list.html index ffba113..be65a8d 100644 --- a/app/templates/account_groups/pages/list.html +++ b/app/templates/account_groups/pages/list.html @@ -44,24 +44,12 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Delete" %}" hx-delete="{% url 'account_group_delete' pk=account_group.id %}" - hx-trigger='delete_confirmed' - _="on click - if event.ctrlKey trigger delete_confirmed - else - call Swal.fire({title: '{% translate 'Are you sure?' %}', - text: '{% blocktranslate %}You won\'t be able to revert this!{% endblocktranslate %}', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - cancelButtonText: '{% blocktranslate %}Cancel{% endblocktranslate %}', - confirmButtonText: '{% blocktranslate %}Yes, delete it!{% endblocktranslate %}', - customClass: { - confirmButton: 'btn btn-primary me-3', - cancelButton: 'btn btn-danger' - }, - buttonsStyling: false}) - if result.isConfirmed trigger delete_confirmed"> + hx-trigger='confirmed' + data-bypass-on-ctrl="true" + data-title="{% translate "Are you sure?" %}" + data-text="{% translate "You won't be able to revert this!" %}" + data-confirm-text="{% translate "Yes, delete it!" %}" + _="install prompt_swal"> {{ account_group.name }} {% endfor %} diff --git a/app/templates/accounts/pages/list.html b/app/templates/accounts/pages/list.html index 4ee48a7..519f474 100644 --- a/app/templates/accounts/pages/list.html +++ b/app/templates/accounts/pages/list.html @@ -47,24 +47,12 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Delete" %}" hx-delete="{% url 'account_delete' pk=account.id %}" - hx-trigger='delete_confirmed' - _="on click - if event.ctrlKey trigger delete_confirmed - else - call Swal.fire({title: '{% translate 'Are you sure?' %}', - text: '{% blocktranslate %}You won\'t be able to revert this!{% endblocktranslate %}', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - cancelButtonText: '{% blocktranslate %}Cancel{% endblocktranslate %}', - confirmButtonText: '{% blocktranslate %}Yes, delete it!{% endblocktranslate %}', - customClass: { - confirmButton: 'btn btn-primary me-3', - cancelButton: 'btn btn-danger' - }, - buttonsStyling: false}) - if result.isConfirmed trigger delete_confirmed"> + hx-trigger='confirmed' + data-bypass-on-ctrl="true" + data-title="{% translate "Are you sure?" %}" + data-text="{% translate "You won't be able to revert this!" %}" + data-confirm-text="{% translate "Yes, delete it!" %}" + _="install prompt_swal"> {{ account.name }} {{ account.currency }} ({{ account.currency.code }}) {% if account.exchange_currency %}{{ account.exchange_currency }} ( diff --git a/app/templates/categories/pages/list.html b/app/templates/categories/pages/list.html index 5b8b517..59e2db1 100644 --- a/app/templates/categories/pages/list.html +++ b/app/templates/categories/pages/list.html @@ -45,24 +45,12 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Delete" %}" hx-delete="{% url 'category_delete' category_id=category.id %}" - hx-trigger='delete_confirmed' - _="on click - if event.ctrlKey trigger delete_confirmed - else - call Swal.fire({title: '{% translate 'Are you sure?' %}', - text: '{% blocktranslate %}You won\'t be able to revert this!{% endblocktranslate %}', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - cancelButtonText: '{% blocktranslate %}Cancel{% endblocktranslate %}', - confirmButtonText: '{% blocktranslate %}Yes, delete it!{% endblocktranslate %}', - customClass: { - confirmButton: 'btn btn-primary me-3', - cancelButton: 'btn btn-danger' - }, - buttonsStyling: false}) - if result.isConfirmed trigger delete_confirmed"> + hx-trigger='confirmed' + data-bypass-on-ctrl="true" + data-title="{% translate "Are you sure?" %}" + data-text="{% translate "You won't be able to revert this!" %}" + data-confirm-text="{% translate "Yes, delete it!" %}" + _="install prompt_swal"> {% if category.mute %}{% endif %} diff --git a/app/templates/currencies/pages/list.html b/app/templates/currencies/pages/list.html index aa2bfd0..02cc4f6 100644 --- a/app/templates/currencies/pages/list.html +++ b/app/templates/currencies/pages/list.html @@ -45,24 +45,12 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Delete" %}" hx-delete="{% url 'currency_delete' pk=currency.id %}" - hx-trigger='delete_confirmed' - _="on click - if event.ctrlKey trigger delete_confirmed - else - call Swal.fire({title: '{% translate 'Are you sure?' %}', - text: '{% blocktranslate %}You won\'t be able to revert this!{% endblocktranslate %}', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - cancelButtonText: '{% blocktranslate %}Cancel{% endblocktranslate %}', - confirmButtonText: '{% blocktranslate %}Yes, delete it!{% endblocktranslate %}', - customClass: { - confirmButton: 'btn btn-primary me-3', - cancelButton: 'btn btn-danger' - }, - buttonsStyling: false}) - if result.isConfirmed trigger delete_confirmed"> + hx-trigger='confirmed' + data-bypass-on-ctrl="true" + data-title="{% translate "Are you sure?" %}" + data-text="{% translate "You won't be able to revert this!" %}" + data-confirm-text="{% translate "Yes, delete it!" %}" + _="install prompt_swal"> {{ currency.code }} {{ currency.name }} diff --git a/app/templates/includes/scripts.html b/app/templates/includes/scripts.html index 0afd0c3..90b6f69 100644 --- a/app/templates/includes/scripts.html +++ b/app/templates/includes/scripts.html @@ -9,6 +9,7 @@ {% include 'includes/scripts/hyperscript/tooltip.html' %} {% include 'includes/scripts/hyperscript/htmx_error_handler.html' %} {% include 'includes/scripts/hyperscript/sounds.html' %} +{% include 'includes/scripts/hyperscript/swal.html' %} {% javascript_pack 'htmx' attrs="defer" %} diff --git a/app/templates/includes/scripts/hyperscript/swal.html b/app/templates/includes/scripts/hyperscript/swal.html new file mode 100644 index 0000000..eef96ed --- /dev/null +++ b/app/templates/includes/scripts/hyperscript/swal.html @@ -0,0 +1,22 @@ +{% load i18n %} + diff --git a/app/templates/monthly_overview/fragments/list.html b/app/templates/monthly_overview/fragments/list.html index a4bb965..dd4be93 100644 --- a/app/templates/monthly_overview/fragments/list.html +++ b/app/templates/monthly_overview/fragments/list.html @@ -64,8 +64,15 @@ diff --git a/app/templates/tags/pages/list.html b/app/templates/tags/pages/list.html index 9ffa93c..a6ba2dd 100644 --- a/app/templates/tags/pages/list.html +++ b/app/templates/tags/pages/list.html @@ -44,24 +44,12 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Delete" %}" hx-delete="{% url 'tag_delete' tag_id=tag.id %}" - hx-trigger='delete_confirmed' - _="on click - if event.ctrlKey trigger delete_confirmed - else - call Swal.fire({title: '{% translate 'Are you sure?' %}', - text: '{% blocktranslate %}You won\'t be able to revert this!{% endblocktranslate %}', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - cancelButtonText: '{% blocktranslate %}Cancel{% endblocktranslate %}', - confirmButtonText: '{% blocktranslate %}Yes, delete it!{% endblocktranslate %}', - customClass: { - confirmButton: 'btn btn-primary me-3', - cancelButton: 'btn btn-danger' - }, - buttonsStyling: false}) - if result.isConfirmed trigger delete_confirmed"> + hx-trigger='confirmed' + data-bypass-on-ctrl="true" + data-title="{% translate "Are you sure?" %}" + data-text="{% translate "You won't be able to revert this!" %}" + data-confirm-text="{% translate "Yes, delete it!" %}" + _="install prompt_swal"> {{ tag.name }} {% endfor %} diff --git a/app/templates/transactions/fragments/item.html b/app/templates/transactions/fragments/item.html index 03a7ddb..27e0d4e 100644 --- a/app/templates/transactions/fragments/item.html +++ b/app/templates/transactions/fragments/item.html @@ -83,24 +83,13 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Delete" %}" hx-delete="{% url 'transaction_delete' transaction_id=transaction.id %}" - hx-trigger='delete_confirmed' - _="on click - if event.ctrlKey trigger delete_confirmed - else - call Swal.fire({title: '{% translate 'Are you sure?' %}', - text: '{% blocktranslate %}You won\'t be able to revert this!{% endblocktranslate %}', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - cancelButtonText: '{% blocktranslate %}Cancel{% endblocktranslate %}', - confirmButtonText: '{% blocktranslate %}Yes, delete it!{% endblocktranslate %}', - customClass: { - confirmButton: 'btn btn-primary me-3', - cancelButton: 'btn btn-danger' - }, - buttonsStyling: false}) - if result.isConfirmed trigger delete_confirmed"> + hx-trigger='confirmed' + data-bypass-on-ctrl="true" + data-title="{% translate "Are you sure?" %}" + data-text="{% translate "You won't be able to revert this!" %}" + data-confirm-text="{% translate "Yes, delete it!" %}" + _="install prompt_swal"> + {# Item actions dropdown fallback for mobile#}