181 lines
4.5 KiB
JavaScript
181 lines
4.5 KiB
JavaScript
$(document).ready(function () {
|
|
$("#user-table").DataTable();
|
|
});
|
|
|
|
function getUser(id) {
|
|
$.ajax({
|
|
url: "/users/details",
|
|
type: "GET",
|
|
data: {
|
|
id: id,
|
|
},
|
|
dataType: "json",
|
|
success: function (result) {
|
|
$("#edit_id").val(id);
|
|
$("#edit_name").val(result.user.name);
|
|
$("#edit_email").val(result.user.email);
|
|
$("#edit_contact_no").val(result.user.contact_number);
|
|
$("#kt_modal_edit_user").modal("show");
|
|
},
|
|
});
|
|
}
|
|
|
|
$("#kt_modal_add_user_form").validate({
|
|
ignore: [],
|
|
debug: false,
|
|
rules: {
|
|
name: 'required',
|
|
email: 'required',
|
|
contact_number: {
|
|
required: true,
|
|
minlength: 10,
|
|
maxlength: 10,
|
|
},
|
|
},
|
|
|
|
messages: {
|
|
name: "Please Enter Name",
|
|
email: "Please Enter Email",
|
|
contact_number: "Please Enter Contact Number",
|
|
},
|
|
|
|
submitHandler: function (form) {
|
|
var formData = new FormData(form);
|
|
// $("#save_btn").text("Please wait...");
|
|
// $("#save_btn").attr("disabled", true);
|
|
$.ajax({
|
|
url: "/users/add",
|
|
type: "POST",
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: "json",
|
|
success: function (result) {
|
|
if (result.status == 200) {
|
|
toastr.success(result.message);
|
|
setTimeout(() => {
|
|
location.reload();
|
|
}, 1000);
|
|
swal({
|
|
// title: "Good job!",
|
|
text: "Form has been successfully submitted!",
|
|
icon: "success",
|
|
button: "Ok,got it!",
|
|
}).then((value) => {
|
|
// swal(`The returned value is: ${value}`);
|
|
location.reload();
|
|
});
|
|
}
|
|
},
|
|
error: function (jqXHR) {
|
|
$("#request_callback_btn").removeClass("d-none");
|
|
$("#loaderContactBtn").addClass("d-none");
|
|
warning(jqXHR.responseJSON);
|
|
},
|
|
});
|
|
},
|
|
});
|
|
|
|
$("#kt_modal_edit_user_form").validate({
|
|
ignore: [],
|
|
debug: false,
|
|
rules: {
|
|
name: 'required',
|
|
email: 'required',
|
|
contact_number: {
|
|
required: true,
|
|
minlength: 10,
|
|
maxlength: 10,
|
|
},
|
|
},
|
|
messages: {
|
|
name: "Please Enter Name",
|
|
email: "Please Enter Email",
|
|
contact_number: "Please Enter Contact Number",
|
|
},
|
|
|
|
submitHandler: function (form) {
|
|
var formData = new FormData(form);
|
|
// $("#save_btn").text("Please wait...");
|
|
// $("#save_btn").attr("disabled", true);
|
|
$.ajax({
|
|
url: "/users/edit",
|
|
type: "POST",
|
|
data: formData,
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: "json",
|
|
success: function (result) {
|
|
if (result.status == 200) {
|
|
toastr.success(result.message);
|
|
setTimeout(() => {
|
|
location.reload();
|
|
}, 1000);
|
|
swal({
|
|
// title: "Good job!",
|
|
text: "Form has been successfully submitted!",
|
|
icon: "success",
|
|
button: "Ok,got it!",
|
|
}).then((value) => {
|
|
// swal(`The returned value is: ${value}`);
|
|
location.reload();
|
|
});
|
|
}
|
|
if (result.status == 400) {
|
|
toastr.warning(result.message);
|
|
}
|
|
},
|
|
error: function (jqXHR) {
|
|
$("#request_callback_btn").removeClass("d-none");
|
|
$("#loaderContactBtn").addClass("d-none");
|
|
warning(jqXHR.responseJSON);
|
|
},
|
|
});
|
|
},
|
|
});
|
|
|
|
function deleteUser(id) {
|
|
swal({
|
|
// title: "Good job!",
|
|
text: "Are you sure want you to delete ?",
|
|
icon: "error",
|
|
// button: "Ok,got it!",
|
|
buttons: ["Nope,cancel it", "Ok, got it!"],
|
|
dangerMode: true,
|
|
}).then((willDelete) => {
|
|
if (willDelete) {
|
|
$.ajax({
|
|
url: "/users/delete",
|
|
type: "post",
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
data: {
|
|
id: id,
|
|
},
|
|
dataType: "json",
|
|
success: function (result) {
|
|
if (result.status == 200) {
|
|
toastr.success(result.message);
|
|
setTimeout(() => {
|
|
location.reload();
|
|
}, 1000);
|
|
swal("User has been deleted!").then((value) => {
|
|
location.reload();
|
|
});
|
|
}
|
|
},
|
|
error: function (jqXHR) {
|
|
$("#request_callback_btn").removeClass("d-none");
|
|
$("#loaderContactBtn").addClass("d-none");
|
|
warning(jqXHR.responseJSON);
|
|
// warning(jqXHR.responseJSON.errors);
|
|
},
|
|
});
|
|
}
|
|
});
|
|
}
|