570 lines
19 KiB
JavaScript
570 lines
19 KiB
JavaScript
$(document).ready(function () {
|
||
$('.form-control-percent').on('keydown', function (e) {
|
||
const allowedKeys = [
|
||
'Backspace', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight',
|
||
'ArrowUp', 'ArrowDown', 'Delete', 'Home', 'End'
|
||
];
|
||
|
||
if (allowedKeys.includes(e.key) || (e.key === 'a' && (e.ctrlKey || e.metaKey))) {
|
||
return;
|
||
}
|
||
|
||
const persianNumbers = /[۰-۹]/;
|
||
const arabicNumbers = /[٠-٩]/;
|
||
|
||
if (persianNumbers.test(e.key) || arabicNumbers.test(e.key)) {
|
||
e.preventDefault();
|
||
const englishDigit = convertPersianNumbersToEnglish(e.key);
|
||
const currentValue = $(this).val();
|
||
$(this).val(currentValue + englishDigit);
|
||
return;
|
||
}
|
||
|
||
if (!/^\d$/.test(e.key)) {
|
||
e.preventDefault();
|
||
}
|
||
});
|
||
|
||
$(".form-control-currency").each(function () {
|
||
let element = $(this);
|
||
|
||
element.on('input', function () {
|
||
let value = convertPersianNumbersToEnglish(element.val());
|
||
element.val(value);
|
||
});
|
||
|
||
new Cleave(this, {
|
||
numeral: true,
|
||
numeralThousandsGroupStyle: 'thousand'
|
||
});
|
||
});
|
||
|
||
$(".dateTime").each(function () {
|
||
let element = $(this);
|
||
|
||
element.on('input', function () {
|
||
let value = convertPersianNumbersToEnglish(element.val());
|
||
element.val(value);
|
||
});
|
||
|
||
new Cleave(this, {
|
||
time: true,
|
||
timePattern: ['h', 'm']
|
||
});
|
||
});
|
||
|
||
//----------------------- Radio Group -----------------------
|
||
//$('.Sub-Radio, .sub-input').prop('disabled', true);
|
||
|
||
$('.Main-Radio').on('change', function () {
|
||
var $currentGroupContainer = $(this).closest('.group-container');
|
||
var $currentGroupInput = $(this).closest('.group');
|
||
|
||
// Clear previous selections
|
||
$currentGroupContainer.find('.Sub-Radio').prop('checked', false).prop('disabled', true);
|
||
$currentGroupContainer.find('.sub-input').val('').prop('disabled', true);
|
||
$currentGroupInput.find('.sub-input').first().prop('disabled', false).focus();
|
||
|
||
// Disable all main checkboxes except the current one
|
||
$currentGroupContainer.find('.main-checkbox').prop('checked', false);
|
||
|
||
var $currentGroup = $(this).closest('.group');
|
||
|
||
|
||
if (!$(this).hasClass('main-checkbox')) {
|
||
$currentGroupContainer.find('.main-checkbox').prop('checked', false);
|
||
} else {
|
||
$currentGroupContainer.find('.main-checkbox').prop('checked', true);
|
||
$currentGroupContainer.find('.main-checkbox').not(this).prop('checked', false);
|
||
|
||
if ($(this).is(':checked')) {
|
||
$currentGroup.find('.Sub-Radio').prop('disabled', false);
|
||
|
||
var $firstSubRadio = $currentGroup.find('.Sub-Radio').first();
|
||
$firstSubRadio.prop('checked', true);
|
||
$firstSubRadio.closest('div').find('.sub-input').prop('disabled', false).focus();
|
||
}
|
||
}
|
||
});
|
||
|
||
$('.Sub-Radio').on('change', function () {
|
||
var $currentSubGroup = $(this).closest('.sub-group');
|
||
|
||
$currentSubGroup.find('.sub-input').val('').prop('disabled', true);
|
||
|
||
if ($(this).is(':checked')) {
|
||
// $(this).next('.sub-input').prop('disabled', false);
|
||
$(this).closest('div').find('.sub-input').prop('disabled', false).focus();
|
||
}
|
||
});
|
||
});
|
||
|
||
$(document).ready(function () {
|
||
//******************** انتخاب چک باکس ********************
|
||
$('#AbsentPenaltyAll').on('change', function () {
|
||
var isChecked = $(this).is(':checked');
|
||
$('input[name="AbsentPenaltyDays"]').not('#AbsentPenaltyAll').prop('checked', isChecked);
|
||
});
|
||
|
||
$('input[name="AbsentPenaltyDays"]').not('#AbsentPenaltyAll').on('change', function () {
|
||
var allChecked = $('input[name="AbsentPenaltyDays"]').not('#AbsentPenaltyAll').length ===
|
||
$('input[name="AbsentPenaltyDays"]:checked').not('#AbsentPenaltyAll').length;
|
||
$('#AbsentPenaltyAll').prop('checked', allChecked);
|
||
});
|
||
//******************** انتخاب چک باکس ********************
|
||
|
||
$('.spinner-loading').hide();
|
||
});
|
||
|
||
$(document).ready(function () {
|
||
$('.current').each(function () {
|
||
var targetForm = $(this).data('target');
|
||
$('#' + targetForm).show();
|
||
});
|
||
|
||
$('.sidebarRollCallMenu ul li').click(function () {
|
||
$('.form-section').hide();
|
||
|
||
$('.sidebarRollCallMenu ul li').removeClass('current');
|
||
|
||
$(this).addClass('current');
|
||
$('#rollCallSettingModalHead').text($(this).find('span').text());
|
||
|
||
var targetForm = $(this).data('target');
|
||
|
||
$('#' + targetForm).show();
|
||
});
|
||
|
||
$(".btnAddTimeWork").on("click", function () {
|
||
var currentCount = $('.groupBox').length;
|
||
|
||
if (currentCount < 3) {
|
||
var namePlacement = "";
|
||
var namePlacementPersian = "";
|
||
|
||
switch (currentCount + 1) {
|
||
case 2:
|
||
namePlacement = "Second";
|
||
namePlacementPersian = "دوم";
|
||
break;
|
||
case 3:
|
||
namePlacement = "Third";
|
||
namePlacementPersian = "سوم";
|
||
break;
|
||
default:
|
||
}
|
||
|
||
var timeWorkHtml = `
|
||
<div class="groupBox timeWork">
|
||
<div class="row align-items-center justify-content-between">
|
||
<div class="col-2 d-flex align-items-center">
|
||
<input type="hidden" name="Command.ShiftsList[${currentCount}].Placement" value="${namePlacement}" />
|
||
<div class="timeWorkTitle">نوبت ${namePlacementPersian}</div>
|
||
</div>
|
||
<div class="col-4 d-flex align-items-center">
|
||
<div class="timeWorkTitle">از</div>
|
||
<input type="text" class="form-control text-center dateTime" name="Command.ShiftsList[${currentCount}].StartTime" placeholder="00:00" style="direction: ltr;"/>
|
||
</div>
|
||
<div class="col-4 d-flex align-items-center">
|
||
<div class="timeWorkTitle">الی</div>
|
||
<input type="text" class="form-control text-center dateTime" name="Command.ShiftsList[${currentCount}].EndTime" placeholder="00:00" style="direction: ltr;"/>
|
||
</div>
|
||
<div class="col-2 d-flex align-items-center justify-content-end">
|
||
<button type="button" class="btnRemoveTimeWork">
|
||
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||
<circle cx="11" cy="11" r="8.25" stroke="white"/>
|
||
<path d="M6.875 11H15.125" stroke="white"/>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>`;
|
||
|
||
$('#appendChildTimeWorkHtml').append(timeWorkHtml);
|
||
|
||
new Cleave(`input[name="Command.ShiftsList[${currentCount}].StartTime"]`, {
|
||
time: true,
|
||
timePattern: ['h', 'm']
|
||
});
|
||
|
||
new Cleave(`input[name="Command.ShiftsList[${currentCount}].EndTime"]`, {
|
||
time: true,
|
||
timePattern: ['h', 'm']
|
||
});
|
||
|
||
updateAddButtonText(currentCount + 1);
|
||
|
||
if (currentCount + 1 === 3) {
|
||
$(".btnAddTimeWork").hide();
|
||
}
|
||
}
|
||
});
|
||
$(document).on("click", ".btnRemoveTimeWork", function () {
|
||
$(this).closest(".groupBox").remove();
|
||
var currentCount = $('.groupBox').length;
|
||
|
||
updateAddButtonText(currentCount);
|
||
|
||
if (currentCount < 3) {
|
||
$(".btnAddTimeWork").show();
|
||
}
|
||
});
|
||
});
|
||
//updateAddButtonText(1);
|
||
function updateAddButtonText(currentCount) {
|
||
if (currentCount === 1) {
|
||
$('.btnAppendChildTimeWork').text('افزودن نوبت دوم');
|
||
} else if (currentCount === 2) {
|
||
$('.btnAppendChildTimeWork').text('افزودن نوبت سوم');
|
||
}
|
||
|
||
let allFilled = true;
|
||
$('.dateTime').each(function () {
|
||
const value = $(this).val().trim();
|
||
if (value === "" || !timeValidCheck(value)) {
|
||
allFilled = false;
|
||
return false; // Break the loop
|
||
}
|
||
});
|
||
|
||
if (allFilled) {
|
||
$('.btn-register').removeClass('disable');
|
||
} else {
|
||
$('.btn-register').addClass('disable');
|
||
}
|
||
}
|
||
|
||
//******************** برای نوشتن تاریخ ********************
|
||
|
||
//$(document).on('input', ".dateTime", function () {
|
||
// var value = $(this).val();
|
||
// $(this).val(convertPersianNumbersToEnglish(value)).mask("00:00");
|
||
//});
|
||
|
||
$(document).on('keyup', ".dateTime", function () {
|
||
let $input = $(this);
|
||
let value = $input.val();
|
||
let lengthValue = value.length;
|
||
let currentCount = $('.groupBox').length;
|
||
|
||
if (lengthValue >= 5) {
|
||
if (!timeValidCheck(value)) {
|
||
showAlert('ساعت را به درستی وارد نمائید', $input);
|
||
updateAddButtonText(currentCount);
|
||
} else {
|
||
clearAlert($input);
|
||
validateAllTimes();
|
||
updateAddButtonText(currentCount);
|
||
|
||
focusNextTimeInput($input);
|
||
}
|
||
} else {
|
||
updateAddButtonText(currentCount);
|
||
}
|
||
});
|
||
|
||
function showAlert(message, inputElement) {
|
||
inputElement.addClass("errored");
|
||
$('.alert-msg').show().find('p').text(message);
|
||
setTimeout(function () {
|
||
clearAlert(inputElement);
|
||
}, 3500);
|
||
}
|
||
|
||
function clearAlert(inputElement) {
|
||
inputElement.removeClass("errored");
|
||
$('.alert-msg').hide().find('p').text('');
|
||
}
|
||
|
||
function timeValidCheck(value) {
|
||
const timePattern = /^([01]\d|2[0-3]):([0-5]\d)$/; // Validates HH:mm format
|
||
return timePattern.test(value);
|
||
}
|
||
|
||
function validateAllTimes() {
|
||
let timeRanges = [];
|
||
|
||
$(".groupBox").each(function () {
|
||
let startTime = $(this).find('input[name*="StartTime"]').val();
|
||
let endTime = $(this).find('input[name*="EndTime"]').val();
|
||
|
||
if (startTime.length === 5 && endTime.length === 5) {
|
||
let startParts = startTime.split(':');
|
||
let endParts = endTime.split(':');
|
||
let startInMinutes = parseInt(startParts[0]) * 60 + parseInt(startParts[1]);
|
||
let endInMinutes = parseInt(endParts[0]) * 60 + parseInt(endParts[1]);
|
||
timeRanges.push({ start: startInMinutes, end: endInMinutes });
|
||
}
|
||
});
|
||
|
||
// Check for conflicts and order
|
||
for (let i = 0; i < timeRanges.length; i++) {
|
||
for (let j = 0; j < i; j++) {
|
||
if (timeRanges[i].start >= timeRanges[i].end) {
|
||
showAlert('زمان شروع باید قبل از زمان پایان باشد', $(".groupBox").eq(i).find('input[name*="StartTime"]'));
|
||
return;
|
||
}
|
||
|
||
// Check for overlap with previous entries
|
||
if (timeRanges[i].start < timeRanges[j].end && timeRanges[i].end > timeRanges[j].start) {
|
||
showAlert('زمانها نباید تداخل داشته باشند', $(".groupBox").eq(i).find('input[name*="StartTime"]'));
|
||
return;
|
||
}
|
||
// Check if the current start time is before the previous start time
|
||
if (i > 0 && timeRanges[i].start < timeRanges[i - 1].start) {
|
||
showAlert('ساعت جدید نباید کوچکتر از ساعتهای قبلی باشد', $(".groupBox").eq(i).find('input[name*="StartTime"]'));
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function focusNextTimeInput(currentInput) {
|
||
var inputs = $(".dateTime");
|
||
var currentIndex = inputs.index(currentInput);
|
||
|
||
if (currentIndex !== -1 && currentIndex < inputs.length - 1) {
|
||
$(inputs[currentIndex + 1]).focus();
|
||
}
|
||
}
|
||
//******************** برای نوشتن تاریخ ********************
|
||
|
||
var eyeShow = $('.eyeShow');
|
||
var eyeClose = $('.eyeClose');
|
||
var reEyeShow = $('.reEyeShow');
|
||
var reEyeClose = $('.reEyeClose');
|
||
eyeShow.show();
|
||
eyeClose.hide();
|
||
reEyeShow.show();
|
||
reEyeClose.hide();
|
||
|
||
$(document).on('click', '#accountModalModal button', function () {
|
||
|
||
// alert($(this));
|
||
// $(this).find('input').type ? 'text' : 'password';
|
||
// document.getElementById('hybrid').type = 'password';
|
||
$("#accountModalModal button").find('input').attr("type", "text");
|
||
|
||
|
||
// var input=document.getElementById(some-id);
|
||
// var input2= input.cloneNode(false);
|
||
// input2.type='password';
|
||
// input.parentNode.replaceChild(input2,input);
|
||
});
|
||
|
||
function passFunction() {
|
||
var x = document.getElementById("signupInputPassword");
|
||
|
||
if (x.type === "password") {
|
||
x.type = "text";
|
||
eyeShow.hide();
|
||
eyeClose.show();
|
||
} else {
|
||
x.type = "password";
|
||
eyeShow.show();
|
||
eyeClose.hide();
|
||
}
|
||
}
|
||
|
||
function rePassFunction() {
|
||
var x = document.getElementById("repeat_password");
|
||
|
||
if (x.type === "password") {
|
||
x.type = "text";
|
||
reEyeShow.hide();
|
||
reEyeClose.show();
|
||
} else {
|
||
x.type = "password";
|
||
reEyeShow.show();
|
||
reEyeClose.hide();
|
||
}
|
||
}
|
||
|
||
function passwordCheck(password) {
|
||
if (password.length >= 8)
|
||
strength += 1;
|
||
if (password.match(/(?=.*[0-9])/))
|
||
strength += 1;
|
||
if (password.match(/(?=.*[!,%,&,@,#,$,^,*,?,_,~,<,>,])/))
|
||
strength += 1;
|
||
if (password.match(/(?=.*[A-Z])/))
|
||
strength += 1;
|
||
|
||
displayBar(strength);
|
||
}
|
||
|
||
function displayBar(strength) {
|
||
$(".password-strength-group").attr('data-strength', strength);
|
||
}
|
||
|
||
$("#signupInputPassword").keyup(function () {
|
||
strength = 0;
|
||
var password = $(this).val();
|
||
passwordCheck(password);
|
||
});
|
||
|
||
$(document).ready(function () {
|
||
var typingTimer;
|
||
var typingInterval = 1500;
|
||
|
||
$("#username").on('keyup', function () {
|
||
clearTimeout(typingTimer);
|
||
var username = $('#username').val();
|
||
|
||
if (username.length >= 6) {
|
||
$('#successSvg').addClass("d-none");
|
||
$('#errorSvg').addClass("d-none");
|
||
$('#loadingSpinner').removeClass("d-none");
|
||
|
||
typingTimer = setTimeout(function () {
|
||
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: checkAccountAjax,
|
||
data: { username: username },
|
||
success: function (response) {
|
||
$('#loadingSpinner').addClass("d-none");
|
||
|
||
if (response.success) {
|
||
$('#errorSvg').addClass("d-none");
|
||
$('#successSvg').removeClass("d-none");
|
||
$('.alert-success-msg').show();
|
||
$('.alert-success-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
$('.alert-success-msg').hide();
|
||
$('.alert-success-msg p').text('');
|
||
}, 2000);
|
||
} else {
|
||
$('#successSvg').addClass("d-none");
|
||
$('#errorSvg').removeClass("d-none");
|
||
$('.alert-msg').show();
|
||
$('.alert-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
$('.alert-msg').hide();
|
||
$('.alert-msg p').text('');
|
||
}, 2000);
|
||
}
|
||
},
|
||
error: function (err) {
|
||
$('#loadingSpinner').addClass("d-none");
|
||
console.log(err);
|
||
}
|
||
});
|
||
}, typingInterval);
|
||
} else {
|
||
$('.alert-msg').show();
|
||
$('.alert-msg p').text("نام کاربری حداقل باید 6 حرف باشد");
|
||
setTimeout(function () {
|
||
$('.alert-msg').hide();
|
||
$('.alert-msg p').text('');
|
||
}, 4000);
|
||
$('#loadingSpinner').addClass("d-none");
|
||
$('#successSvg').addClass("d-none");
|
||
$('#errorSvg').removeClass("d-none");
|
||
}
|
||
});
|
||
});
|
||
|
||
function registerAccount() {
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: saveCameraAccountAndWorkshopSettingAjax,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
data: $('#create-form').serialize(),
|
||
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('');
|
||
}, 3500);
|
||
window.location.reload();
|
||
} 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);
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
$('#saveRollCallButton').on('click', saveRollCallSettingAjax);
|
||
function saveRollCallSettingAjax() {
|
||
var isValid = true;
|
||
var loading = $('#saveRollCallButton').next('.spinner-loading');
|
||
|
||
$('#create-form').find('.sub-input, select').each(function () {
|
||
if (!$(this).prop('disabled') && !$(this).val()) {
|
||
isValid = false;
|
||
$(this).addClass('errored');
|
||
$('.alert-msg').show();
|
||
$('.alert-msg p').text('لطفا جای خالی تنظیمات را پر نمائید');
|
||
setTimeout(function () {
|
||
$('.alert-msg').hide();
|
||
$('.alert-msg p').text('');
|
||
}, 3500);
|
||
return false;
|
||
} else {
|
||
$(this).removeClass('error');
|
||
}
|
||
});
|
||
|
||
if (!isValid) {
|
||
return;
|
||
}
|
||
|
||
var data = $('#create-form').serialize();
|
||
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
url: saveWorkshopSetting,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
data: data ,
|
||
success: function (response) {
|
||
if (response.isSuccess) {
|
||
isSettingChangedGlobal = true;
|
||
|
||
loading.show();
|
||
$('.alert-success-msg').show();
|
||
$('.alert-success-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
//window.location.reload();
|
||
$('#MainModal').modal('hide');
|
||
loadDataAjax();
|
||
}, 800);
|
||
|
||
setTimeout(function () {
|
||
$('.alert-success-msg').hide();
|
||
$('.alert-success-msg p').text('');
|
||
loading.hide();
|
||
}, 3500);
|
||
} else {
|
||
$('.alert-msg').show();
|
||
$('.alert-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
$('.alert-msg').hide();
|
||
$('.alert-msg p').text('');
|
||
loading.hide();
|
||
}, 3500);
|
||
}
|
||
},
|
||
error: function (err) {
|
||
loading.hide();
|
||
console.log(err);
|
||
}
|
||
});
|
||
} |