Files
Backend-Api/ServiceHost/wwwroot/AssetsClient/pages/CustomizeCheckout/js/ModalCheckoutUnofficialCreate.js

285 lines
9.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 () {
//$('.yearDropDown').click(function () {
// var value = $(this).data('value');
// $('#year-select').val(value);
//});
//$('.monthDropDown').click(function () {
// var value = $(this).data('value');
// $('#month-select').val(value);
//});
//Scrollbar.init(document.querySelector('.dropdown-global-content'), {
// alwaysShowTracks: true
//});
$("#next-step").on("click", function() {
loadEmployeesByYearAndMonthFunction();
});
$("#prev-step").on("click", function() {
$('#step-form1').show();
if ($('#step-form2').is(":hidden")) {
$("#MainModal").modal("hide");
}
$('#step-form2').hide();
$('#prev-step').text('انصراف');
$('#next-step').text('مرحله بعد');
$('#step-2').addClass('not-step');
});
$('.dropdown-year .item').on("click", function() {
let dataVal = $(this).attr("value-data-year");
$('#sendDropdownYear').val(dataVal);
});
$('.dropdown-month .item').on("click", function() {
let dataVal = $(this).attr("value-data-month");
$('#sendDropdownMonth').val(dataVal);
});
var sendDropdownYear = $("#sendDropdownYear").val();
if (sendDropdownYear) {
let itemDropdownYear = $(".dropdown-year").find(".item[value-data-year='" + sendDropdownYear + "']");
itemDropdownYear.addClass("active");
var selectedYearDisplay = $(".wrapper-dropdown-year").find(".selected-display");
selectedYearDisplay.text(itemDropdownYear.text());
}
var sendDropdownMonth = $("#sendDropdownMonth").val();
if (sendDropdownMonth) {
let itemDropdownMonth = $(".dropdown-month").find(".item[value-data-month='" + sendDropdownMonth + "']");
itemDropdownMonth.addClass("active");
var selectedMonthDisplay = $(".wrapper-dropdown-month").find(".selected-display");
selectedMonthDisplay.text(itemDropdownMonth.text());
}
/* سلکت شدن ماه جاری */
//const today = new Date();
//const jalaaliDate = jalaali.toJalaali(today.getFullYear(), today.getMonth(), today.getDate());
//const currentMonth = String(jalaaliDate.jm).padStart(2, '0');
const monthSelect = document.getElementById('month-select');
monthSelect.value = lastMonth;
/* سلکت شدن ماه جاری */
});
$(document).on('change', '.fooCreate, .checkAllCreate', function () {
const form = $("#step-form2");
$("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);
});
});
$('.btnCreateNew').click(function() {
var data = $('#create-form-unofficial').serialize();
if ($("#step-form2").is(":visible")) {
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');
$.ajax({
async: false,
dataType: 'json',
type: 'POST',
url: saveCheckoutUnofficialAjax,
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');
}
});
}
});
function loadEmployeesByYearAndMonthFunction()
{
var htmlTable = '';
$.ajax({
async: false,
dataType: 'json',
type: 'GET',
url: loadEmployeesByYearAndMonthAjax,
headers: { "RequestVerificationToken": antiForgeryToken },
data: {
year: $('#year-select').val(),
month: $('#month-select').val()
},
success: function (response) {
if (response.success) {
if (response.data.length > 0) {
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-unoff 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>`;
});
$('#step-form1').hide();
$('#step-form2').show();
$('#prev-step').text('مرحله قبل');
$('#next-step #textShowBtn').text('ثبت');
// $('#next-step').addClass('disable')
$('#step-2').removeClass('not-step');
}
$('#loadTableCheckout').html(htmlTable);
} 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);
}
});
}
$('#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');
});
//******************** انتخاب همه ی چک باکس ها ********************
$(".checkAllCreate").change(function () {
$('.fooCreate:checkbox').not(':disabled').prop('checked', this.checked);
});
//******************** انتخاب همه ی چک باکس ها ********************