File: /var/www/vhost/disk-apps/teamdemo.sports-crowd.com/public/js/line.js
/**
* Esta función obtiene los datos de la vista y los envía a la capa de lógica
* para la creacion de una línea de negocio
* @version 2018/05/20
*/
function createLine() {
$('#createLine').validator('update');
$("#createLine").validator('update').on('submit', function (e) {
if (e.isDefaultPrevented()) {} else {
e.preventDefault();
var info = {
"name": $(" #createLine input[name='name']").val()
};
swal(Lang.get("messagesClient.line_tag3"), {
buttons: {
cancel: "No",
Ok: true,
}
}).then((val) => {
if (val == "Ok") {
createLineBusiness(info);
}
});
}
});
/**
* Esta función hace un llamado AJAX y envia un json creando un nuevo registro de linea de negocio
* @param info el json con la informacion de la vista
* @version 2018/05/20
*/
function createLineBusiness(info) {
$.ajax({
url: "/lineBusiness/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', '/lineBusiness');
}
});
} else {
swal("Error",r.m, "error");
}
}, error :function(e){
swal(Lang.get("messagesClient.line_tag1"), "error");
}
});
}
}
/*
* En caso de que se haga clic en el icono de editar
* se redirecciona a la vista de edición de Lineas de Negocio
*/
function clickEditLine(value) {
_table = $("#example2").DataTable();
index = _table.page();
localStorage.setItem("productsTableIndex", index);
$(location).attr('href','/lineBusiness/edit/' + value);
}
//eliminar linea de negocio
function clickDeleteLine(value) {
var info = {
"id":value
};
swal( Lang.get("messagesClient.line_tag4"), {
buttons: {
cancel: "No",
Ok: true,
}
}).then((val) => {
if (val == "Ok") {
deleteLine(info);
}
});
}
/**
* Esta función obtiene los datos de la vista de edtitar y los envía a la capa de lógica
* para la actualización de los datos de una línea de negocio
* @version 2018/05/20
*/
function editLine() {
$('#editLine').validator('update');
$("#editLine").validator('update').on('submit', function (e) {
if (e.isDefaultPrevented()) {} else {
e.preventDefault();
var info = {
"id": $(" #editLine input[name='id']").val(),
"name": $(" #editLine input[name='name']").val(),
};
swal(Lang.get("messagesClient.line_tag5"), {
buttons: {
cancel: "No",
Ok: true,
}
}).then((val) => {
if (val == "Ok") {
updateLine(info);
}
});
}
});
/**
* Esta función hace un llamado AJAX y envia un json actualizando un registro de linea de negocio
* @param info el json con la informacion de la vista
* @version 2018/05/20
*/
function updateLine(info) {
$.ajax({
url: "/lineBusiness/update",
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('modificado');
localStorage.setItem("setPageTable", true);
$(location).attr('href','/lineBusiness');
}
});
} else {
swal("Error",r.m, "error");
}
}, error: function (e){
swal("Error",Lang.get("messagesClient.line_tag2"), "error");
}
});
}
}
function setPageTable(){
localStorage.setItem("setPageTable", true);
$(location).attr('href', '/lineBusiness');
}
function chkLine(id) {
var state;
if ($('#Checkactive'+id).is(':checked')) {
state = 1;
} else {
state = 0;
}
var info = {
"id": id,
"state": state
};
$.ajax({
url: "/lineBusiness/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", '¡Linea modificada con éxito!');
} else {
swal("Ok", "¡Error al modificar Linea!", "error");
}
},
error: function (e) {
swal("Ok", "¡Error al modificar Linea!", "error");
}
});
}
//funcion eliminar linea de negocio
function deleteLine(info) {
$.ajax({
url: "/lineBusiness/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) {
if (r.r) {
swal("Linea de Negocio eliminada!", {
icon: "success",
buttons: {
Ok: true,
}
}).then((val) => {
if (val == "Ok") {
console.log('modificado');
$(location).attr('href', '/lineBusiness');
}
});
} else {
swal("Hubo un error al querer eliminar la Linea de Negocio", "error");
}
},
error: function (e) {
swal("Hubo un error al querer eliminar la Linea de Negocio", "error");
}
});
}