127 lines
4.0 KiB
JavaScript
127 lines
4.0 KiB
JavaScript
$('#user-list-card td.user-operations > .btn.btn-warning').on('click', function () {
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'آیا مطمئن هستید؟',
|
|
text: "این عملیات قابل بازگشت نیست!",
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'بله، تایید میشود',
|
|
cancelButtonText: 'منصرف شدم!',
|
|
showLoaderOnConfirm: true,
|
|
preConfirm: () => {
|
|
return updateUserPasswordToDefault($(this).attr('data-id'));
|
|
},
|
|
allowOutsideClick: () => !Swal.isLoading()
|
|
}).then((result) => {
|
|
if (result.value) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'رمز عبور کاربر باموفقیت بروزرسانی شد!',
|
|
text: "رمز عبور جدید 123 میباشد.",
|
|
confirmButtonText: 'بستن'
|
|
})
|
|
}
|
|
})
|
|
});
|
|
|
|
function updateUserPasswordToDefault(userId) {
|
|
$.ajax({
|
|
url: '/users/reset/' + userId,
|
|
type: 'POST',
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
},
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (result) {
|
|
//console.log(result);
|
|
return true;
|
|
},
|
|
error: function (error) {
|
|
//console.log(error);
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
|
|
$('#user-list-card > .card-header .btn.btn-success').on('click', function () {
|
|
$('#createNewUser').modal('show');
|
|
});
|
|
|
|
function submitNewUser() {
|
|
formData = new FormData();
|
|
|
|
formData.append('username', $("input[name=username]").val());
|
|
formData.append('name', $("input[name=user-name]").val());
|
|
formData.append('password', $("input[name=password]").val());
|
|
formData.append('password_confirmation', $("input[name=password-confirmation]").val());
|
|
|
|
if ($("input[name=user-fname]").val() != '') {
|
|
formData.append('fname', $("input[name=user-fname]").val());
|
|
}
|
|
if ($("input[name=user-lname]").val() != '') {
|
|
formData.append('lname', $("input[name=user-lname]").val());
|
|
}
|
|
if ($("input[name=user-position]").val() != '') {
|
|
formData.append('position', $("input[name=user-position]").val());
|
|
}
|
|
if ($("input[name=user-mobile]").val() != '') {
|
|
formData.append('mobile', $("input[name=user-mobile]").val());
|
|
}
|
|
|
|
$.ajax({
|
|
url: '/users',
|
|
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);
|
|
$('#createNewUser').modal('hide');
|
|
setTimeout(() => {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'کاربر جدید با موفقیت ایجاد شد!',
|
|
showConfirmButton: false,
|
|
timer: 2000
|
|
})
|
|
}, 500);
|
|
},
|
|
error: function (error) {
|
|
//console.log(error);
|
|
if (error.responseJSON.errors) {
|
|
showUserUpdateValidateErrors(error.responseJSON.errors);
|
|
} else {
|
|
$('#createNewUser').modal('hide');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function showUserUpdateValidateErrors(errors) {
|
|
if (errors.username) {
|
|
$("input[name=username]").removeClass('is-valid').addClass('is-invalid');
|
|
} else {
|
|
$("input[name=username]").removeClass('is-invalid').addClass('is-valid');
|
|
}
|
|
|
|
if (errors.name) {
|
|
$("input[name=user-name]").removeClass('is-valid').addClass('is-invalid');
|
|
} else {
|
|
$("input[name=user-name]").removeClass('is-invalid').addClass('is-valid');
|
|
}
|
|
|
|
if (errors.password) {
|
|
$("input[name=password]").removeClass('is-valid').addClass('is-invalid');
|
|
$('#password-invalid-msg').text('رمز عبور باید حداقل ۸ کاراکتر و شامل حداقل یک حرف بزرگ لاتین یک حرف کوچک لاتین و یک عدد باشد.');
|
|
} else {
|
|
$("input[name=password]").removeClass('is-invalid').addClass('is-valid');
|
|
$('#password-invalid-msg').text('');
|
|
}
|
|
} |