A free open source IT asset/license management system
Show number of selected, use checkboxEnabledFormatter on simple toolbars
snipe221e4959743e
diff --git a/app/Http/Transformers/CategoriesTransformer.php b/app/Http/Transformers/CategoriesTransformer.phpindex 412ccb0023..c35912df3e 100644--- a/app/Http/Transformers/CategoriesTransformer.php+++ b/app/Http/Transformers/CategoriesTransformer.php@@ -75,6 +75,9 @@ class CategoriesTransformer$permissions_array['available_actions'] = ['update' => Gate::allows('update', Category::class),'delete' => $category->isDeletable(),+ 'bulk_selectable' => [+ 'delete' => $category->isDeletable(),+ ],];$array += $permissions_array;diff --git a/app/Http/Transformers/ManufacturersTransformer.php b/app/Http/Transformers/ManufacturersTransformer.phpindex 1e793439a4..8485bfb338 100644--- a/app/Http/Transformers/ManufacturersTransformer.php+++ b/app/Http/Transformers/ManufacturersTransformer.php@@ -52,6 +52,9 @@ class ManufacturersTransformer'update' => (($manufacturer->deleted_at == '') && (Gate::allows('update', Manufacturer::class))),'restore' => (($manufacturer->deleted_at != '') && (Gate::allows('create', Manufacturer::class))),'delete' => $manufacturer->isDeletable(),+ 'bulk_selectable' => [+ 'delete' => $manufacturer->isDeletable(),+ ],];$array += $permissions_array;diff --git a/app/Http/Transformers/SuppliersTransformer.php b/app/Http/Transformers/SuppliersTransformer.phpindex f4b6bfaaa0..efe83defb6 100644--- a/app/Http/Transformers/SuppliersTransformer.php+++ b/app/Http/Transformers/SuppliersTransformer.php@@ -57,6 +57,9 @@ class SuppliersTransformer$permissions_array['available_actions'] = ['update' => Gate::allows('update', Supplier::class),'delete' => (Gate::allows('delete', Supplier::class) && ($supplier->isDeletable())),+ 'bulk_selectable' => [+ 'delete' => (Gate::allows('delete', Supplier::class) && ($supplier->isDeletable())),+ ],];$array += $permissions_array;diff --git a/app/Presenters/CategoryPresenter.php b/app/Presenters/CategoryPresenter.phpindex 5c5d620c57..db8390c9c5 100644--- a/app/Presenters/CategoryPresenter.php+++ b/app/Presenters/CategoryPresenter.php@@ -18,6 +18,7 @@ class CategoryPresenter extends Presenter['field' => 'checkbox','checkbox' => true,+ 'formatter' => 'checkboxEnabledFormatter','titleTooltip' => trans('general.select_all_none'),'printIgnore' => true,'class' => 'hidden-print',diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.phpindex 2332ab9215..64bc9f2c61 100644--- a/app/Presenters/ManufacturerPresenter.php+++ b/app/Presenters/ManufacturerPresenter.php@@ -18,6 +18,7 @@ class ManufacturerPresenter extends Presenter['field' => 'checkbox','checkbox' => true,+ 'formatter' => 'checkboxEnabledFormatter','titleTooltip' => trans('general.select_all_none'),'printIgnore' => true,'class' => 'hidden-print',diff --git a/app/Presenters/SupplierPresenter.php b/app/Presenters/SupplierPresenter.phpindex 914d546a57..ef78d10680 100644--- a/app/Presenters/SupplierPresenter.php+++ b/app/Presenters/SupplierPresenter.php@@ -16,6 +16,7 @@ class SupplierPresenter extends Presenter['field' => 'checkbox','checkbox' => true,+ 'formatter' => 'checkboxEnabledFormatter','titleTooltip' => trans('general.select_all_none'),'printIgnore' => true,'class' => 'hidden-print',diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.phpindex 46ba6f7aac..ca7fe9b744 100644--- a/resources/lang/en-US/general.php+++ b/resources/lang/en-US/general.php@@ -288,6 +288,7 @@ return ['select_var' => 'Select :thing... ', // this will eventually replace all of our other selects'select' => 'Select','select_all' => 'Select All',+ 'selected' => 'selected','search' => 'Search','select_category' => 'Select a Category','select_datasource' => 'Select a data source',diff --git a/resources/views/blade/table/index.blade.php b/resources/views/blade/table/index.blade.phpindex e9d6a1ef22..e44e91c9f7 100644--- a/resources/views/blade/table/index.blade.php+++ b/resources/views/blade/table/index.blade.php@@ -24,6 +24,7 @@data-toolbar="#{{ Illuminate\Support\Str::camel($name) }}Toolbar"data-bulk-button-id="#{{ Illuminate\Support\Str::camel($name) }}Button"data-bulk-form-id="#{{ Illuminate\Support\Str::camel($name) }}Form"+ data-selected-count-id="#{{ Illuminate\Support\Str::camel($name) }}SelectedCount"id="{{ $name }}ListingTable"data-show-columns-search="{{ $show_column_search }}"data-show-advanced-search="{{ $show_advanced_search }}"diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex 3bcab6f5dd..9936bdec8e 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -1367,6 +1367,30 @@}+ function updateSelectedCount(table) {+ var countId = $(table).data('selected-count-id');+ if (!countId || !$(countId).length) return;+ var count = $(table).bootstrapTable('getSelections').length;+ $(countId).find('.badge').text(count);+ if (count > 0) {+ $(countId).show();+ } else {+ $(countId).hide();+ }+ }++ $('.snipe-table').on('post-body.bs.table', function () {+ var countId = $(this).data('selected-count-id');+ if (!countId) return;+ var $paginationDetail = $(this).closest('.bootstrap-table')+ .find('.fixed-table-pagination').first()+ .find('.pagination-detail');+ if ($paginationDetail.length && $(countId).length === 0) {+ $paginationDetail.after('<span id="' + countId.substring(1) + '" style="display:none; float:left; margin-top:10px; margin-bottom:10px; margin-left:10px; line-height:34px;">— <span class="badge">0</span> {{ trans('general.selected') }}</span>');+ }+ updateSelectedCount(this);+ });+// These methods dynamically add/remove hidden input values in the bulk actions form$('.snipe-table').on('check.bs.table .btSelectItem', function (row, $element) {var buttonName = $(this).data('bulk-button-id');@@ -1374,12 +1398,12 @@$(buttonName).removeAttr('disabled');$(buttonName).after('<input id="' + tableId + '_checkbox_' + $element.id + '" type="hidden" name="ids[]" value="' + $element.id + '">');+ updateSelectedCount(this);});$('.snipe-table').on('check-all.bs.table', function (event, rowsAfter) {var buttonName = $(this).data('bulk-button-id');- $(buttonName).removeAttr('disabled');var tableId = $(this).data('id-table');for (var i in rowsAfter) {@@ -1388,12 +1412,18 @@$(buttonName).after('<input id="' + tableId + '_checkbox_' + rowsAfter[i].id + '" type="hidden" name="ids[]" value="' + rowsAfter[i].id + '">');}}++ if ($(this).bootstrapTable('getSelections').length > 0) {+ $(buttonName).removeAttr('disabled');+ }+ updateSelectedCount(this);});$('.snipe-table').on('uncheck.bs.table .btSelectItem', function (row, $element) {var tableId = $(this).data('id-table');$( "#" + tableId + "_checkbox_" + $element.id).remove();+ updateSelectedCount(this);});@@ -1416,6 +1446,7 @@for (var i in rowsBefore) {$('#' + tableId + "_checkbox_" + rowsBefore[i].id).remove();}+ updateSelectedCount(this);});