Skip to content

Commit

Permalink
Rename deletion JavaScript and add confirmation alert
Browse files Browse the repository at this point in the history
  • Loading branch information
ilumos committed Sep 8, 2024
1 parent 64ad782 commit 9e13760
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 16 deletions.
11 changes: 5 additions & 6 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ clipboard.on('error', function (e) {
console.error('Trigger:', e.trigger);
});

window.submitClosestForm = function (event) {
// Prevent the default action of the event
window.submitDeletionForm = function (event) {
event.preventDefault();

// Find the closest form to the clicked element
const form = event.target.closest('form');

// If a form is found, submit it
if (form) {
form.submit();
if (confirm('Are you sure you want to delete this?')) {
form.submit();
}
} else {
console.error('No form found');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<form action="{{ route( $route . '.destroy', $item->id) }}" method="POST" class="confirm-deletion">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event)">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event)">@lang('title.delete')</a>
</form>
@endcan
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<form action="{{ route('allowed-ip-ranges.destroy', $allowedIpRange) }}" method="POST" class="confirm-deletion">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event);">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcan
@endcomponent
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<form action="{{ route('lans.events.destroy', ['lan' => $event->lan, 'event' => $event->id]) }}" method="POST" class="confirm-deletion">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event);">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcan
@endcomponent
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class="dropdown-item">@lang('title.edit')</a>
<form action="{{ route('lans.guides.destroy', ['lan' => $guide->lan, 'guide' => $guide]) }}" method="POST" class="confirm-deletion">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event);">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcan
@endcomponent
2 changes: 1 addition & 1 deletion resources/views/pages/images/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#"
onclick="submitClosestForm(event);">@lang('title.delete')</a>
onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcomponent
</td>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/pages/lan-games/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class="custom-control-input"
class="confirm-deletion d-inline ml-1">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a href="#" onclick="submitClosestForm(event);" title="Delete">
<a href="#" onclick="submitDeletionForm(event);" title="Delete">
<i class="fa-solid fa-trash-can"></i>
</a>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class="dropdown-item">@lang('title.edit')</a>
<form action="{{ route('lans.destroy', $lan) }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event);">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcan
@endcomponent
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<form action="{{ route('lans.slides.destroy', ['lan' => $slide->lan, 'slide' => $slide]) }}" method="POST" class="confirm-deletion">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event);">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcan
@endcomponent
2 changes: 1 addition & 1 deletion resources/views/pages/user-achievements/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#"
onclick="submitClosestForm(event);">@lang('title.delete')</a>
onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcomponent
@endcan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<form action="{{ route('venues.destroy', $venue) }}" method="POST" class="confirm-deletion">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<a class="dropdown-item" href="#" onclick="submitClosestForm(event);">@lang('title.delete')</a>
<a class="dropdown-item" href="#" onclick="submitDeletionForm(event);">@lang('title.delete')</a>
</form>
@endcan
@endcomponent

0 comments on commit 9e13760

Please sign in to comment.