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.
269 lines
11 KiB
269 lines
11 KiB
@section('css') |
|
@parent |
|
<style> |
|
.modal-xl { |
|
max-width: 1140px; |
|
} |
|
</style> |
|
@stop |
|
|
|
@section('js') |
|
@parent |
|
<script> |
|
function userManagePopUp(id) { |
|
console.log(id) |
|
|
|
$.ajax({ |
|
url: '/api/user/' + id, |
|
type: 'GET', |
|
dataType: 'json', |
|
success: function(res) { |
|
// console.log(res) |
|
$('#id').val(res.user.id) |
|
$('#name').val(res.user.name) |
|
$('#class').val(res.user.class) |
|
$('#leader').val(res.user.leader) |
|
$('#exp_op').val(res.user.exp_op) |
|
$('#unit').val(res.user.unit) |
|
$('#account').val(res.user.account) |
|
$('#status').val(res.user.status) |
|
// $('#roles') 是一個select 將 res.roles中的每一個role.id當作value role.display_name當作名稱 塞入option中 並將res.user.roles[0].id = role.id 的先selected |
|
$('#roles').empty() |
|
$('#roles').append(`<option value="">請選擇群組</option>`) |
|
|
|
$.each(res.role, function(index, value) { |
|
$('#roles').append(`<option value="${value.id}">${value.display_name}</option>`) |
|
}) |
|
if (res.user.roles[0] == null) {} else { |
|
$('#roles').val(res.user.roles[0].id) |
|
} |
|
if (res.user.device == null) {} else { |
|
// 切割res.user.device 字串, 轉陣列 |
|
res.user.device = res.user.device.split(',') |
|
// 取消勾選所有checkbox |
|
$('input[name="device[]"]').prop('checked', false) |
|
$.each(res.user.device, function(index, value) { |
|
// console.log(value) |
|
// get element by input name and value |
|
// 並將其checked |
|
$(`input[name="device[]"][value="${value}"]`).prop('checked', true) |
|
}) |
|
|
|
|
|
} |
|
$('#saveBtn').attr('onclick', 'saveUser(' + id + ')') |
|
$('#password_reset').attr('onclick', 'resetPassword(' + id + ')') |
|
|
|
$('#userManagePopUp').modal('show') |
|
}, |
|
error: function(err) { |
|
console.log(err) |
|
} |
|
}) |
|
|
|
} |
|
|
|
function resetPasswordAjax(id) { |
|
// Perform Ajax request |
|
$.ajax({ |
|
url: `/api/user/${id}`, // Replace with your actual endpoint |
|
type: "PUT", |
|
data: { |
|
password_reset: 1, |
|
}, |
|
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 |
|
$("#myModal").modal("hide"); |
|
userManagerTable.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.' |
|
}); |
|
} |
|
}); |
|
} |
|
|
|
function resetPassword(id) { |
|
// 增加swal確認 |
|
Swal.fire({ |
|
title: '確定要重設密碼嗎?', |
|
text: "重設後將無法回復!", |
|
icon: 'warning', |
|
showCancelButton: true, |
|
confirmButtonColor: '#3085d6', |
|
cancelButtonColor: '#d33', |
|
confirmButtonText: '確定', |
|
cancelButtonText: '取消' |
|
}).then((result) => { |
|
if (result.isConfirmed) { |
|
resetPasswordAjax(id) |
|
} |
|
}) |
|
} |
|
|
|
function saveUser(id) { |
|
// Get form data |
|
let formData = $("#myForm").serialize(); |
|
|
|
// Perform Ajax request |
|
$.ajax({ |
|
url: `/api/user/${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 |
|
$("#myModal").modal("hide"); |
|
userManagerTable.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="userManagePopUp" tabindex="-1" aria-labelledby="userManagePopUpLabel" 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="userManagePopUpLabel">使用者管理</h5> |
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
|
</div> |
|
<div class="modal-body"> |
|
<form id="myForm" class="row"> |
|
<input type="hidden" id="id" name="id"> |
|
<!-- Your form fields here --> |
|
<div class="form-group col-4"> |
|
<label for="name">姓名</label> |
|
<input type="text" class="form-control" id="name" name="name"> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="class">職級</label> |
|
<input type="text" class="form-control" id="class" name="class"> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="leader">單位代碼</label> |
|
<input type="text" class="form-control" id="leader" name="leader"> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="exp_op">員警代碼</label> |
|
<input type="text" class="form-control" id="exp_op" name="exp_op"> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="account">帳號</label> |
|
<input type="text" class="form-control" id="account" name="account"> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="unit">單位</label> |
|
<select class="form-control" id="unit" name="unit"> |
|
@foreach (\App\Class\StaticData::$unit as $key => $label) |
|
<option value="{{ $key }}">{{ $label }}</option> |
|
@endforeach |
|
<!-- Add more options as needed --> |
|
</select> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="roles">管理群組</label> |
|
<select class="form-control" id="roles" name="role"> |
|
<!-- Add more options as needed --> |
|
</select> |
|
</div> |
|
|
|
<div class="form-group col-4"> |
|
<label for="status">帳號狀態</label> |
|
<select class="form-control" id="status" name="status"> |
|
<option value="0">啟用</option> |
|
<option value="1">停用</option> |
|
<!-- Add more options as needed --> |
|
</select> |
|
</div> |
|
<div class="form-group col-4"> |
|
<label for="password_reset">密碼重設</label> |
|
<button type="button" class="form-control btn btn-primary" id="password_reset">重設密碼</button> |
|
</div> |
|
<div class="form-group row"> |
|
<!-- Add more options as needed --> |
|
|
|
@foreach ($equipments as $key => $equipment) |
|
<div class="col-6 mt-3 p-c-g-{{ $key }}"> |
|
<div class="row"> |
|
<p>{{ $equipments_title[$key] }}</p> |
|
@foreach ($equipment as $key2 => $value) |
|
<div class="form-check checkbox-lg col-6"> |
|
<label class="form-check-label" |
|
for="equipment-manage-edit-{{ "$key-$value->id" }}">({{ $value->serialnumber }}) |
|
{{ $value->short_name }}</label> |
|
<input class="form-check-input permission-check {{ "$key" }}" |
|
type="checkbox" id="equipment-manage-edit-{{ "$key-$value->id" }}" |
|
name="device[]" value="{{ $value->serialnumber }}" /> |
|
</div> |
|
@endforeach |
|
</div> |
|
</div> |
|
@endforeach |
|
|
|
</div> |
|
<div class="form-group col-12 text-center mt-3"> |
|
<button type="button" class="btn btn-primary" id="saveBtn">儲存</button> |
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button> |
|
</div> |
|
|
|
</form> |
|
</div> |
|
</div> |
|
</div> |
|
</div>
|
|
|