var okCallback; var cancelCallback; var basketProduct; function popupCancel() { cancelCallback(basketProduct); } function cadeaubonPopupOk() { try { let amount = parseInt(document.getElementById("amount").value); if ((amount < 20) || (amount > 10000)) document.getElementById("amount").value = ""; } catch (e) { document.getElementById("amount").value = ""; } let forbidden = "<>"; let givenBy = document.getElementById("givenBy").value; if (givenBy != undefined) { givenBy = givenBy.trim(); if (givenBy.length > 100) { document.getElementById("givenBy").value = ""; } for (c in givenBy) { if (forbidden.indexOf(givenBy[c]) > -1) { document.getElementById("givenBy").value = ""; break; } } } let givenTo = document.getElementById("givenTo").value; if (givenTo != undefined) { givenTo = givenTo.trim(); if (givenTo.length > 100) { document.getElementById("givenTo").value = ""; } for (c in givenTo) { if (forbidden.indexOf(givenTo[c]) > -1) { document.getElementById("givenTo").value = ""; break; } } } var form = $("#myFormCadeaubon"); if (form[0].checkValidity() === false) { event.preventDefault() event.stopPropagation() form.addClass('was-validated'); return; } let output = {}; output.givenBy = document.getElementById("givenBy").value; output.givenTo = document.getElementById("givenTo").value; output.amount = document.getElementById("amount").value; output.type = "cadeaubon"; basketProduct.productConfiguration = JSON.stringify(output); basketProduct.unitPriceInCent = output.amount * 100; okCallback(basketProduct); } function cadeaubonPaintForm(basketProduct) { if ((basketProduct != undefined) && (basketProduct.productConfiguration != undefined) && (basketProduct.productConfiguration != "")) { let productConfiguration = JSON.parse(basketProduct.productConfiguration); if (productConfiguration.givenBy != undefined) document.getElementById("givenBy").value = productConfiguration.givenBy; if (productConfiguration.givenTo != undefined) document.getElementById("givenTo").value = productConfiguration.givenTo; if (productConfiguration.amount != undefined) document.getElementById("amount").value = productConfiguration.amount; } $('#cadeauProductConfiguration').on('shown.bs.modal', function () { $('#givenBy').focus(); }); } function inscriptionPopupOk() { let inscription = document.getElementById("inscription").value; if (inscription != undefined) { inscription = inscription.trim(); if (inscription.length > 12) { document.getElementById("inscription").value = ""; } let characterSet = "abcdefghijklmnopqrstuvwxyz"; for (c in inscription) { let lc = inscription[c].toLowerCase(); if (characterSet.indexOf(lc) == -1) { document.getElementById("inscription").value = ""; break; } } } var form = $("#myFormInscription"); if (form[0].checkValidity() === false) { event.preventDefault() event.stopPropagation() form.addClass('was-validated'); return; } let output = {}; output.inscription = document.getElementById("inscription").value; output.type = "inscription"; basketProduct.productConfiguration = JSON.stringify(output); okCallback(basketProduct); } function inscriptionPaintForm(basketProduct) { if ((basketProduct != undefined) && (basketProduct.productConfiguration != undefined) && (basketProduct.productConfiguration != "")) { let productConfiguration = JSON.parse(basketProduct.productConfiguration); document.getElementById("inscription").value = productConfiguration.inscription; } $('#inscriptionProductConfiguration').on('shown.bs.modal', function () { $('#inscription').focus(); }); } function sizePopupOk(e) { let output = {}; output.size = e.currentTarget.innerText; output.type = "size"; basketProduct.productConfiguration = JSON.stringify(output); $('#sizeProductConfiguration').modal('hide'); okCallback(basketProduct); } function sizePaintForm(basketProduct) { //generate buttons let inputConfiguration = JSON.parse(basketProduct.configuration); let sizes = inputConfiguration.values; let HTML = ""; for (i in sizes) { HTML += ""; } document.getElementById("sizeButtons").innerHTML = HTML; } function lettersPopupOk(e) { let output = {}; output.letter = e.currentTarget.innerText; output.type = "letters"; basketProduct.productConfiguration = JSON.stringify(output); $('#lettersProductConfiguration').modal('hide'); okCallback(basketProduct); } function lettersPaintForm(basketProduct) { let inputConfiguration = JSON.parse(basketProduct.configuration); let letters = inputConfiguration.values; let HTML = ""; for (i in letters) { HTML += ""; } document.getElementById("lettersButtons").innerHTML = HTML; } function namePopupOk() { let name = document.getElementById("useName").value; if (name != undefined) { name = name.trim(); if (name.length > 10) { document.getElementById("useName").value = ""; } let characterSet = "abcdefghijklmnopqrstuvwxyz"; for (c in name) { let lc = name[c].toLowerCase(); if (characterSet.indexOf(lc) == -1) { document.getElementById("useName").value = ""; break; } } } var form = $("#myFormName"); if (form[0].checkValidity() === false) { event.preventDefault() event.stopPropagation() form.addClass('was-validated'); return; } let output = {}; output.name = name; output.type = "name"; basketProduct.productConfiguration = JSON.stringify(output); okCallback(basketProduct); } function namePaintForm(basketProduct) { if ((basketProduct != undefined) && (basketProduct.productConfiguration != undefined) && (basketProduct.productConfiguration != "")) { let productConfiguration = JSON.parse(basketProduct.productConfiguration); document.getElementById("useName").value = productConfiguration.name; } $('#nameProductConfiguration').on('shown.bs.modal', function () { $('#useName').focus(); }); } function showPopup(modalId, paintForm, inputOkCallback, inputCancelCallback, inputBasketProduct) { basketProduct = inputBasketProduct; okCallback = inputOkCallback; cancelCallback = inputCancelCallback; if (paintForm != null) paintForm(basketProduct); $('#' + modalId).modal('show'); }