File: /var/www/vhost/disk-apps/agile-selling-mia/public/js/event_prices.js
/**
* metodos para administrar Torneos
* @diegoDuque
*/
function create() {
$("#form_create").validator("update");
$("#form_create")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var zone_id = $("#form_create select[name='zone_id']").val();
if (!zone_id || zone_id == "0") {
swal(Lang.get("messagesClient.event_prices.tag_3"), {
icon: "error",
});
return;
}
var info = {
match_event_id: $(
"#form_create select[name='match_event_id']"
).val(),
zone_id,
price: $(" #form_create input[name='price']").val(),
price_suscription: $(
" #form_create input[name='price_suscription']"
).val(),
};
$("#btn-create").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
swal(Lang.get("messagesClient.events.tag_1"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/event_prices/save/" + info.match_event_id,
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",
"/event_prices/" +
info.match_event_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(value) {
$(location).attr("href", "/event_prices/" + value + "/edit");
}
function edit() {
$("#form_edit").validator("update");
$("#form_edit")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var zone_id = $("#form_edit select[name='zone_id']").val();
if (!zone_id || zone_id == "0") {
swal(Lang.get("messagesClient.event_prices.tag_3"), {
icon: "error",
});
return;
}
var info = {
match_event_id: $(
"#form_edit select[name='match_event_id']"
).val(),
zone_id,
price: $(" #form_edit input[name='price']").val(),
price_suscription: $(
" #form_edit input[name='price_suscription']"
).val(),
};
var id = $("#form_edit").attr("matchEventZonePrice_id");
$("#btn-edit").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
swal(Lang.get("messagesClient.events.tag_2"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/event_prices/update/" + 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",
"/event_prices/" +
info.match_event_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");
}
});
}
});
}
function setPageTable() {
$(location).attr("href", "/events");
}
/**Método para eliminar match_price*/
function clickDelete(value, event_id) {
console.log("value: ", value);
console.log("event_id: ", event_id);
swal(Lang.get("messagesClient.events.tag_6"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
var info = {
_method: "DELETE",
};
$.ajax({
url: "/event_prices/" + 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",
"/event_prices/" + event_id + "/list"
);
}
});
} else {
swal(r.m, { icon: "error" });
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.events.error_delete"),
"error"
);
},
});
}
});
}