From 723587b0acc49c4638df4a049903f789de205805 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 7 Aug 2020 09:50:01 +0900 Subject: [PATCH] =?UTF-8?q?deleteCheckinModal=E3=81=AE=E4=B8=AD=E8=BA=AB?= =?UTF-8?q?=E3=81=A7=E3=81=AA=E3=82=8B=E3=81=B9=E3=81=8FjQuery=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/tissue.ts | 31 +++++++++------------- resources/views/ejaculation/show.blade.php | 12 ++++----- resources/views/user/profile.blade.php | 12 ++++----- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/resources/assets/js/tissue.ts b/resources/assets/js/tissue.ts index ae2ddcb..804ef4d 100644 --- a/resources/assets/js/tissue.ts +++ b/resources/assets/js/tissue.ts @@ -6,6 +6,8 @@ export function suicide(e: T) { }; } +const die = suicide('Element not found!'); + export function linkCard(el: Element) { const url = el.querySelector('a')?.href; if (!url) { @@ -15,7 +17,6 @@ export function linkCard(el: Element) { fetchGet('/api/checkin/card', { url }) .then((response) => response.json()) .then((data) => { - const die = suicide('Element not found!'); const metaColumn = el.querySelector('.col-12:last-of-type') || die(); const imageColumn = el.querySelector('.col-12:first-of-type') || die(); const title = el.querySelector('.card-title') || die(); @@ -58,21 +59,15 @@ export function pageSelector(el: Element) { return el; } -export function deleteCheckinModal(el: Element) { - return $(el) - .on('show.bs.modal', function (event) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const target = $(event.relatedTarget!); - const modal = $(this); - modal.find('.modal-body .date-label').text(target.data('date')); - modal.data('id', target.data('id')); - }) - .find('.btn-danger') - .on('click', function (_event) { - const modal = $('#deleteCheckinModal'); - const form = modal.find('form'); - form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null); - form.submit(); - }) - .end(); +export function deleteCheckinModal(modal: Element) { + let id: any = null; + modal.querySelector('form')?.addEventListener('submit', function () { + this.action = this.action.replace('@', id); + }); + return $(modal).on('show.bs.modal', function (event) { + const target = event.relatedTarget || die(); + const dateLabel = this.querySelector('.modal-body .date-label') || die(); + dateLabel.textContent = target.dataset.date || null; + id = target.dataset.id; + }); } diff --git a/resources/views/ejaculation/show.blade.php b/resources/views/ejaculation/show.blade.php index 5dea347..4f9db40 100644 --- a/resources/views/ejaculation/show.blade.php +++ b/resources/views/ejaculation/show.blade.php @@ -97,13 +97,13 @@ 削除確認 @endslot のチェックインを削除してもよろしいですか? -
- {{ csrf_field() }} - {{ method_field('DELETE') }} -
@slot('footer') - - +
+ {{ csrf_field() }} + {{ method_field('DELETE') }} + + +
@endslot @endcomponent @endsection diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index d850e6a..d7c39d7 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -117,13 +117,13 @@ 削除確認 @endslot のチェックインを削除してもよろしいですか? -
- {{ csrf_field() }} - {{ method_field('DELETE') }} -
@slot('footer') - - +
+ {{ csrf_field() }} + {{ method_field('DELETE') }} + + +
@endslot @endcomponent @endsection