Files
Backend-Api/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/ModalAddEmployeeToGroup.js
2024-12-03 15:40:11 +03:30

232 lines
6.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
$(document).ready(function () {
$('#createNewGroupLabel').text(titleOfGroup);
//******************** انتخاب چک باکس ********************
$('.items').click(function (e) {
if ($(e.target).is('input[type="checkbox"]')) {
return;
}
var checkbox = $(this).find('input[type="checkbox"]');
var isChecked = checkbox.is(":checked");
checkbox.prop('checked', !isChecked);
$(this).toggleClass('checked-item', !isChecked);
});
$('.items input[type="checkbox"]').click(function (e) {
e.stopPropagation();
var isChecked = $(this).is(":checked");
$(this).closest('.items').toggleClass('checked-item', isChecked);
});
$('.items label').click(function (e) {
e.stopPropagation();
var isChecked = $(this).is(":checked");
$(this).closest('.items').toggleClass('checked-item', isChecked);
});
//******************** انتخاب چک باکس ********************
//******************** انتخاب همه ی چک باکس ها ********************
$(".selectAll").change(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
if ($(this).is(":checked")) {
$('.items').addClass('checked-item');
} else {
$('.items').removeClass('checked-item');
}
});
//******************** انتخاب همه ی چک باکس ها ********************
$('.select2Position').select2({
placeholder: {
text: "انتخاب اعضاء ..."
}
});
$('#btn-add').on('click', function (e) {
e.preventDefault();
var idlist = "";
// if ($('.select2Position').select2('data').length > 0) {
if (($('input:checkbox').is(":checked"))) {
$('.foo').each(function () {
if ($(this).is(":checked")) {
var a = $(this).val();
var b = a + "+";
idlist += b;
}
});
$('#Accounts').val(idlist);
$.ajax({
async: false,
dataType: 'json',
type: 'POST',
url: '@Url.Page("./Group", "AddAccountToPosition")',
headers: { "RequestVerificationToken": $('@Html.AntiForgeryToken()').val() },
data: $('#create-form').serialize(),
success: function (response) {
if (response.isSuccedded) {
$("#groupName").val('');
$('.alert-success-msg').show();
$('.alert-success-msg p').text(response.message);
setTimeout(function () {
$('.alert-success-msg').hide();
$('.alert-success-msg p').text('');
window.location.replace('/AdminNew/Company/Task/Group');
}, 1500);
} 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);
}
});
} else {
$('.alert-msg').show();
$('.alert-msg p').text('لطفا شخصی برای ذخیره انتخاب کنید.');
$("#groupName").addClass('errored');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
$("#groupName").removeClass('errored');
}, 3500);
}
});
});
function searchMember() {
var input, filter, tbody, tr, a, i;
input = document.getElementById("search");
filter = input.value.toUpperCase();
tbody = document.getElementById("PersonnelList");
tr = tbody.getElementsByClassName("items");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByClassName("searchItem")[0];
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
LoadEmployeeAjax();
function LoadEmployeeAjax(parameters) {
var html = "";
$.ajax({
async: false,
contentType: 'charset=utf-8',
dataType: 'json',
type: 'GET',
url: loadEmployeeGroupAjax,
data: {
'rollCallWorkshopSettingId': workshopSettingId
},
headers: { "RequestVerificationToken": `${antiForgeryToken}` },
success: function (response) {
if (response.success) {
if (response.data.length > 0) {
response.data.forEach(function (item) {
html += `<div class="items">
<div class="from-group">
<input class="form-check-input foo" type="checkbox" name="employeeIds[]" id="select-${item.id}" value="${item.id}">
<label class="form-check-label searchItem" for="select-${item.id}">
${item.employeeFullName}
</label>
</div>
</div>`;
});
$('#PersonnelList').append(html);
$('#loadingSkeleton').hide();
}
else {
html += `<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>`;
$('#PersonnelList').append(html);
$('#loadingSkeleton').hide();
}
}
},
failure: function (response) {
console.log(5, response);
}
});
}
function saveEmployeeData() {
$('.btn-register').addClass('disable');
const employeeIds = [];
$('input[name="employeeIds[]"]:checked').each(function () {
employeeIds.push($(this).val());
});
const data = {
'command.EmployeeIds': employeeIds,
'command.GroupId': groupId,
'command.WorkshopSettingId': workshopSettingId
};
$.ajax({
async: false,
//contentType: 'charset=utf-8',
//dataType: 'json',
type: 'POST',
url: saveEmployeeToGroupAjax,
data: data,
headers: { "RequestVerificationToken": `${antiForgeryToken}` },
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('');
$('#MainModal').modal('toggle');
loadDataAjax();
}, 2000);
} else {
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3000);
$('.btn-register').removeClass('disable');
}
},
failure: function (response) {
console.log(5, response);
}
});
}