409 lines
12 KiB
JavaScript
409 lines
12 KiB
JavaScript
|
|
$(".select2OptionWorkshop").select2({
|
|
language: "fa",
|
|
dir: "rtl",
|
|
dropdownParent: $('#MainModal'),
|
|
templateResult: function (data, container) {
|
|
if (data.element) {
|
|
$(container).addClass($(data.element).attr("class"));
|
|
}
|
|
return data.text;
|
|
}
|
|
});
|
|
|
|
$(".select2OptionRole").select2({
|
|
language: "fa",
|
|
dir: "rtl",
|
|
dropdownParent: $('#MainModal'),
|
|
templateResult: function (data, container) {
|
|
if (data.element) {
|
|
$(container).addClass($(data.element).attr("class"));
|
|
}
|
|
return data.text;
|
|
}
|
|
});
|
|
|
|
|
|
$(document).ready(function() {
|
|
ajaxWorkshops();
|
|
ajaxRoles();
|
|
});
|
|
|
|
function ajaxWorkshops() {
|
|
$.ajax({
|
|
url: workshopListAjax,
|
|
type: 'GET',
|
|
success: function (response) {
|
|
if (response.success) {
|
|
var items = response.data;
|
|
var itemOptionsHtml = '<option value="0" disabled>انتخاب کارگاه ...</option>';
|
|
items.forEach(function (item) {
|
|
itemOptionsHtml += `<option value="${item.id}">${item.name}</option>`;
|
|
});
|
|
$('#workshopSelect').html(itemOptionsHtml);
|
|
} else {
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text(response.message);
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
}, 3500);
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
function ajaxRoles() {
|
|
$.ajax({
|
|
url: roleListAjax,
|
|
type: 'GET',
|
|
success: function (response) {
|
|
if (response.success) {
|
|
var items = response.data;
|
|
var itemOptionsHtml = '<option value="0" selected>انتخاب نقش ...</option>';
|
|
items.forEach(function (item) {
|
|
itemOptionsHtml += `<option value="${item.id}">${item.title}</option>`;
|
|
});
|
|
$('#roleSelect').html(itemOptionsHtml);
|
|
} else {
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text(response.message);
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
}, 3500);
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
$('#PhoneNumber').on('input', function () {
|
|
var value = $(this).val();
|
|
|
|
value = value.replace(/[^0-9]/g, '');
|
|
|
|
if (value.length > 11) {
|
|
value = value.substring(0, 11);
|
|
}
|
|
$(this).val(value);
|
|
});
|
|
|
|
$('#NationalCode').on('input', function () {
|
|
var value = $(this).val();
|
|
|
|
value = value.replace(/\D/g, '');
|
|
|
|
if (value.length > 10) {
|
|
value = value.substring(0, 10);
|
|
}
|
|
$(this).val(value);
|
|
});
|
|
|
|
$('#NationalCode ').on('keyup', function () {
|
|
var nationalCodeValue = $('#NationalCode ').val();
|
|
|
|
if ($('#NationalCode ').val().length === 10) {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: loadNationalCodeAjax,
|
|
data: { nationalCode: nationalCodeValue },
|
|
success: function (response) {
|
|
if (response.success) {
|
|
if (response.data.fName != null) {
|
|
$('#FName ').val(response.data.fName);
|
|
$('#LName ').val(response.data.lName);
|
|
}
|
|
} else {
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text(response.message);
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
}, 3500);
|
|
}
|
|
},
|
|
error: function (err) {
|
|
loading.hide();
|
|
console.log(err);
|
|
}
|
|
});
|
|
}
|
|
//else {
|
|
// $('#FName ').val('');
|
|
// $('#LName ').val('');
|
|
//}
|
|
});
|
|
|
|
$("#Username").on("input", function () {
|
|
var currentValue = $(this).val();
|
|
|
|
if (/[^a-zA-Z0-9_\-\$\#\@\!\^\&\%\*]/.test(currentValue)) {
|
|
$('#Username').addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('فقط حروف انگلیسی، اعداد و علائم خاص _-$#@!^&%* مجاز هستند.');
|
|
|
|
setTimeout(function () {
|
|
$('#Username').removeClass('errored');
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
}, 3500);
|
|
|
|
$(this).val(currentValue.replace(/[^a-zA-Z0-9_\-\$\#\@\!\^\&\%\*]/g, ''));
|
|
} else {
|
|
$('#Username').removeClass('errored');
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
}
|
|
});
|
|
|
|
|
|
var eyeShow = $('.eyeShow');
|
|
var eyeClose = $('.eyeClose');
|
|
eyeShow.show();
|
|
eyeClose.hide();
|
|
|
|
function passFunction() {
|
|
var x = document.getElementById("Password");
|
|
|
|
if (x.type === "password") {
|
|
x.type = "text";
|
|
eyeShow.hide();
|
|
eyeClose.show();
|
|
} else {
|
|
x.type = "password";
|
|
eyeShow.show();
|
|
eyeClose.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);
|
|
}
|
|
|
|
$("#Password").keyup(function () {
|
|
strength = 0;
|
|
var password = $(this).val();
|
|
passwordCheck(password);
|
|
});
|
|
|
|
|
|
//document.getElementById("fileInput").addEventListener("change", function () {
|
|
// const fileInput = this;
|
|
// const loadingSpinner = document.getElementById("loadingSpinner");
|
|
// const previewImage = document.getElementById("previewImage");
|
|
// const deleteButton = document.getElementById("deleteButton");
|
|
|
|
// // نمایش لودینگ و پنهان کردن دکمه حذف
|
|
// loadingSpinner.style.display = "block";
|
|
// previewImage.style.display = "none";
|
|
// deleteButton.style.display = "none";
|
|
|
|
// // گرفتن فایل و ایجاد پیشنمایش
|
|
// const file = fileInput.files[0];
|
|
// if (file) {
|
|
// const reader = new FileReader();
|
|
// reader.onload = function (e) {
|
|
// // نمایش تصویر پس از تاخیر 2 ثانیهای
|
|
// setTimeout(() => {
|
|
// loadingSpinner.style.display = "none";
|
|
// previewImage.src = e.target.result;
|
|
// previewImage.style.display = "block";
|
|
// deleteButton.style.display = "block"; // نمایش دکمه حذف
|
|
// }, 2000); // تاخیر ۲ ثانیهای
|
|
// };
|
|
// reader.readAsDataURL(file);
|
|
// } else {
|
|
// loadingSpinner.style.display = "none";
|
|
// }
|
|
//});
|
|
|
|
//// افزودن رویداد کلیک برای دکمه حذف
|
|
//document.getElementById("deleteButton").addEventListener("click", function () {
|
|
// const fileInput = document.getElementById("fileInput");
|
|
// const previewImage = document.getElementById("previewImage");
|
|
// const deleteButton = document.getElementById("deleteButton");
|
|
|
|
// // پاک کردن فایل انتخاب شده و بازگرداندن فرم به حالت اولیه
|
|
// fileInput.value = "";
|
|
// previewImage.style.display = "none";
|
|
// deleteButton.style.display = "none";
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#createData').on('click', SaveDataAjax);
|
|
function SaveDataAjax() {
|
|
var loading = $('#createData .spinner-loading');
|
|
|
|
|
|
/* var workshopSelect = $('#workshopSelect').val();*/
|
|
var roleSelect = $('#roleSelect').val();
|
|
var nationalCode = $('#NationalCode');
|
|
var fName = $('#FName');
|
|
var lName = $('#LName');
|
|
var phoneNumber = $('#PhoneNumber');
|
|
var username = $('#Username');
|
|
var password = $('#Password');
|
|
|
|
|
|
//if (workshopSelect.length === 0) {
|
|
// $('.alert-msg').show();
|
|
// $('.alert-msg p').text('لطفا کارگاه را مشخص نمائید.');
|
|
// $('.select-workshop-alert').addClass('errored');
|
|
// setTimeout(function () {
|
|
// $('.alert-msg').hide();
|
|
// $('.alert-msg p').text('');
|
|
// $('.select-workshop-alert').removeClass('errored');
|
|
// }, 3500);
|
|
// return;
|
|
//}
|
|
|
|
if (roleSelect === "0") {
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا نقش را مشخص نمائید.');
|
|
$('.select-role-alert').addClass('errored');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
$('.select-role-alert').removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
if (!nationalCode.val()) {
|
|
nationalCode.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا کد ملی را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
nationalCode.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
if (!fName.val()) {
|
|
fName.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا نام را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
fName.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
if (!lName.val()) {
|
|
lName.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا نام خانوادگی را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
lName.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
if (!phoneNumber.val()) {
|
|
phoneNumber.addClass('errored');
|
|
$('.alert-msg').show();
|
|
if (phoneNumber.val().length > 0 && phoneNumber.length !== 11) {
|
|
$('.alert-msg p').text('شماره تلفن همراه نامعتبر است');
|
|
} else {
|
|
$('.alert-msg p').text('لطفا شماره تلفن همراه را وارد نمائید');
|
|
}
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
phoneNumber.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
if (!username.val()) {
|
|
username.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا نام کاربری را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
username.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
if (!password.val()) {
|
|
password.addClass('errored');
|
|
$('.alert-msg').show();
|
|
$('.alert-msg p').text('لطفا گذرواژه را وارد نمائید');
|
|
setTimeout(function () {
|
|
$('.alert-msg').hide();
|
|
$('.alert-msg p').text('');
|
|
password.removeClass('errored');
|
|
}, 3500);
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
var data = $('#create-form-sub-account').serialize();
|
|
$.ajax({
|
|
async: false,
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
url: saveNewSubAccountAjax,
|
|
headers: { "RequestVerificationToken": antiForgeryToken },
|
|
data: data,
|
|
success: function (response) {
|
|
if (response.success) {
|
|
loading.show();
|
|
$('.alert-success-msg').show();
|
|
$('.alert-success-msg p').text(response.message);
|
|
setTimeout(function () {
|
|
$('.alert-success-msg').hide();
|
|
$('.alert-success-msg p').text('');
|
|
}, 2000);
|
|
|
|
loading.hide();
|
|
$('#MainModal').modal('hide');
|
|
// Load Roles with its Sub Accounts in Index page
|
|
LoadRolesAndAccountsList();
|
|
} 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);
|
|
}
|
|
});
|
|
} |