123 lines
4.5 KiB
PHP
Raw Normal View History

2024-06-23 17:02:56 +05:45
<div class="row gy-4">
@foreach ($permissionLists as $key => $permission)
{{-- @dd($permissionLists); --}}
<div class="col-lg-4">
{{-- <p class="justify-center text-soft-success"> --}}
<div class="form-check form-switch form-switch-custom form-switch-success mb-3">
{{-- <input class="form-check-input parent-switch" type="checkbox" role="switch" id="check_{{ $key }}"> --}}
<label class="form-check-label ms-2" for="{check_{$key}}">{{ Str::ucfirst($key) }}</label>
</div>
{{-- {{ Str::ucfirst($key) }}
</p> --}}
<fieldset class="rounded-2 p-3">
<legend class="fs-5">Permissions</legend>
<div class="row">
@foreach ($permission as $index => $item)
<div class="col-lg-12">
<div class="form-check form-check-success">
{{-- {{ html()->checkbox('permissions[]')->id('permission_' . $index)->value($index)->class('form-check-input child-checkbox')->checked($editable && in_array($index, $permissionIDsArray)) }} --}}
<a href="javascript:void(0);"
data-link="{{ route('permissions.destroy', $index) }}"
data-id="{{ $index }}"
class="link-danger fs-15 remove-item-btn"><i
class="ri-delete-bin-line"></i></a>
{{ html()->label(Str::ucfirst($item))->for('permission_' . $index)->class('form-check-label ms-2') }}
</div>
</div>
@endforeach
</div>
</fieldset>
</div>
@endforeach
</div>
@push('js')
<script type="text/javascript">
// $(document).ready(function() {
// // Cache selectors
// const childCheckboxes = $('.child-checkbox');
// const parentSwitches = $('.parent-switch');
// const allCheck = $('#all-check');
// // Initial selection (optional, can be removed if not needed)
// childCheckboxes.trigger('change');
// // Parent switch and child checkbox change handler (combined)
// $('.child-checkbox, .parent-switch').change(function() {
// const currentCol = $(this).closest('.col-lg-4');
// const currentSwitch = currentCol.find('.parent-switch');
// const currentChildren = currentCol.find(childCheckboxes);
// let allChecked = true;
// currentChildren.each(function() {
// if (!$(this).prop('checked')) {
// allChecked = false;
// return false;
// }
// });
// currentSwitch.prop('checked', allChecked);
// allCheck.prop('checked', childCheckboxes.prop(
// 'checked')); // Check all checkbox state
// });
// // "all-check" change handler
// allCheck.change(function() {
// childCheckboxes.prop('checked', this.checked).trigger('change');
// });
// });
$(document).ready(function() {
$('.child-checkbox').trigger('change');
$('.parent-switch').change(function() {
let childCheckboxes = $(this).closest('.col-lg-4').find('.child-checkbox');
childCheckboxes.prop('checked', this.checked);
});
$('.child-checkbox').change(function() {
let parentSwitch = $(this).closest('.col-lg-4').find('.parent-switch');
let childCheckboxes = $(this).closest('.col-lg-4').find('.child-checkbox');
let allChecked = true;
childCheckboxes.each(function() {
if (!$(this).prop('checked')) {
allChecked = false;
return false;
}
});
parentSwitch.prop('checked', allChecked);
});
$('#all-check').change(function() {
let childCheckboxes = $('.child-checkbox');
childCheckboxes.prop('checked', this.checked);
childCheckboxes.prop('checked', this.checked).trigger('change');
});
$('.child-checkbox, .parent-switch').change(function() {
let allCheck = $('#all-check');
let childCheckboxes = $('.child-checkbox');
let allChecked = true;
childCheckboxes.each((index, checkBox) => {
if (!$(checkBox).prop('checked')) {
allChecked = false;
return false;
}
});
allCheck.prop('checked', allChecked);
});
});
</script>
@endpush