Files
Backend-Api/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/CameraAccounts.js

258 lines
14 KiB
JavaScript

$(document).ready(function () {
loadDataCameraAccountAjax();
});
$(document).on('click', ".openAction", function () {
if (window.matchMedia('(max-width: 768px)').matches) {
$(this).next().find(".operations-btns").slideToggle(500);
$(".operations-btns").not($(this).next().find(".operations-btns")).slideUp(500);
}
});
function loadDataCameraAccountAjax() {
var html = '';
$('#ajaxCameraAccountDataLoad').html('');
$.ajax({
async: false,
contentType: 'charset=utf-8',
dataType: 'json',
type: 'GET',
url: loadCameraAccountsAjax,
data: { workshopId: wpId },
headers: { "RequestVerificationToken": `${antiForgeryToken}` },
success: function (response) {
console.log(response.data);
if (response.data.length > 0) {
var n = 1;
var dataLoad = response.data;
dataLoad.forEach(function (item) {
html += `
<div></div>
<div class="Rtable-row align-items-center position-relative openAction">
<div class="Rtable-cell d-md-block d-flex width1">
<div class="Rtable-cell--content">
<span class="d-flex justify-content-center align-items-center justify-content-center">
${n}
</span>
</div>
</div>
<div class="Rtable-cell d-md-block d-flex width2">
<div class="Rtable-cell--content d-flex align-items-center text-start">
<div id="EmployeeFullName_${item.workshopId}">${item.workshopName}</div>
</div>
</div>
<div class="Rtable-cell d-md-block d-md-block d-sm-flex d-none width3">
<div class="Rtable-cell--content text-start">${item.username}</div>
</div>
<div class="Rtable-cell d-md-flex d-none justify-content-center width5">
<div class="Rtable-cell--content align-items-center d-flex d-md-flex text-end me-3">
<div class="d-flex align-items-center justify-content-center">
<span class="mx-1 df">فعال</span>
<label class="switch">
<input type="checkbox"
id="toggleCameraAccountPersonnelStatus_${item.id}_desktop"
${item.isActiveString === "true" ? `checked` : ``}
class="toggle-camera-account-switch-desktop btnAvticeActionCameraAccount_${item.accountId}">
<span class="sliderEUP"></span>
</label>
<span class="mx-1 df">غیر فعال</span>
</div>
</div>
</div>
<div class="Rtable-cell d-md-flex justify-content-end width6">
<div class="Rtable-cell--content align-items-center d-flex d-md-flex justify-content-end">
<button class="btn-pass ChangePassword d-none d-md-block" onclick="showModalCameraAccountChangePassword(${item.id})" id="CameraAccountChangePassword_${item.id}" type="button">
<span class="spanTxt d-none">تغییر گذرواژه</span>
<span class="spanSvg">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 5.25a3 3 0 0 1 3 3m3 0a6 6 0 0 1-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1 1 21.75 8.25Z" />
</svg>
</span>
</button>
<button type="button" class="btn-more position-relative d-md-none d-flex" style="width: 36px;padding: 0;height: 36px;align-items: center;justify-content: center;position: relative !important;">
<span class="mx-1 align-items-center d-flex justify-content-center"></span>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 16 16" fill="currentColor">
<circle cx="8.4001" cy="8.39922" r="1.2" transform="rotate(90 8.4001 8.39922)"/>
<circle cx="8.4001" cy="4.39922" r="1.2" transform="rotate(90 8.4001 4.39922)"/>
<circle cx="8.4001" cy="12.3992" r="1.2" transform="rotate(90 8.4001 12.3992)"/>
</svg>
</button>
</div>
</div>
</div>
<div class="operation-div w-100 d-block d-md-none">
<div class="operations-btns">
<div class="row p-0">
<div class="d-flex align-items-center justify-content-between my-1">
<span class="span1">نام حساب کاربری:</span>
<span class="span1">${item.username}</span>
</div>
<div class="d-flex align-items-center justify-content-between my-1">
<span class="span1">وضعیت:</span>
<div class="d-flex align-items-center justify-content-center">
<span class="span1 mx-1 df">فعال</span>
<label class="switch">
<input type="checkbox"
id="toggleCameraAccountPersonnelStatus_${item.id}_desktop"
${item.isActiveString === "true" ? `checked` : ``}
class="toggle-camera-account-switch-desktop btnAvticeActionCameraAccount_${item.employeeId}">
<span class="sliderEUP"></span>
</label>
<span class="span1 mx-1 df">غیر فعال</span>
</div>
</div>
<div class="col-md-12 col-12">
<button class="btn-upload me-1 ChangePhoneNumber d-none d-md-block" id="ChanePhoneNumber_${item.id}" type="button">
<span class="spanTxt">شماره تماس</span>
<span class="spanSvg">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 0 0 2.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 0 1-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 0 0-1.091-.852H4.5A2.25 2.25 0 0 0 2.25 4.5v2.25Z" />
</svg>
</span>
</button>
<button class="btn-pass ChangePassword w-100" onclick="showModalCameraAccountChangePassword(${item.id})" id="ChangePassword_${item.id}" type="button">
<span class="spanTxt">تغییر گذرواژه</span>
<span class="spanSvg">
<svg width="24" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 5.25a3 3 0 0 1 3 3m3 0a6 6 0 0 1-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1 1 21.75 8.25Z" />
</svg>
</span>
</button>
</div>
</div>
</div>
</div>
`;
n += 1;
});
$('#ajaxCameraAccountDataLoad').append(html);
$('#loadingSkeletonCameraAccount').hide();
} else {
html += `<div></div>
<div class="text-center bg-white d-flex align-items-center justify-content-center w-100">
<div class="">
<img src="/assetsclient/images/empty.png" alt="" class="img-fluid" />
<h5>اطلاعاتی وجود ندارد.</h5>
</div>
</div>`;
$('#ajaxCameraAccountDataLoad').html(html);
$('#loadingSkeletonCameraAccount').hide();
}
},
failure: function (response) {
console.log(response);
}
});
}
function showModalCameraAccountChangePassword(id) {
window.location.href = `#showmodal=/AdminNew/Company/RollCall/CameraAccounts?id=${id}&handler=ChangeCameraPassword`;
}
$(document).on('change', '.toggle-camera-account-switch-desktop, .toggle-camera-account-switch-mobile', function () {
var id = $(this).attr('id').split('_')[1];
var isActive = $(this).is(':checked') ? 'active' : 'deactive';
toggleCameraAccountStatus(id, isActive);
});
function toggleCameraAccountStatus(id, type) {
const toggleDesktop = $(`#toggleCameraAccountPersonnelStatus_${id}_desktop`);
const toggleMobile = $(`#toggleCameraAccountPersonnelStatus_${id}_mobile`);
if (type === "deactive") {
swal.fire({
title: "اخطار",
text: "آیا میخواهید غیر فعال نمائید؟",
icon: "warning",
showCancelButton: true,
confirmButtonText: "بله",
cancelButtonText: "خیر",
confirmButtonColor: '#84cc16',
reverseButtons: true
}).then((result) => {
if (result.isConfirmed) {
toggleCameraAccountStatusAjax(id, type);
} else {
toggleDesktop.prop('checked', true);
toggleMobile.prop('checked', true);
}
});
}
if (type === "active") {
swal.fire({
title: "اخطار",
text: "آیا میخواهید فعال نمائید؟",
icon: "warning",
showCancelButton: true,
confirmButtonText: "بله",
cancelButtonText: "خیر",
confirmButtonColor: '#84cc16',
reverseButtons: true
}).then((result) => {
if (result.isConfirmed) {
toggleCameraAccountStatusAjax(id, type);
} else {
toggleDesktop.prop('checked', false);
toggleMobile.prop('checked', false);
}
});
}
}
function toggleCameraAccountStatusAjax(id, type) {
$.ajax({
async: false,
dataType: 'json',
headers: { "RequestVerificationToken": antiForgeryToken },
url: changeCameraAccountStatusAjax,
type: 'POST',
data: { id: id, type: type },
success: function (response) {
if (response.success) {
$('.alert-success-msg').show();
$('.alert-success-msg p').text(response.message);
setTimeout(function () {
$('.alert-success-msg').hide();
$('.alert-success-msg p').text('');
}, 2500);
} else {
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3500);
}
},
error: function (err) {
console.log(err);
}
});
}