https://www.portlandglass.com/brand/_assets/js/o2/opus2.gift-purchase-loader.510623a72929033fa9bb.js
1"use strict";(self.webpackChunkcrownpeak_opus2=self.webpackChunkcrownpeak_opus2||[]).push([["gift-purchase-loader"],{"./src/js/opus2/mly/gift-purchase.ts"(e,i,t){t.r(i),t.d(i,{GiftPurchase:()=>d});var a=t(/*! tslib */"./node_modules/tslib/tslib.es6.mjs"),l=t(/*! ../api/apiRequest */"./src/js/opus2/api/apiRequest.ts"),n=t(/*! ../config/apiConfig */"./src/js/opus2/config/apiConfig.ts"),s=t(/*! ../constants/regex */"./src/js/opus2/constants/regex.ts"),r=t(/*! ../util/share */"./src/js/opus2/util/share.ts");class d{static getInstance(){return d.instance||(d.instance=new d),d.instance}constructor(){this.PHONE_NUMBER_LENGTH=14,this.init()}init(){this.addNextBtnEventListener(),this.addInputEventListeners(),this.backBtn();const e=document.getElementById("purchaser-phone-number");e&&e.addEventListener("input",this.handleMobileInput.bind(this))}backBtn(){const e=(0,r.removeAllEventListeners)("#gc-purchaser-details .btn-cancel");e&&e.addEventListener("click",this.handleBackButtonClick.bind(this))}handleBackButtonClick(){const e=document.getElementById("gc-recipients-details"),i=document.getElementById("gc-purchaser-details");(0,r.hmsProgressBarUpdate)("0%",0),window.scrollTo(0,0),null==e||e.classList.add("form-step-active"),null==i||i.classList.remove("form-step-active")}addNextBtnEventListener(){const e=(0,r.removeAllEventListeners)("#gc-purchaser-details .submit-gift");e&&e.addEventListener("click",this.handleNextButtonClick.bind(this))}handleNextButtonClick(){var e,i,t,a;if(this.isValidForm()){const l=null===(e=document.getElementById("purchaser-first-name"))||void 0===e?void 0:e.value,n=null===(i=document.getElementById("purchaser-last-name"))||void 0===i?void 0:i.value,s=null===(t=document.getElementById("purchaser-phone-number"))||void 0===t?void 0:t.value,r=null===(a=document.getElementById("purchaser-email"))||void 0===a?void 0:a.value;(null===window||void 0===window?void 0:window.giftRecipient)&&(window.giftRecipient=window.giftRecipient.map(e=>e?Object.assign(Object.assign({},e),{PurchaserEmail:r,PurchaserFirstName:l,PurchaserLastName:n,PurchaserPhoneNumber:s,PurchaserPhoneType:"",Campaign:""}):e),this.prePurchaseCertificate())}}prePurchaseCertificate(){return(0,a.__awaiter)(this,void 0,void 0,function*(){var e,i,t;try{const t="https://api2.dwyergroup.com/Core/v5/GiftCertificateGroups/PrePurchase";if(null===window||void 0===window?void 0:window.giftRecipient){let a={method:"POST",url:t,data:null===window||void 0===window?void 0:window.giftRecipient};if(null===(i=null===(e=null==a?void 0:a.data[0])||void 0===e?void 0:e.PurchaserFirstName)||void 0===i?void 0:i.toLowerCase().includes("isfakesubmit"))return a.data=null==a?void 0:a.data[0],(0,r.handleFakeSubmit)(a).then(()=>{console.log("Fake Submit Request triggered")}).catch(e=>{console.error("Error in Fake Submit:",e)}).finally(()=>{this.naviateToConfirmation()}),!0;const s=yield(0,l.default)(a);if(s){const e=null==s?void 0:s.GiftCertificateGroupId,i=`${n.apiConfig.paymentPostUrl}?invoicenumber=${e}&appkey=51cd4638-de12-4558-b37a-df63b3b381dc`;console.log(i,"PaymentPostUrl");const t=(0,r.removeAllEventListeners)("#gc-purchaser-details");t&&(t.action=i,t.method="POST",t.submit())}}}catch(e){const i=document.querySelector(".gift-certificate-form #error-modal");i&&(i.classList.remove("hidden"),null===(t=document.querySelector("#gc-error-modal-btn"))||void 0===t||t.click())}})}naviateToConfirmation(){window.history.replaceState({},"","/gift-certificate/confirmation/?result_msg=APPROVAL"),window.location.href="/gift-certificate/confirmation/?result_msg=APPROVAL"}addInputEventListeners(){document.querySelectorAll("#gc-purchaser-details input").forEach(e=>{null==e||e.addEventListener("input",this.handleInputEvent.bind(this,e))})}handleInputEvent(e){if(!(null==e?void 0:e.name))return;const i={},t=e.name.toLowerCase();t.includes("first-name")?this.validateField(e,i,{type:"firstName",required:!0,regex:s.REGEX.sendName,emptyMsg:"Please enter a valid first name",invalidMsg:"Please enter a valid first name"}):t.includes("last-name")?this.validateField(e,i,{type:"lastName",required:!0,regex:s.REGEX.sendName,emptyMsg:"Please enter a valid last name",invalidMsg:"Please enter a valid last name"}):t.includes("email")&&(t.includes("confirm")?this.validateField(e,i,{type:"confirmEmail",required:!0,matchFieldId:"purchaser-email",emptyMsg:"Please confirm the email address",mismatchMsg:"Email addresses do not match"}):this.validateField(e,i,{type:"email",required:!0,regex:s.REGEX.sendEmail,emptyMsg:"Please enter a valid email address",invali
1dMsg:"Please enter a valid email address"})),Object.keys(i).length>0&&this.showErrors(i),i[null==e?void 0:e.id]||this.clearFieldError(null==e?void 0:e.id)}showErrors(e){var i;if(!e||"object"!=typeof e)return;Object.entries(e).forEach(([e,i])=>{var t;const a=document.getElementById(e),l=document.getElementById(`${e}-error-msg`);null===(t=null==a?void 0:a.classList)||void 0===t||t.add("invalid-field"),l&&(l.textContent=i,l.classList.remove("hidden"))});const t=Object.keys(e)[0];t&&(null===(i=document.getElementById(t))||void 0===i||i.focus())}validateNameField(e,i,t,a,l){(!(null==e?void 0:e.value)||a&&!a.test(e.value))&&(i[e.id]=null!=l?l:`Please enter a valid ${"firstName"===t?"first":"last"} name`)}validateEmailField(e,i,t,a){(!(null==e?void 0:e.value)||t&&!t.test(e.value))&&(i[e.id]=null!=a?a:"Please enter a valid email address")}validateConfirmEmail(e,i,t,a){if(!(null==e?void 0:e.id))return;const l=document.getElementById(t);e.value&&(null==l?void 0:l.value)&&e.value===l.value||(i[e.id]=null!=a?a:"Email addresses do not match")}validateField(e,i,t){var a;if(""===(null==e?void 0:e.value))if(!t.required||e.value)switch(t.type){case"firstName":case"lastName":this.validateNameField(e,i,t.type,t.regex,t.invalidMsg);break;case"email":this.validateEmailField(e,i,t.regex,t.invalidMsg);break;case"confirmEmail":t.matchFieldId&&this.validateConfirmEmail(e,i,t.matchFieldId,t.mismatchMsg)}else i[e.id]=null!==(a=t.emptyMsg)&&void 0!==a?a:"Field is required";else this.hideError(null==e?void 0:e.id)}clearFieldError(e){var i,t;if(!e)return;const a=document.getElementById(e),l=document.getElementById(`${e}-error-msg`);null===(i=null==a?void 0:a.classList)||void 0===i||i.remove("invalid-field"),null===(t=null==l?void 0:l.classList)||void 0===t||t.add("hidden")}hideError(e){var i;if(!e)return;const t=document.getElementById(`${e}-error-msg`);null===(i=null==t?void 0:t.classList)||void 0===i||i.add("hidden")}handleMobileInput(e){e.preventDefault();const i=document.getElementById("purchaser-phone-number");if(!i)return;const t=s.REGEX.mobileNumberRegex,a=(null==i?void 0:i.value)||"",l=null==a?void 0:a.replace(/\D/g,""),n=null==t?void 0:t.exec(l||"");
1if(a&&(null==a?void 0:a.length)<14&&(!n||n[0].length<10)){const e=document.getElementById("purchaser-phone-number-error-msg");e&&(e.textContent="Invalid phone format.",e.classList.remove("hidden"))}else this.hideError("purchaser-phone-number");if(n){let e;if(n[2]){const i=n[3]?`-${n[3]}`:"";e=`(${n[1]}) ${n[2]}${i}`}else e=n[1];i.value=e}}isValidForm(){var e,i;document.querySelectorAll(".error-msg").forEach(e=>{e instanceof HTMLElement&&e.classList.add("hidden")}),document.querySelectorAll(".invalid-field").forEach(e=>{e.classList.remove("invalid-field")});const t={},a=e=>document.getElementById(e),l=a("purchaser-first-name"),n=a("purchaser-last-name"),r=a("purchaser-phone-number"),d=a("purchaser-email"),o=a("purchaser-confirmemail");if(!(l&&n&&r&&d&&o))return console.error("One or more form inputs are missing"),!1;if(this.validateField(l,t,{type:"firstName",required:!0,regex:s.REGEX.sendName,emptyMsg:"Please enter a valid first name",invalidMsg:"Please enter a valid first name"}),this.validateField(n,t,{type:"lastName",required:!0,regex:s.REGEX.sendName,emptyMsg:"Please enter a valid last name",invalidMsg:"Please enter a valid last name"}),this.validateField(d,t,{type:"email",required:!0,regex:s.REGEX.sendEmail,emptyMsg:"Please enter a valid email address",invalidMsg:"Please enter a valid email address"}),this.validateField(o,t,{type:"confirmEmail",required:!0,matchFieldId:"purchaser-email",emptyMsg:"Please confirm the email address",mismatchMsg:"Email addresses do not match"}),(null==r?void 0:r.required)&&!r.value){const a=null!==(i=null===(e=document.getElementById(`${r.id}-error-msg`))||void 0===e?void 0:e.innerText)&&void 0!==i?i:"Please enter a valid Phone Number";t[r.id]=a}else r&&(null==r?void 0:r.required)&&r.value.length<this.PHONE_NUMBER_LENGTH&&(t[r.id]="Please enter a valid Phone Number");return this.showErrors(t),0===Object.keys(t).length}}}}]); 2//# sourceMappingURL=opus2.gift-purchase-loader.510623a72929033fa9bb.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.