File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/public/js/other-users.js
$(document).on("ready", function () {
$("input[name='phone']").on("keyup", function () {
this.value = (this.value + "").replace(/[^0-9]/g, "");
});
$("input[name=email]").on("keyup", function () {
if ($("#email").val()) {
var regex = /[\w-\.]{2,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
if (regex.test($("#email").val().trim())) {
$(this).css("border", "1px solid green");
document.getElementById("btn-create-user").disabled = false;
} else {
$(this).css("border", "1px solid red");
document.getElementById("btn-create-user").disabled = true;
}
}
});
});
/**Activar/Desactivar clientes usando switch*/
function chkOtherUsers(value) {
var state;
if ($("#Checkactive" + value).is(":checked")) {
state = true;
} else {
state = false;
}
var info = {
id: value,
state: state,
};
$.ajax({
url: "/other-users/active",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal("Ok", "Usuario modificado con éxito!");
} else {
swal("Error", Lang.get("messagesClient.user_other_tag3"), "error");
}
},
error: function (e) {
swal("Error", Lang.get("messagesClient.user_other_tag3"), "error");
},
});
}
function createOtherUsers() {
$("#createUser").validator("update");
$("#createUser")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
if (validatePasswords(true)) {
var info = {
first_name: $("#createUser input[name='first_name']").val(),
phone: $("#createUser input[name='phone']").val(),
email: $("#createUser input[name='email']").val(),
document: $("#createUser input[name='document']").val(),
last_name: $("#createUser input[name='last_name']").val(),
password: $("#createUser input[name='password']").val(),
rol_id: $("#createUser select[name='rol_id']").val(),
tags: $("#createUser select[name='tags']").val(),
locations: $("#createUser select[name='locations']").val(),
};
swal(Lang.get("messagesClient.user_other_tag4"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/other-users/create",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $(
'meta[name="csrf-token"]'
).attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/other-users");
}
});
} else {
swal("Error", r.m, "warning");
}
},
});
}
});
}
}
});
}
function clickEditOtherUsers(value) {
_table = $("#example2").DataTable();
index = _table.page();
localStorage.setItem("productsTableIndex", index);
$(location).attr("href", "/other-users/edit/" + value);
}
function editOtherUsers() {
$("#editUser").validator("update");
$("#editUser")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
if (validatePasswords()) {
var info = {
id: $("#btn-edit-client").attr("data-id"),
first_name: $("#editUser input[name='first_name']").val(),
phone: $("#editUser input[name='phone']").val(),
email: $("#editUser input[name='email']").val(),
direction_used: $("#editUser select[name='direction_id']").val(),
document: $("#editUser input[name='document']").val(),
last_name: $("#editUser input[name='last_name']").val(),
rol_id: $("#editUser select[name='rol_id']").val(),
password: $("#editUser input[name='password']").val(),
tags: $("#editUser select[name='tags']").val(),
locations: $("#editUser select[name='locations']").val(),
};
swal(Lang.get("messagesClient.user_other_tag5"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/other-users/update",
type: "PUT",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $(
'meta[name="csrf-token"]'
).attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
localStorage.setItem("setPageTable", true);
$(location).attr("href", "/other-users");
}
});
} else {
swal("Error", r.m, "error");
}
},
error: function (e) {
swal("Error", Lang.get("messagesClient.user_other_tag3"), "error");
},
});
}
});
}
}
});
}
function clickDeleteOtherUsers(value) {
swal(Lang.get("messagesClient.user_other_tag1"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
var info = {
id: value,
};
$.ajax({
url: "/other-users/delete",
type: "DELETE",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr(
"content"
),
"Content-Type": "application/json",
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/other-users");
}
});
} else {
swal("Error", Lang.get("messagesClient.user_other_tag2"), "error");
}
},
error: function (r) {
swal("Error", Lang.get("messagesClient.user_other_tag2"), "error");
},
});
}
});
}