File: /var/www/vhost/disk-apps/comfama.sports-crowd.com/public/js/seasons.js
function create() {
$("#form_create").validator("update");
$("#form_create")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
$("#btn-create").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
var start = $("#form_create input[name='start']").val();
start = start.replace("T", " ");
var end = $("#form_create input[name='end']").val();
end = end.replace("T", " ");
var tournament_id = $('#form_create').attr('tournament_id');
var info = {
name: $(" #form_create input[name='name']").val(),
start,
end,
tournament_id,
is_suscription: $(" #form_create select[name='is_suscription']").val(),
active: $(" #form_create select[name='active']").val(),
};
swal(Lang.get("messagesClient.seasons.tag_1"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/seasons/save",
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",
"/seasons/" + tournament_id + "/list"
);
}
});
} else {
swal(r.m, "error");
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("¡Hubo un Error al crear!", "error");
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
},
});
} else {
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
}
});
}
function clickEdit(season_id,tournament_id) {
$(location).attr("href", "/seasons/" + season_id + "/edit/" + tournament_id);
}
function goToEvents(season_id) {
$(location).attr("href", "/season/" + season_id + "/event");
}
function edit() {
$("#form_edit").validator("update");
$("#form_edit")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
$("#btn-edit").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
var start = $("#form_edit input[name='start']").val();
start = start.replace("T", " ");
var end = $("#form_edit input[name='end']").val();
end = end.replace("T", " ");
var tournament_id = $('#form_edit').attr('tournament_id');
var season_id = $('#form_edit').attr('season_id');
var info = {
_method: $("input[name=_method]").val(),
name: $(" #form_edit input[name='name']").val(),
start,
end,
tournament_id,
active: $(" #form_edit select[name='active']").val(),
is_suscription: $("#form_edit select[name='is_suscription']").val(),
};
swal(Lang.get("messagesClient.seasons.tag_2"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/seasons/update/" + season_id,
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") {
$(location).attr(
"href",
"/seasons/" + tournament_id + "/list"
);
}
});
} else {
swal(r.m, "error");
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("¡Hubo un Error al actualizar!", "error");
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
},
});
} else {
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
}
});
}
/**Activar/Desactivar torneo usando switch*/
function chk(value) {
var state;
if ($("#Checkactive" + value).is(":checked")) {
state = 1;
} else {
state = 0;
}
var info = {
id: value,
state: state,
};
$.ajax({
url: "/seasons/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", r.m, "error");
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.seasons.error_update_image"),
"error"
);
},
});
}
function chk_suscription(value) {
var state;
if ($("#check_is_suscription" + value).is(":checked")) {
state = 1;
} else {
state = 0;
}
var info = {
id: value,
state: state,
};
$.ajax({
url: "/seasons/suscription",
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", r.m, "error");
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.seasons.error_update_image"),
"error"
);
},
});
}
/**Método para eliminar banner*/
function clickDelete(value,tournament_id) {
swal(Lang.get("messagesClient.seasons.tag_6"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
var info = {
_method: "DELETE",
};
$.ajax({
url: "/seasons/" + value + "/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(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href","/seasons/" + tournament_id + "/list");
}
});
} else {
swal(r.m, { icon: "error" });
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.seasons.error_delete"),
"error"
);
},
});
}
});
}