Additional JS tweaking

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-06-05 20:13:51 -07:00
parent 7c77e03c5a
commit 9f478b51e2
4 changed files with 35 additions and 17 deletions

View file

@ -98,6 +98,8 @@
data-show-refresh="true"
data-sort-order="asc"
data-toolbar="#toolbar"
data-bulk-action-id="#bulkEditButton"
data-bulk-form-id="#usersBulkForm"
id="usersTable"
class="table table-striped snipe-table"
data-url="{{route('api.users.index', ['location_id' => $location->id])}}"
@ -126,7 +128,7 @@
data-show-export="true"
data-show-refresh="true"
data-sort-order="asc"
data-toolbar="#toolbar"
data-toolbar="#assetToolbar"
id="assetsListingTable"
class="table table-striped snipe-table"
data-url="{{route('api.assets.index', ['location_id' => $location->id]) }}"

View file

@ -1,9 +1,9 @@
<div id="assets-toolbar">
<div id="toolbar">
{{ Form::open([
'method' => 'POST',
'route' => ['hardware/bulkedit'],
'class' => 'form-inline',
'id' => 'bulkForm']) }}
'id' => 'assetToolbar']) }}
<label for="bulk_actions">

View file

@ -114,8 +114,11 @@
// These methods dynamically add/remove hidden input values in the bulk actions form
$('.snipe-table').on('check.bs.table .btSelectItem', function (row, $element) {
$('#bulkEdit').removeAttr('disabled');
$('#bulkEdit').prepend('<input id="checkbox_' + $element.id + '" type="hidden" name="ids[]" value="' + $element.id + '">');
var buttonName = $(this).data('bulk-action-id');
var formName = this;
$(buttonName).removeAttr('disabled');
$(formName).prepend('<input id="checkbox_' + $element.id + '" type="hidden" name="ids[]" value="' + $element.id + '">');
});
$('.snipe-table').on('uncheck.bs.table .btSelectItem', function (row, $element) {
@ -125,14 +128,23 @@
// Handle whether or not the edit button should be disabled
$('.snipe-table').on('uncheck.bs.table', function () {
var buttonName = $(this).data('bulk-action-id');
console.log('Something was unchecked');
console.log($('.snipe-table').bootstrapTable('getSelections').length);
if ($('.snipe-table').bootstrapTable('getSelections').length == 0) {
$('#bulkEdit').attr('disabled', 'disabled');
console.log('length is 0');
$(buttonName).attr('disabled', 'disabled');
}
});
$('.snipe-table').on('uncheck-all.bs.table', function (event, rowsAfter, rowsBefore) {
$('#bulkEdit').attr('disabled', 'disabled');
//console.dir(rowsBefore);
var buttonName = $(this).data('bulk-action-id');
$(buttonName).attr('disabled', 'disabled');
console.log('all are unchecked');
for (var i in rowsBefore) {
$( "#checkbox_" + rowsBefore[i].id).remove();
@ -141,13 +153,15 @@
});
$('.snipe-table').on('check-all.bs.table', function (event, rowsAfter, rowsBefore) {
$('#bulkEdit').removeAttr('disabled');
//console.dir(rowsAfter);
var buttonName = $(this).data('bulk-action-id');
$(buttonName).removeAttr('disabled');
var formName = this;
console.log('check all fired');
for (var i in rowsAfter) {
// console.log(rowsAfter[i].id);
$('#bulkEdit').prepend('<input id="checkbox_' + rowsAfter[i].id + '" type="hidden" name="ids[]" value="' + rowsAfter[i].id + '">');
$(formName).prepend('<input id="checkbox_' + rowsAfter[i].id + '" type="hidden" name="ids[]" value="' + rowsAfter[i].id + '">');
}
});

View file

@ -1,8 +1,9 @@
{{ Form::open([
<div id="toolbar">
{{ Form::open([
'method' => 'POST',
'route' => ['users/bulkedit'],
'class' => 'form-inline',
'id' => 'bulkForm']) }}
'id' => 'usersBulkForm']) }}
@if (request('status')!='deleted')
@can('delete', \App\Models\User::class)
@ -13,7 +14,8 @@
<option value="edit">{{ trans('general.bulk_edit') }}</option>
<option value="bulkpasswordreset">{{ trans('button.send_password_link') }}</option>
</select>
<button class="btn btn-default" id="bulkEdit" disabled>{{ trans('button.go') }}</button>
<button class="btn btn-default" id="bulkEditButton" disabled>{{ trans('button.go') }}</button>
</div>
@endcan
@endif
@endif
</div>