\
');
}
// console.log('input.files:');
// console.log(input.files);
}
}
function deletfilepic(id) {
// console.log("GGG",id)
$('#itempic-' + id).remove()
$('input[name=modalUpFilepic]').val('')
}
$('#example').on('click', 'button.edit_pro', function (e) {
e.preventDefault();
$("#edituser").modal('show')
restrictInputOtherThanArabic($('#user-nameedit'))
restrictInputOtherThanArabic($('#user-bosname'))
restrictInputOtherThanArabic($('#user-bosfamilyname'))
data_row = table.row($(this).closest('tr')).data();
karbarid = data_row.id
$('input[name="user-nameedit"]').val(data_row.name)
$('input[name="user-username"]').val(data_row.username)
$('input[name="user-phone"]').val(data_row.mobile)
$('input[name="user-bosname"]').val(data_row.firstName)
$('input[name="user-bosfamilyname"]').val(data_row.lastName)
$('input[name="madrak-edit"]').val(data_row.degree)
$('input[name="password-edit"]').on("input", function () {
$('#confirm-pass').prop('disabled', '');
})
// Display the key/value pairs
});
$('#submitedit').on('click', function () {
showLoaderScreen()
// id = data_row.id
// console.log(id)
// console.log(karbarid)
nameedit = $('input[name="user-nameedit"]').val()
username = $('input[name="user-username"]').val()
fname = $('input[name="user-bosname"]').val()
lname = $('input[name="user-bosfamilyname"]').val()
mobile = $('input[name="user-phone"]').val()
degree = $('input[name="madrak-edit"]').val()
password = $('input[name="password-edit"]').val()
password_confirmation = $('input[name="password-editconfirmation"]').val()
// console.log(password)
let formData = new FormData();
if (nameedit != data_row.name)
formData.append('name', nameedit);
if (username != data_row.username)
formData.append('username', username);
if (fname != data_row.firstName)
formData.append('fname', fname);
if (lname != data_row.lastName)
formData.append('lname', lname);
if (mobile != data_row.mobile)
formData.append('mobile', mobile);
if (degree != data_row.degree)
formData.append('degree', degree);
if (password != "")
formData.append('password', password);
if (password_confirmation != "")
formData.append('password_confirmation', password_confirmation);
if ($('input[name=modalUpFilepic]')[0].files.length != 0)
formData.append('image', $('input[name=modalUpFilepic]')[0].files[0]);
// for (var pair of formData.entries()) {
// console.log(pair[0] + ', ' + pair[1]);
// }
// console.log('/users/updateinfo/' + karbarid)
$.ajax({
url: '/users/updateinfo/' + karbarid,
type: 'POST',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (result) {
console.log(result)
$("#edituser").modal('hide')
reloadtable()
// table.clear().draw();
// table.rows.add(result.data.users); // Add new data
// table.columns.adjust().draw(); // Redraw the DataTable
// hideLoaderScreen();
},
error: function (error) {
console.log(error)
alert("خطایی رخ داده ")
hideLoaderScreen();
}
});
})
function reloadtable() {
$("#example")
.DataTable()
.ajax.url("/users/list")
.load();
hideLoaderScreen()
}
document.getElementById('user-nameedit').addEventListener('keypress', function (e) {
if (isEnglish(e.charCode)) {
alert("لطفا به فارسی تایپ کنید ")
}
});
document.getElementById('user-bosname').addEventListener('keypress', function (e) {
if (isEnglish(e.charCode)) {
alert("لطفا به فارسی تایپ کنید ")
}
});
document.getElementById('user-bosfamilyname').addEventListener('keypress', function (e) {
if (isEnglish(e.charCode)) {
alert("لطفا به فارسی تایپ کنید ")
}
});
document.getElementById('user-username').addEventListener('keypress', function (e) {
if (isPersian(e.key)) {
alert("لطفا به انگلیسی تایپ کنید ")
}
});
document.getElementById('password-edit').addEventListener('keypress', function (e) {
if (isPersian(e.key)) {
alert("لطفا به انگلیسی تایپ کنید ")
}
});
document.getElementById('confirm-pass').addEventListener('keypress', function (e) {
if (isPersian(e.key)) {
alert("لطفا به انگلیسی تایپ کنید ")
}
});
function isEnglish(charCode) {
return (charCode >= 97 && charCode <= 122)
|| (charCode >= 65 && charCode <= 90);
}
function isPersian(key) {
var p = /^[\u0600-\u06FF\s]+$/;
return p.test(key) && key != ' ';
}
function restrictInputOtherThanArabic($field) {
// Arabic characters fall in the Unicode range 0600 - 06FF
var arabicCharUnicodeRange = /[\u0600-\u06FF]/;
$field.bind("keypress", function (event) {
var key = event.which;
// 0 = numpad
// 8 = backspace
// 32 = space
if (key == 8 || key == 0 || key === 32) {
return true;
}
var str = String.fromCharCode(key);
if (arabicCharUnicodeRange.test(str)) {
return true;
}
return false;
});
}
// $("#user-username").on("keypress", function (event) {
// // Disallow anything not matching the regex pattern (A to Z uppercase, a to z lowercase and white space)
// // For more on JavaScript Regular Expressions, look here: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions
// var englishAlphabetAndWhiteSpace = /[A-Za-z ]/g;
// // Retrieving the key from the char code passed in event.which
// // For more info on even.which, look here: http://stackoverflow.com/q/3050984/114029
// var key = String.fromCharCode(event.which);
// //alert(event.keyCode);
// // For the keyCodes, look here: http://stackoverflow.com/a/3781360/114029
// // keyCode == 8 is backspace
// // keyCode == 37 is left arrow
// // keyCode == 39 is right arrow
// // englishAlphabetAndWhiteSpace.test(key) does the matching, that is, test the key just typed against the regex pattern
// if (event.keyCode == 8 || event.keyCode == 37 || event.keyCode == 39 || englishAlphabetAndWhiteSpace.test(key)) {
// return true;
// }
// // If we got this far, just return false because a disallowed key was typed.
// return false;
// });
$("#user-username").keypress(function (event) {
var ew = event.which;
if (ew == 32)
return true;
if (48 <= ew && ew <= 57)
return true;
if (65 <= ew && ew <= 90)
return true;
if (97 <= ew && ew <= 122)
return true;
return false;
});
$("#password-edit").keypress(function (event) {
var ew = event.which;
if (ew == 32)
return true;
if (48 <= ew && ew <= 57)
return true;
if (65 <= ew && ew <= 90)
return true;
if (97 <= ew && ew <= 122)
return true;
return false;
});
$("#confirm-pass").keypress(function (event) {
var ew = event.which;
if (ew == 32)
return true;
if (48 <= ew && ew <= 57)
return true;
if (65 <= ew && ew <= 90)
return true;
if (97 <= ew && ew <= 122)
return true;
return false;
});
// function deletfilepic(id) {
// // console.log("GGG",id)
// $('#itempic-' + id).remove()
// $('input[name=modalUpFilepic]').val('')
// }