398 lines
12 KiB
JavaScript
398 lines
12 KiB
JavaScript
var flatten = [];
|
|
var datauser = null
|
|
var karbarid = null
|
|
var table
|
|
var completepic = 0
|
|
var nameedit = ""
|
|
var username = ""
|
|
var fname = ""
|
|
var lname = ""
|
|
var mobile = ""
|
|
var degree = ""
|
|
var image = ""
|
|
var password = ""
|
|
var password_confirmation = ""
|
|
function showLoaderScreen() {
|
|
$('.starter-loader-container').css('display', 'flex').hide().fadeIn();
|
|
}
|
|
|
|
function hideLoaderScreen() {
|
|
$('.starter-loader-container').fadeOut();
|
|
}
|
|
$(document).ready(function () {
|
|
table = $("#example").DataTable({
|
|
dom: 'lBfrtip',
|
|
// "scrollX": true,
|
|
// "pagingType": "full_numbers",
|
|
pagingType: "simple_numbers",
|
|
language: {
|
|
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
|
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
|
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
|
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
|
sInfoPostFix: "",
|
|
sInfoThousands: ",",
|
|
sLengthMenu: "نمایش _MENU_ ردیف",
|
|
sLoadingRecords: "در حال بارگذاری...",
|
|
sProcessing: "در حال پردازش...",
|
|
sSearch: "جستجو: ",
|
|
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
|
oPaginate: {
|
|
sFirst: "برگهی نخست",
|
|
sLast: "برگهی آخر",
|
|
sNext: "بعدی",
|
|
sPrevious: "قبلی",
|
|
},
|
|
oAria: {
|
|
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
|
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
|
},
|
|
},
|
|
processing: true,
|
|
ajax: {
|
|
|
|
url: "/users/list",
|
|
type: "GET",
|
|
dataSrc: function (json) {
|
|
return json.data.users;
|
|
},
|
|
},
|
|
columns: [
|
|
{
|
|
data: null,
|
|
render: function (data, type, row, meta) {
|
|
// console.log(meta.row);
|
|
return meta.row + 1;
|
|
},
|
|
},
|
|
{ data: "provinceName" },
|
|
{ data: "name" },
|
|
{ data: "username" },
|
|
{
|
|
data: null,
|
|
render: function (data, type, row) {
|
|
return data.firstName + " " + data.lastName;
|
|
},
|
|
},
|
|
{ orderable: false, data: "mobile" },
|
|
{ data: "lastSubmit" },
|
|
{ orderable: false, data: "degree" },
|
|
{
|
|
orderable: false,
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data, type, row) {
|
|
return '<div><img src=' + data.photo + ' class="zoom"></div>'
|
|
}
|
|
},
|
|
{
|
|
orderable: false,
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data, type, row) {
|
|
if (data.delete == 1) {
|
|
return ' <button class="btn btn-warning btn-sm edit_pro" title="ویرایش کاربر"><i class="fas fa-edit"></i></button> <button class="btn btn-danger btn-sm editor_remove" title="حذف کاربر"><i class="fas fa-trash-alt"></i></i></button>'
|
|
}
|
|
else return ' <button class="btn btn-warning btn-sm edit_pro" title="ویرایش کاربر"><i class="fas fa-edit"></i></button>'
|
|
},
|
|
},
|
|
],
|
|
buttons: [
|
|
{
|
|
extend: 'excelHtml5',
|
|
title: 'Excel',
|
|
text: 'خروجی به اکسل',
|
|
messageTop: 'فهرست کاربران ',
|
|
exportOptions: {
|
|
columns: [1, 2, 3, 4, 5, 6, 7]
|
|
}
|
|
}
|
|
]
|
|
});
|
|
});
|
|
|
|
function showUploadedFilespic(input) {
|
|
if (input.files) {
|
|
if (completepic == 0) {
|
|
|
|
$('#uploadedItemspic').append('\
|
|
<div class="row" id="itempic-' + 0 + '">\
|
|
<div class="col-md-6"><span style="margin-right: 12px;">نام: </span><span>' + input.files[0].name + '</span></div>\
|
|
<div class="col-md-4"><span style="margin-right: 12px;">حجم: </span><span>' + input.files[0].size / 1000 + 'KB</span></div>\
|
|
<div class="col-md-2" onclick="deletfilepic('+ 0 + ')"><span style="margin-right: 12px; cursor: pointer" >✖</span><br></div>\
|
|
</div>\
|
|
');
|
|
completepic = 1;
|
|
}
|
|
else {
|
|
$('#uploadedItemspic').empty();
|
|
$('#uploadedItemspic').append('\
|
|
<div class="row" id="itempic-' + 0 + '">\
|
|
<div class="col-md-6"><span style="margin-right: 12px;">نام: </span><span>' + input.files[0].name + '</span></div>\
|
|
<div class="col-md-4"><span style="margin-right: 12px;">حجم: </span><span>' + input.files[0].size / 1000 + 'KB</span></div>\
|
|
<div class="col-md-2" onclick="deletfilepic('+ 0 + ')"><span style="margin-right: 12px; cursor: pointer" >✖</span><br></div>\
|
|
</div>\
|
|
');
|
|
}
|
|
// 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('')
|
|
|
|
// }
|