mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Fixed bulk actions using native bootstrap-tables checkall
This commit is contained in:
parent
47cf734f72
commit
5d14acaac4
|
@ -43,7 +43,8 @@
|
|||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['hardware/bulkedit'],
|
||||
'class' => 'form-inline' ]) }}
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkEditForm']) }}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@if (Input::get('status')!='Deleted')
|
||||
|
@ -70,7 +71,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
@if (Input::get('status')!='Deleted')
|
||||
<th data-class="hidden-xs" data-switchable="false" data-searchable="false" data-sortable="false" data-field="checkbox"><div class="text-center"><input type="checkbox" id="checkAll" style="padding-left: 0px;"></div></th>
|
||||
<th data-checkbox="true" data-field="checkbox"></th>
|
||||
@endif
|
||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||
<th data-field="companyName" data-searchable="true" data-sortable="true" data-switchable="true" data-visible="false">{{ trans('general.company') }}</th>
|
||||
|
@ -128,23 +129,32 @@
|
|||
])
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
function checkForChecked() {
|
||||
var check_checked = $('input.one_required:checked').length;
|
||||
if (check_checked > 0) {
|
||||
$('#bulkEdit').removeAttr('disabled');
|
||||
}
|
||||
else {
|
||||
$('#bulkEdit').attr('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
$('#table').on('change','input.one_required',checkForChecked);
|
||||
$("#checkAll").change(function () {
|
||||
$("input:checkbox").prop('checked', $(this).prop("checked"));
|
||||
checkForChecked();
|
||||
});
|
||||
|
||||
var checkedRows = 0;
|
||||
|
||||
$('.snipe-table').on('check.bs.table', function (e, row) {
|
||||
$(this).val(row.id);
|
||||
checkedRows++;
|
||||
$('#bulkEdit').removeAttr('disabled');
|
||||
atLeastOneChecked(checkedRows);
|
||||
});
|
||||
|
||||
$('.snipe-table').on('uncheck.bs.table', function (e, row) {
|
||||
checkedRows--;
|
||||
atLeastOneChecked(checkedRows);
|
||||
|
||||
});
|
||||
|
||||
|
||||
function atLeastOneChecked(checkedRows) {
|
||||
if (checkedRows > 0) {
|
||||
$('#bulkEdit').removeAttr('disabled');
|
||||
}
|
||||
else {
|
||||
$('#bulkEdit').attr('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function actionsFormatter(value, row) {
|
||||
return '<nobr><a href="{{ url('/') }}/hardware/' + row.id + '/edit" class="btn btn-sm btn-warning"><i class="fa fa-pencil"></i></a> '
|
||||
+ '<a data-html="false" class="btn delete-asset btn-danger btn-sm" ' +
|
||||
|
@ -160,5 +170,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('#bulkEdit').click(function () {
|
||||
var selectedIds = $('.snipe-table').bootstrapTable('getSelections');
|
||||
|
||||
$.each(selectedIds, function(key,value) {
|
||||
$( "#bulkEditForm" ).append($('<input type="hidden" name="edit_asset[' + value.id + ']" value="' + value.id + '">' ));
|
||||
//alert(value.id);
|
||||
});
|
||||
|
||||
//event.preventDefault();
|
||||
//return false;
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
@stop
|
||||
|
|
|
@ -11,7 +11,6 @@ $('.snipe-table').bootstrapTable({
|
|||
undefinedText: '',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
//selectItemName: 'bulk_ids[]',
|
||||
@if (isset($search))
|
||||
search: true,
|
||||
@endif
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['users/bulkedit'],
|
||||
'class' => 'form-inline' ]) }}
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkEditForm']) }}
|
||||
|
||||
@if (Input::get('status')!='deleted')
|
||||
@can('delete', \App\Models\User::class)
|
||||
|
@ -69,7 +70,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
@if (Input::get('status')!='deleted')
|
||||
<th data-checkbox="true" data-field="checkbox" data-formatter="checkboxFormatter"></th>
|
||||
<th data-checkbox="true" data-field="checkbox"></th>
|
||||
@endif
|
||||
<th data-switchable="true" data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||
<th data-switchable="true" data-sortable="false" data-field="companyName" data-visible="false">{{ trans('admin/companies/table.title') }}</th>
|
||||
|
@ -110,8 +111,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<div id="id_collector">
|
||||
</div>
|
||||
|
||||
{{ Form::close() }}
|
||||
</div><!-- /.box-body -->
|
||||
</div><!-- /.box -->
|
||||
|
@ -124,13 +124,14 @@
|
|||
@include ('partials.bootstrap-table', ['exportFile' => 'users-export', 'search' => true])
|
||||
|
||||
<script>
|
||||
|
||||
var checkedRows = 0;
|
||||
|
||||
$('.snipe-table').on('check.bs.table', function (e, row) {
|
||||
$(this).val(row.id);
|
||||
checkedRows++;
|
||||
$('#bulkEdit').removeAttr('disabled');
|
||||
atLeastOneChecked(checkedRows);
|
||||
addCheckedInput(row);
|
||||
});
|
||||
|
||||
$('.snipe-table').on('uncheck.bs.table', function (e, row) {
|
||||
|
@ -148,15 +149,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
function addCheckedInput(value, row) {
|
||||
return '<input type="hidden" name="bulk_ids[' + value.id + ']" value="' + value.id + '" />';
|
||||
}
|
||||
|
||||
function checkboxFormatter(value, row) {
|
||||
if (value) {
|
||||
return '<input type="hidden" name="foo[]" value="bar">';
|
||||
}
|
||||
}
|
||||
|
||||
function locationFormatter(value, row) {
|
||||
if ((value) && (value[0].name)) {
|
||||
|
@ -205,6 +198,20 @@
|
|||
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('#bulkEdit').click(function () {
|
||||
var selectedIds = $('.snipe-table').bootstrapTable('getSelections');
|
||||
|
||||
$.each(selectedIds, function(key,value) {
|
||||
$( "#bulkEditForm" ).append($('<input type="hidden" name="edit_user[' + value.id + ']" value="' + value.id + '">' ));
|
||||
//alert(value.id);
|
||||
});
|
||||
|
||||
//event.preventDefault();
|
||||
//return false;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue