Hide "Delete Selected" button when no points are selected.

This commit is contained in:
Eugene Burmakin
2025-07-26 14:41:03 +02:00
parent b94be44cbf
commit e3d3a92faa
4 changed files with 21 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- The Warden error in jobs is now fixed. #1556
- The Live Map setting is now respected.
- The Live Map info modal is now displayed. #665
- The "Delete Selected" button is now hidden when no points are selected. #1025

View File

@@ -18,6 +18,10 @@ class PointsController < ApplicationController
end
def bulk_destroy
redirect_to points_url(preserved_params),
alert: 'No points selected.',
status: :see_other and return if params[:point_ids].blank?
current_user.tracked_points.where(id: params[:point_ids].compact).destroy_all
redirect_to points_url(preserved_params),
notice: 'Points were successfully destroyed.',

View File

@@ -2,11 +2,12 @@ import BaseController from "./base_controller"
// Connects to data-controller="checkbox-select-all"
export default class extends BaseController {
static targets = ["parent", "child"]
static targets = ["parent", "child", "deleteButton"]
connect() {
this.parentTarget.checked = false
this.childTargets.map(x => x.checked = false)
this.updateDeleteButtonVisibility()
}
toggleChildren() {
@@ -15,6 +16,7 @@ export default class extends BaseController {
} else {
this.childTargets.map(x => x.checked = false)
}
this.updateDeleteButtonVisibility()
}
toggleParent() {
@@ -23,5 +25,14 @@ export default class extends BaseController {
} else {
this.parentTarget.checked = true
}
this.updateDeleteButtonVisibility()
}
updateDeleteButtonVisibility() {
const hasCheckedItems = this.childTargets.some(target => target.checked)
if (this.hasDeleteButtonTarget) {
this.deleteButtonTarget.style.display = hasCheckedItems ? 'inline-block' : 'none'
}
}
}

View File

@@ -48,7 +48,7 @@
<%= form_with url: bulk_destroy_points_path(params.permit!), method: :delete, id: :bulk_destroy_form do |f| %>
<div class="flex justify-between my-5">
<%= f.submit "Delete Selected", class: "px-4 py-2 bg-red-500 text-white rounded-md", data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" } %>
<%= f.submit "Delete Selected", class: "px-4 py-2 bg-red-500 text-white rounded-md", data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?", checkbox_select_all_target: "deleteButton" }, style: "display: none;" %>
<div>
<%= page_entries_info @points, entry_name: 'point' %>
</div>
@@ -64,14 +64,15 @@
<tr>
<th>
<%= label_tag do %>
Select all
<%= check_box_tag 'Select all',
id: :select_all_points,
data: {
checkbox_select_all_target: 'parent',
action: 'change->checkbox-select-all#toggleChildren'
}
},
class: 'mr-2'
%>
Select all
<% end %>
</div>
</th>