(() => { // webpackBootstrap var __webpack_exports__ = {}; (() => { const { pageHelper, EventManager, utils } = ShopbySkin; const articleWriteFormLayerModalHelper = pageHelper.articleWriteFormLayerModalHelper(); articleWriteFormLayerModalHelper.initialize({ layerModalHelperKey: 'article-write-form', }); const boardNo = '277061'; const internationalTelephoneInput = (() =>{ // HTML 입력 필드에 대한 인스턴스 생성 const tel = document.querySelector("[name='tel']"); // International Telephone Input 초기화 const iti = window.intlTelInput(tel, { // 옵션 설정 (선택 사항) nationalMode: false, utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.12/js/utils.js", // 추가 스크립트 로드 }); // 전화번호가 변경될 때 이벤트 처리 //tel.addEventListener("change", function () { // const selectedCountryData = iti.getSelectedCountryData(); // console.log("국가코드:", selectedCountryData.iso2); // console.log("전화번호:", iti.getNumber()); //}); return iti; })(); const getCapchaKey = () => { return (new Date()).getTime().toString(); }; const getCapchaImage = async (key) => { const res = await fetch(`https://shop-api.shopby.co.kr/captcha/image?key=${key}`, { method: 'GET', headers: { 'Content-Type': 'application/json', Version: '1.0', clientId: '99ZDpWfrizZV8irrjPvB8w==', platform: 'PC', language: 'ko', }, }).then((res) => res.json()); return res.url; }; const verifyCapcha = async (key, code) => { const res = await fetch(`https://shop-api.shopby.co.kr/captcha/verify?key=${key}&code=${code}`, { method: 'POST', headers: { 'Content-Type': 'application/json', Version: '1.0', clientId: '99ZDpWfrizZV8irrjPvB8w==', platform: 'PC', language: 'ko', }, }); return ( res.status === 204 || res.status === 200 ); }; const refreshCapcha = async () => { const key = getCapchaKey(); getCapchaImage(key).then((url) => { document.querySelector('.captcha_key').value = key; document.querySelector('.captcha_image').src = url; document.querySelector('.captcha_image').style.visibility = ''; document.querySelector('.captcha_code').value = ''; }); } const getFormData = (formElement) => { const formData = new FormData(formElement); return { inquiryType: formData.get('inquiryType'), companyName: formData.get('companyName'), managerName: formData.get('managerName'), productKind: formData.get('productKind'), tel: formData.get('tel'), email: formData.getAll('email[]').join('@').trim(), title: formData.get('title'), content: formData.get('content').replaceAll(/\n/g, '
'), agreement: formData.get('agreement'), } } const checkInvalidPostForm = async (data) => { if (!data.inquiryType) { return { message: 'Please select the type of inquiry.', invalid: true }; } if (!data.companyName) { return { message: 'Please enter the company name.', invalid: true }; } if (!data.managerName) { return { message: 'Please enter the name of the person in charge.', invalid: true }; } if (!data.productKind) { return { message: 'Please enter the product you are looking for.', invalid: true }; } if (!data.tel) { return { message: 'Please enter your contact information.', invalid: true }; } if (!internationalTelephoneInput.isValidNumber()) { return { message: 'Please enter a valid contact information.', invalid: true }; } if ('@' == data.email) { return { message: 'Please enter your email.', invalid: true }; } if (!/^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\-]+\.[A-Za-z0-9\-]+/.test(data.email)) { return { message: 'Please enter a valid email.', invalid: true }; } if (!data.title) { return { message: 'Please enter a title.', invalid: true }; } if (!data.content) { return { message: 'Please enter the content.', invalid: true }; } const captchaKey = document.querySelector('.captcha_key').value; const captchaCode = document.querySelector('.captcha_code').value; const isCaptchaVerified = await verifyCapcha(captchaKey, captchaCode); if (!isCaptchaVerified) { return { message: 'Please enter the characters to prevent automatic input correctly.', invalid: true }; } if ('on' != data.agreement) { return { message: 'Please agree to the collection and use of personal information.', invalid: true }; } return { message: '', invalid: false }; }; const filesUpload = async (files) => { const result = []; try { if ( true === files[0].type.startsWith('image') ) { await utils.postImages({ files: files, }).then((res)=>{ res.data.forEach((file) => { result.push({ originalFileName: file.value.originName, uploadedFileName: file.value.imageUrl }); }); }); } else { await utils.postFiles({ files: files, }).then((res)=>{ res.data.forEach((file) => { result.push(file.value); }); }); } } catch(e) { console.log(e); } return result; } const savePost = async (data) => { const combinedContents = '문의구분: ' + data.inquiryType + '
' + '업 체 명: ' + data.companyName + '
' + '담당자명: ' + data.managerName + '
' + '문의제품: ' + data.productKind + '
' + '연 락 처: ' + data.tel + '
' + '이 메 일: ' + data.email + '
' + '문의내용: ' + '
' + data.content + '
' ; const files = await filesUpload(document.querySelector('.upload_hidden').files); const { isSuccess } = await articleWriteFormLayerModalHelper.saveArticle({ articleNo: null, boardNo: boardNo, articleTitle: '[EN]' + data.title, articleContent: combinedContents, guestName: data.managerName, password: '1111', secreted: false, images: files, isModify: false, }); if (isSuccess) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', label: 'Confirm', message: 'Your inquiry has been accepted.
We will contact you after confirmation.
', onClose: () => { EventManager.fire('CLOSE_TITLE_MODAL'); window.location.href = '/en/index.html'; }, }); } } document.querySelector('.btn_inquiry').addEventListener('click', async (event) => { try { const formElement = document.forms['formContactUs']; const data = getFormData(formElement); const { message, invalid } = await checkInvalidPostForm(data); if (invalid) { console.log('invalid:', message); EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'WARNING', label: 'Confirm', message: `${message}`, }); return; } await savePost(data); } catch (e) { console.log(e); /* EventManager.fire('MODAL_ALERT_OPEN', { message: e.error.description ?? e.description, }); */ } }); document.querySelector('.btn_captcha_refresh').addEventListener('click', async (event) => { refreshCapcha(); }); EventManager.on('PAGE_LOAD_COMPLETED', (data) => { refreshCapcha(); }); })(); })(); // 240610 서주원 - 이메일 const emailSelect = document.querySelector('.email_select'); const emailDomainInput = document.querySelector('.e-domain'); emailSelect.addEventListener('change', function () { if (this.value === '') { emailDomainInput.value = ''; emailDomainInput.removeAttribute('readonly'); } else { console.log(this.value); emailDomainInput.value = this.value; emailDomainInput.setAttribute('readonly', true); } }); // 240610 서주원 - 파일업로드 var fileTargets = document.querySelectorAll('.area_filebox .upload_hidden'); fileTargets.forEach(function(fileTarget) { fileTarget.addEventListener('change', function() { let maxSize = 5 * 1024 * 1024; //* 5MB 사이즈 제한 let fileSize = this.files[0].size; //업로드한 파일용량 if(fileSize > maxSize){ openAlertModal("The file size is too large. (Maximum 5MB)"); this.value = ''; //업로드한 파일 제거 return; } var filename; if (window.FileReader) { filename = this.files[0].name; } else { filename = this.value.split('/').pop().split('\\').pop(); } var sibling = this.parentElement.querySelector('.upload_name'); if (sibling) { sibling.value = filename; } }); });