294 lines
8.9 KiB
JavaScript
294 lines
8.9 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) {
|
|
var isSelected = itemsWorkshop.some(workshop => workshop.id === item.id);
|
|
var selectedAttr = isSelected ? 'selected' : '';
|
|
|
|
itemOptionsHtml += `<option value="${item.id}" ${selectedAttr}>${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) {
|
|
|
|
var isSelected = subAccountId === item.id;
|
|
var selectedAttr = isSelected ? 'selected' : '';
|
|
|
|
itemOptionsHtml += `<option value="${item.id}" ${selectedAttr}>${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);
|
|
}
|
|
});
|
|
}
|
|
|
|
$('#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) {
|
|
$('#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('');
|
|
//}
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#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();
|
|
// $('.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);
|
|
}
|
|
});
|
|
} |