File: /var/www/vhost/disk-apps/qas.sports-crowd.com/public/js/statistics.js
function update() {
active = $("#chkActive").is(":checked");
$("#edit").validator("update");
$("#edit")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var info = {
id: $("#edit input[name='id']").val(),
team_name: $("#edit input[name='team_name']").val(),
team_league: $("#edit input[name='team_league']").val(),
team_season: $("#edit input[name='team_season']").val(),
api_key: $("#edit input[name='api_key']").val(),
api_key_standings: $("#edit input[name='api_key_standings']").val(),
synchronization_frequency: $("#edit input[name='synchronization_frequency']").val(),
active,
carousel_matches: $("#edit textarea[name='carousel_matches']").val(),
carousel_results: $("#edit textarea[name='carousel_results']").val(),
};
swal((info.id ? "¿Modificar" : "¿Crear") + " configuración estadísticas?", {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/statistics/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("Estadísticas modificadas con éxito!", {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/statistics");
}
});
}
},
error: function (e) {
swal("Error", "Error al actualizar la configuración estadísticas", "error");
},
});
}
});
}
});
}
function syncData() {
swal("Sincronizar datos?", {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/statistics/syncData/" + true,
type: "GET",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $(
'meta[name="csrf-token"]'
).attr("content"),
"Content-Type": "application/json",
},
data: {},
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/statistics");
}
});
} else {
swal("Error", r.m, { icon: "error" });
}
},
error: function (e) {
swal("Error", "Error al sincronizar datos " + (e.responseJSON ? e.responseJSON.message : ''), { icon: "error" });
},
});
}
});
}
function syncDataApiFootball(standings) {
$.ajax({
url: "/statistics/saveDataApiFootball",
type: "POST",
contentType: "application/json",
headers: {
"Content-Type": "application/json",
},
data: JSON.stringify({
result_standings: standings
}),
success: function (r) {
if (r.r) {
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
if (!isMobile) {
alert(r.m);
$(location).attr("href", "/statistics");
}
} else {
alert(r.m);
}
},
error: function (e) {
alert("Error al sincronizar datos " + (e.responseJSON ? e.responseJSON.message : ''));
},
});
}