You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.9 KiB
125 lines
4.9 KiB
@section('css') |
|
@parent |
|
<style> |
|
.modal-xl { |
|
max-width: 1140px; |
|
} |
|
</style> |
|
@stop |
|
|
|
@section('js') |
|
@parent |
|
<script> |
|
function roleEditPopUp(id) { |
|
// permission-check 是一個class 將所有的checkbox都取消勾選 |
|
$('.permission-check').prop('checked', false) |
|
$.ajax({ |
|
url: '/api/role/' + id, |
|
type: 'GET', |
|
dataType: 'json', |
|
success: function(res) { |
|
// console.log(res) |
|
$('#role_id_edit').val(res.role.id) |
|
$('#role_name_edit').val(res.role.display_name) |
|
|
|
// $('#permission-edit-{id}') 是一個input 將 id相等的checked |
|
$.each(res.role.permissions, function(index, value) { |
|
$('#permission-edit-' + value.id).prop('checked', true) |
|
}) |
|
$('#saveBtn').attr('onclick', `saveRole(${id})`) |
|
$('#roleEditPopUp').modal('show') |
|
}, |
|
error: function(err) { |
|
console.log(err) |
|
} |
|
}) |
|
|
|
} |
|
|
|
function saveRole(id) { |
|
// Get form data |
|
let formData = $("#roleEdit").serialize(); |
|
|
|
// Perform Ajax request |
|
$.ajax({ |
|
url: `/api/role/${id}`, // Replace with your actual endpoint |
|
type: "PUT", |
|
data: formData, |
|
success: function(response) { |
|
// Check response and show appropriate message |
|
if (response.success) { |
|
// Show success alert |
|
Swal.fire({ |
|
icon: 'success', |
|
title: 'Success', |
|
text: response.success |
|
}); |
|
// Close the modal |
|
$("#roleEditPopUp").modal("hide"); |
|
roleTable.ajax.reload(null, false); |
|
} else { |
|
// Show error alert with the error message |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: response.message |
|
}); |
|
} |
|
}, |
|
error: function(xhr, status, error) { |
|
// Show error alert with the error details |
|
Swal.fire({ |
|
icon: 'error', |
|
title: 'Error', |
|
text: 'An error occurred. Please try again.' |
|
}); |
|
} |
|
}); |
|
} |
|
</script> |
|
|
|
@endsection |
|
<!-- Modal --> |
|
|
|
<div class="modal fade" id="roleEditPopUp" tabindex="-1" aria-labelledby="roleEditPopUpLabel" aria-modal="true" |
|
role="dialog"> |
|
<div class="modal-dialog modal-xl"> |
|
<div class="modal-content"> |
|
<div class="modal-header"> |
|
<h5 class="modal-title h4" id="roleEditPopUpLabel">權限管理</h5> |
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
|
</div> |
|
<div class="modal-body"> |
|
<form id="roleEdit" class="row"> |
|
<input type="hidden" id="role_id_edit" name="id"> |
|
<!-- Your form fields here --> |
|
<div class="form-group col-12"> |
|
<label for="role_name_edit">群組名稱</label> |
|
<input type="text" class="form-control" id="role_name_edit" name="display_name"> |
|
</div> |
|
|
|
|
|
@foreach ($permissions as $idx => $item) |
|
<div class="col-3 mt-3 p-e-g-{{ $idx }}"> |
|
@foreach ($item as $permission) |
|
<div class="form-check checkbox-lg col-12"> |
|
<label class="form-check-label" |
|
for="permission-edit-{{ $permission->id }}">{{ $permission->display_name }}</label> |
|
<input class="form-check-input permission-check" type="checkbox" |
|
id="permission-edit-{{ $permission->id }}" name="permission[]" |
|
value="{{ $permission->id }}" /> |
|
</div> |
|
@endforeach |
|
</div> |
|
@endforeach |
|
|
|
<div class="form-group col-12 text-center mt-3"> |
|
<button type="button" class="btn btn-primary" onclick="saveRole()" id="saveBtn">更新</button> |
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button> |
|
</div> |
|
|
|
</form> |
|
</div> |
|
</div> |
|
</div> |
|
</div>
|
|
|