File: /var/www/vhost/disk-apps/teamdemo.sports-crowd.com/public/js/complimentary_tickets.js
function viewComplimentaryTickets(ticketMainId, userId) {
$(location).attr("href", "/complimentary_tickets/details/" + ticketMainId + "/" + userId);
}
function changeSeats(ticketMainId, userId, zoneId, element, showModal = true) {
if (showModal) {
showZoneModal(zoneId, function (selectedZoneId) {
$("#zoneId").val(selectedZoneId);
changeSeats(ticketMainId, userId, zoneId, element, false);
});
return;
}
var dataLog = $(element).attr("data-log");
$.ajax({
url: "/complimentary_tickets/changeSeats",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify({
ticketMainId: ticketMainId,
userId: userId,
zoneId: parseInt($("#zoneId").val()),
dataLog: dataLog,
}),
success: function (response) {
if (response.success) {
swal(response.message, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/complimentary_tickets");
}
});
} else {
swal("Error", response.message, "error");
}
},
error: function (xhr, status, error) {
swal("Error", xhr.responseJSON.message, "error");
}
});
}
function showZoneModal(zoneId, callback) {
$.get('/tickets/childZones/' + zoneId, function (response) {
if (!response.r) {
swal("Error", response.m, "error");
return;
}
let zones = response.data;
let $select = $('#modalZoneSelect');
$select.empty().append('<option value="">Selecciona una zona</option>');
zones.forEach(function (zone) {
$select.append(`<option value="${zone.id}">${zone.name}</option>`);
});
});
$('#zoneModal').modal('show');
$('#confirmZoneBtn').off('click').on('click', function () {
let selectedZoneId = $('#modalZoneSelect').val();
if (selectedZoneId) {
$('#zoneModal').modal('hide');
callback(selectedZoneId);
} else {
swal("Warning", "Debes seleccionar una zona", "warning");
}
});
}
function changeEmail(ticketMainId, userId, element, email = null) {
if (!email) {
swal({
text: "Por favor ingresa el nuevo correo electrónico:",
content: "input",
buttons: {
cancel: {
text: "Cancelar",
visible: true,
className: "",
closeModal: true,
},
confirm: {
text: "Enviar",
closeModal: false,
},
},
}).then(inputEmail => {
if (inputEmail === null) {
return;
}
if (!inputEmail) {
swal("Warning", "No se ingresó ningún correo", "warning");
return;
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inputEmail)) {
swal("Error", "Correo electrónico no válido", "error");
return;
}
changeEmail(ticketMainId, userId, element, inputEmail);
});
return;
}
var dataLog = $(element).attr("data-log");
$.ajax({
url: "/complimentary_tickets/changeEmail",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify({
ticketMainId: ticketMainId,
userId: userId,
email: email,
dataLog: dataLog,
}),
success: function (response) {
if (response.success) {
swal(response.message, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/complimentary_tickets");
}
});
} else {
swal("Error", response.message, "error");
}
},
error: function (xhr, status, error) {
swal("Error", xhr.responseJSON.message, "error");
}
});
}
function sendEmailNotification(ticketMainId, userId, element) {
swal({
text: "¿Estás seguro de que deseas reenviar la notificación de cortesias por correo electrónico?",
buttons: {
cancel: {
text: "Cancelar",
visible: true,
className: "",
closeModal: true,
},
confirm: {
text: "Enviar",
closeModal: false,
},
},
}).then((val) => {
if (val === null) {
return;
}
var dataLog = $(element).attr("data-log");
$.ajax({
url: "/complimentary_tickets/sendEmailNotification",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify({
ticketMainId: ticketMainId,
userId: userId,
dataLog: dataLog,
}),
success: function (response) {
if (response.success) {
swal(response.message, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/complimentary_tickets");
}
});
} else {
swal("Error", response.message, "error");
}
},
error: function (xhr, status, error) {
swal("Error", xhr.responseJSON.message, "error");
}
});
});
}
function cancelComplimentaryTickets(ticketMainId, userId, element) {
swal({
text: "¿Estás seguro de anular todas las cortesias de este usuario?",
buttons: {
cancel: {
text: "Cancelar",
visible: true,
className: "",
closeModal: true,
},
confirm: {
text: "Enviar",
closeModal: false,
},
},
}).then((val) => {
if (val === null) {
return;
}
var dataLog = $(element).attr("data-log");
$.ajax({
url: "/complimentary_tickets/cancelComplimentaryTickets",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json",
},
data: JSON.stringify({
ticketMainId: ticketMainId,
userId: userId,
dataLog: dataLog,
}),
success: function (response) {
if (response.success) {
swal(response.message, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/complimentary_tickets");
}
});
} else {
swal("Error", response.message, "error");
}
},
error: function (xhr, status, error) {
swal("Error", xhr.responseJSON.message, "error");
}
});
});
}