File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/public/js/companies.js
function createCompany() {
$("#createCompany").validator("update");
$("#createCompany")
.validator("update")
.on("submit", function(e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var info = {
nit: $(" #createCompany input[name='nit']").val(),
name: $(" #createCompany input[name='name']").val(),
phone: $(" #createCompany input[name='phone']").val(),
contact: $("#createCompany input[name='contact']").val()
};
console.log(info);
swal(Lang.get("messagesClient.company_tag1"), {
buttons: {
cancel: "No",
Ok: true
}
}).then(val => {
if (val == "Ok") {
$("#btn-create-company").prop("disabled", true);
$.ajax({
url: "/companies/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") {
console.log("creado");
$(location).attr(
"href",
"/companies"
);
}
});
} else {
swal("Error", r.m, "error");
$("#btn-create-company").prop(
"disabled",
false
);
}
},
error: function(e) {
swal(
"Error",
Lang.get("messagesClient.company_tag2"),
"error"
);
$("#btn-create-company").prop(
"disabled",
false
);
}
});
}
});
}
});
}
function clickEditCompany(value) {
_table = $("#example2").DataTable();
index = _table.page();
localStorage.setItem("productsTableIndex", index);
$(location).attr("href", "/companies/edit/" + value);
}
function editCompany(id) {
$("#editCompany").validator("update");
$("#editCompany")
.validator("update")
.on("submit", function(e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var info = {
id: id,
nit: $(" #editCompany input[name='nit']").val(),
name: $(" #editCompany input[name='name']").val(),
phone: $(" #editCompany input[name='phone']").val(),
contact: $("#editCompany input[name='contact']").val()
};
console.log(info);
swal(Lang.get("messagesClient.company_tag4"), {
buttons: {
cancel: "No",
Ok: true
}
}).then(val => {
if (val == "Ok") {
$("#btn-edit-company").prop("disabled", true);
$.ajax({
url: "/companies/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") {
console.log("creado");
localStorage.setItem(
"setPageTable",
true
);
$(location).attr(
"href",
"/companies"
);
}
});
} else {
swal("Error", r.m, "error");
$("#btn-edit-company").prop(
"disabled",
false
);
}
},
error: function(e) {
swal(
"Error",
Lang.get("messagesClient.company_tag3"),
"error"
);
$("#btn-edit-company").prop("disabled", false);
}
});
}
});
}
});
}
/**Activar/Desactivar empresa usando switch*/
function chkCompany(value) {
var state;
if ($("#Checkactive" + value).is(":checked")) {
state = 1;
} else {
state = 0;
}
var info = {
id: value,
state: state
};
$.ajax({
url: "/companies/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", r.m);
} else {
swal("Error", Lang.get("messagesClient.company_tag3"), "error");
}
},
error: function(e) {
swal("Error", Lang.get("messagesClient.company_tag3"), "error");
}
});
}
/**Método para eliminar empresa desde la tabla de admins y en editar */
function clickDeleteCompany(id) {
swal(Lang.get("messagesClient.company_tag5"), {
buttons: {
cancel: "No",
Ok: true
}
}).then(val => {
if (val == "Ok") {
var info = {
id: id
};
console.log(info);
$.ajax({
url: "/companies/delete",
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) {
console.log(r);
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true
}
}).then(val => {
if (val == "Ok") {
console.log("creado");
$(location).attr("href", "/companies");
}
});
} else {
swal(
"Error",
Lang.get("messagesClient.company_tag6"),
"error"
);
}
},
error: function(e) {
swal(
"Error",
Lang.get("messagesClient.company_tag6"),
"error"
);
}
});
}
});
}
function setPageTable() {
localStorage.setItem("setPageTable", true);
$(location).attr("href", "/companies");
}