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

500 lines
17 KiB
JavaScript

$(document).ready(function () {
$(".dateTime").each(function () {
new Cleave(this, {
time: true,
timePattern: ['h', 'm']
});
});
if (hasCamera && hasGroupWorkshop) {
$("#MainModal").modal("hide");
}
if (!hasCamera) {
if ($('#username').val() === '' && $('#signupInputPassword').val() === '' && $('#repeat_password').val() === '') {
$('#next-step').addClass('disable');
}
}
if (hasCamera && !hasGroupWorkshop) {
$('#step-form1 .row .ShowMessage').removeClass('d-none');
$('#ShowAccountMessage').text('شما از قبل اکانت ساخته اید.');
$('#step-form1').addClass('disable');
$('#step-form1').hide();
$('#step-form2').show();
$('#prev-step').text('مرحله قبل');
$('#next-step').text('ثبت');
$('#next-step').attr('onclick', 'registerAccount()');
$('#step-2').removeClass('not-step');
// برای نمایش وضعیت ساخت ساعت
$('#step_workTimeOption').hide();
}
if (!hasCamera && hasGroupWorkshop) {
$('#step-form2 .row .ShowMessage').removeClass('d-none');
$('#ShowSettingMessage').text('شما از قبل ساعات کاری را تنظیم کرده اید.');
$('#step-form2').addClass('disable');
}
$("#next-step").on("click", function () {
$('#step-form1').hide();
$('#step-form2').show();
$('#prev-step').text('مرحله قبل');
if ($('#step-form2').is(':visible')) {
$('#step_workTimeOption').hide();
$('.dateTime').each(function () {
if ($(this).val() === '') {
$('#next-step').addClass('disable');
}
});
}
$('#next-step').text('ثبت');
$('#next-step').attr('onclick', 'registerAccount()');
$('#step-2').removeClass('not-step');
});
$("#prev-step").on("click", function () {
$('#step-form1').show();
if ($('#step-form2').is(":hidden")) {
$("#MainModal").modal("hide");
}
$("#next-step").removeAttr("onclick");
$('#next-step').removeClass('disable');
$('#step-form2').hide();
$('#prev-step').text('انصراف');
$('#next-step').text('مرحله بعد');
$('#step-2').addClass('not-step');
});
$("#organized").on("click", function () {
$('#step_workTimeOption').show();
$('#step_workTimeOptionIrregular').hide();
if ($('#step-form2').is(':visible')) {
$('.dateTime').each(function () {
if ($(this).val() === '') {
$('#next-step').addClass('disable');
}
});
}
});
$("#disorganized").on("click", function () {
$('#step_workTimeOption').hide();
$('#step_workTimeOptionIrregular').show();
$('#next-step').removeClass('disable');
});
$(".btnAddTimeWork").on("click", function () {
var currentCount = $('.groupBox').length;
var $inputs = $('.dateTime');
var allFilled = true;
$inputs.each(function () {
if ($(this).val() === '') {
allFilled = false;
showAlert('ابتدا ساعت شروع و پایان را وارد نمائید.', $(this));
}
});
//validateAllTimes();
if (!allFilled) {
return false;
}
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-3 d-flex align-items-center">
<input type="hidden" name="CreateWorkshopSettings.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="CreateWorkshopSettings.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="CreateWorkshopSettings.ShiftsList[${currentCount}].EndTime" placeholder="00:00" style="direction: ltr;">
</div>
<div class="col-1 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="CreateWorkshopSettings.ShiftsList[${currentCount}].StartTime"]`, {
time: true,
timePattern: ['h', 'm']
});
new Cleave(`input[name="CreateWorkshopSettings.ShiftsList[${currentCount}].EndTime"]`, {
time: true,
timePattern: ['h', 'm']
});
updateAddButtonText(currentCount + 1);
if (currentCount + 1 === 3) {
$(".btnAddTimeWork").hide();
}
// Update Remove button enable/disable state
updateRemoveButtons();
}
});
$(document).on("click", ".btnRemoveTimeWork", function () {
$(this).closest(".groupBox").remove();
var currentCount = $('.groupBox').length;
updateAddButtonText(currentCount);
if (currentCount < 3) {
$(".btnAddTimeWork").show();
}
});
});
function updateRemoveButtons() {
$(".btnRemoveTimeWork").addClass("disable");
$(".btnRemoveTimeWork").last().removeClass("disable");
}
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);
}
} 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)$/;
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;
// }
// }
// }
//}
//******************** برای نوشتن تاریخ ********************
var eyeShow = $('.eyeShow');
var eyeClose = $('.eyeClose');
var reEyeShow = $('.reEyeShow');
var reEyeClose = $('.reEyeClose');
eyeShow.show();
eyeClose.hide();
reEyeShow.show();
reEyeClose.hide();
$("#username").on("input", function () {
var currentValue = $(this).val();
$(this).val(currentValue.replace(/[^a-zA-Z0-9_\-\$\#\@\!\^\&\%\*]/g, ''));
});
$('#username, #signupInputPassword, #repeat_password').on('keyup', function () {
if ($('#username').val() && $('#signupInputPassword').val() && $('#repeat_password').val() && $('#signupInputPassword').val() === $('#repeat_password').val()) {
$('#next-step').removeClass('disable');
} else {
$('#next-step').addClass('disable');
}
});
$('#repeat_password').on('keyup', function () {
if ($('#signupInputPassword').val() !== $('#repeat_password').val()) {
$('#passwordErrorMessage').text('گذرواژه یکسان نیست');
} else {
$('#passwordErrorMessage').text('');
}
});
$(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);
}
});
}