jQuery(document).ready(function($){
$(document).on('click','.saveParticipantsCart', function (e){
e.preventDefault();
let productID=$(this).attr("data-pid");
if(parseInt(($(".participantsModal"+productID)).length)>1){
($(".participantsModal"+productID).eq(1)).remove();
}
const collc=document.getElementsByClassName("seminar_participants"+productID);
let allow="Yes";
for(var i=0;i<collc.length;i++){
if(collc[i].value!=='seminar_participantssave'&&collc[i].value=='')
allow="No";
}
if(allow=='Yes'){
$(".participantsNamesValidation"+productID).html("");
$(this).attr("disabled",true);
$(this).val("Warten Sie mal");
$.ajax({
type: "POST",
url: seminar_ajax_obj.ajaxurl,
data: $(".seminar_participants"+productID).serialize(),
success: function(data){
console.log(data);
const collection=document.getElementsByClassName("seminar_participants"+productID);
const participants=[];
for(var i=0;i<collection.length;i++){
if(collection[i].value!=='seminar_participantssave'&&collection[i].value!='')
participants.push(collection[i].value);
}
$(".saveParticipantsCart").attr("disabled",false);
$(".saveParticipantsCart").val("Teilnehmer speichern");
$(".participantsNames"+productID).html("Teilnehmer :&nbsp;<span>"+(participants.join(' , '))+"</span>");
$(".participantsNamesValidation"+productID).html("");
$.modal.close();
},
error: function(data){
$(".participantsNamesValidation"+productID).html("");
alert("There are some server error.Please try again in some time");
$.modal.close();
}});
}else{
$(".participantsNamesValidation"+productID).html("<span style='color:red'>Bitte füllen Sie alle Teilnehmer aus</span>");
}})
$(document).on('updated_cart_totals', function (e){
$(".saveParticipantsCart").trigger("click");
})
})
function savePartidata(pid){
let productID=pid;
jQuery("#saveParticipants"+productID).attr("disabled",true);
jQuery("#saveParticipants"+productID).val("Please wait...");
jQuery.ajax({
type: "POST",
url: seminar_ajax_obj.ajaxurl,
data: jQuery(".seminar_participants"+productID).serialize(),
success: function(data){
console.log(data);
const collection=document.getElementsByClassName("seminar_participants"+productID);
const participants=[];
for(var i=0;i<collection.length;i++){
if(collection[i].value!=='seminar_participantssave')
participants.push(collection[i].value);
}
jQuery("#saveParticipants"+productID).attr("disabled",false);
jQuery("#saveParticipants"+productID).val("Teilnehmer speichern");
jQuery("#participantsNames"+productID).html(participants.toString());
jQuery.modal.close();
},
error: function(data){
alert("There are some server error.Please try again in some time");
jQuery.modal.close();
}});
}
function setModelD(pid){
jQuery(".GlobalPartiSModel").html(jQuery(".participantsModal"+pid).html());
};