Files
Backend-Api/ServiceHost/wwwroot/AssetsClient/pages/CustomizeCheckout/js/ModalCheckoutTemporaryCreate.js
2025-01-04 20:11:47 +03:30

238 lines
7.6 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 () {
loadEmployeesByDay(day);
$('.dropdown-global-item').click(function () {
var selectedItem = $(this).text();
$('#day-select').val(selectedItem);
loadEmployeesByDay(selectedItem);
});
Scrollbar.init(document.querySelector('.dropdown-global-content'), {
alwaysShowTracks: true
});
});
$(document).on('change', '.foo', function () {
const form = $("#employeeLists");
$("input.foo-remove").remove();
$(".foo:checked").each(function () {
const value = $(this).val();
$("<input>")
.attr("type", "hidden")
.attr("name", "EmployeeId")
.attr("class", "foo-remove")
.val(value)
.appendTo(form);
});
});
function loadEmployeesByDay(day) {
var htmlTable = '';
$.ajax({
async: false,
contentType: 'charset=utf-8',
dataType: 'json',
type: 'GET',
url: loadEmployeesByDayAjax,
data: {
day: Number(day)
},
headers: { "RequestVerificationToken": antiForgeryToken },
success: function (response) {
if (response.success) {
if (response.data.length > 0) {
$('.btnCreateNew').removeClass('disable');
htmlTable += `<div></div>`;
response.data.forEach(function(item, index) {
index++;
valueColor = '';
switch (item.color) {
case "green":
valueColor = "greenStatus";
break;
case "red":
valueColor = "redStatus";
break;
case "orange":
valueColor = "orangeStatus";
break;
default:
valueColor = "";
break;
}
htmlTable += `
<div class="Rtable-row align-items-center position-relative checkout-temp openAction employee-row ${
valueColor}">
<div class="Rtable-cell width1">
<div class="Rtable-cell--heading d-none">
ردیف
</div>
<label for="Employee_ID_${index}" class="Rtable-cell--content prevent-select">
<span class="d-flex align-items-center justify-content-between gap-1">
<input id="Employee_ID_${index
}" type="checkbox" class="form-check-input fooCreate" name="fooCreate" value="${item.id}" ${
item.isEligible === false ? "disabled" : ""}>
<span class="w-100 text-center">${index}</span>
</span>
</label>
</div>
<div class="Rtable-cell width2">
<div class="Rtable-cell--heading d-none">نام پرسنل</div>
<div class="Rtable-cell--content text-start employee-name">
${item.name}
</div>
</div>
<div class="Rtable-cell width3">
<div class="Rtable-cell--content text-center">
<div class="d-md-none d-none">وضعیت: </div>
<div class="d-flex justify-content-center">${item.reason}</div>
</div>
</div>
<div class="Rtable-cell width4">
<div class="Rtable-cell--content text-center">
<div class="d-md-none d-none">شماره پرسنلی: </div>
<div class="d-flex justify-content-center">${item.personnelCode}</div>
</div>
</div>
</div>`;
});
$('#loadTableCheckout').html(htmlTable);
}
} else {
$('.btnCreateNew').addClass('disable');
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3500);
}
},
failure: function (response) {
$('#MainModal').modal('hide');
console.log(5, response);
}
});
}
$('#search').on('keyup', function () {
let searchValue = $(this).val().toLowerCase();
$('.employee-row').filter(function () {
$(this).toggle($(this).find('.employee-name').text().toLowerCase().includes(searchValue));
});
updateIndexes();
if ($(this).val().length > 0) {
$('#clear-search').removeClass('d-none').addClass('d-flex');
} else {
$('#clear-search').removeClass('d-flex').addClass('d-none');
}
});
$('#clear-search').on('click', function () {
$('#search').val('');
$('.employee-row').show();
updateIndexes();
$(this).removeClass('d-flex').addClass('d-none');
});
//******************** انتخاب همه ی چک باکس ها ********************
$(document).on('change', '.fooCreate, .checkAllCreate', function () {
const form = $("#create-form-temporary");
$("input.foo-remove").remove();
$(".fooCreate:checked").each(function () {
const value = $(this).val();
$("<input>")
.attr("type", "hidden")
.attr("name", "EmployeeIds[]")
.attr("class", "foo-remove")
.val(value)
.appendTo(form);
});
});
$(".checkAllCreate").change(function () {
$('.fooCreate:checkbox').not(':disabled').prop('checked', this.checked);
});
//******************** انتخاب همه ی چک باکس ها ********************
function saveCheckoutTemporary() {
if ($(".fooCreate:checked").length === 0) {
$('.alert-msg').show();
$('.alert-msg p').text('لطفا یک یا چند پرسنل را انتخاب کنید');
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3500);
return;
}
var loading = $('.btnCreateNew .loading');
loading.show();
$('.btnCreateNew').addClass('disable');
var data = $('#create-form-temporary').serialize();
$.ajax({
async: false,
dataType: 'json',
type: 'POST',
url: saveCheckoutTemporaryAjax,
headers: { "RequestVerificationToken": antiForgeryToken },
data: data,
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('');
loading.hide();
window.location.reload();
}, 1500);
} else {
$('.alert-msg').show();
$('.alert-msg p').text(response.message);
setTimeout(function () {
$('.alert-msg').hide();
$('.alert-msg p').text('');
}, 3500);
loading.hide();
$('.btnCreateNew').removeClass('disable');
}
},
error: function (err) {
console.log(err);
loading.hide();
$('.btnCreateNew').removeClass('disable');
}
});
}