(() => { const { EventManager, utils, constants, actions } = ShopbySkin; const url = new URL(window.location.href); const searchParams = new URLSearchParams(url.search); const boardId = searchParams.get('boardId'); const boardNo = searchParams.get('boardNo'); let shopbyCommonData = {}; EventManager.on('PAGE_LOAD_COMPLETED', (commonData) => { shopbyCommonData = commonData; }); const restrictionCauseMessageWithNextUrlMap = { MEMBER_ONLY: (writable) => { if (writable) { return {}; } return { modalType: 'MODAL_CONFIRM_OPEN', message: '로그인하셔야 본 서비스를 이용하실 수 있습니다.', nextUrl: `${location.origin}${constants.PAGE.SIGN_IN}`, }; }, SPECIFIC_MEMBERS: (writable) => { if (writable) { return {}; } if (!utils.isSignedIn()) return { modalType: 'MODAL_CONFIRM_OPEN', message: '로그인하셔야 본 서비스를 이용하실 수 있습니다.', nextUrl: `${location.origin}${constants.PAGE.SIGN_IN}`, }; return { modalType: 'MODAL_ALERT_OPEN', message: '글쓰기 권한이 없습니다.', }; }, }; const openArticleWriteForm = ({ boardName, canSecretPosting, usesAttachment }) => { const { boardConfigs = [] } = shopbyCommonData.allBoardConfig; EventManager.fire('OPEN_LAYER_MODAL', { name: 'article-write-form', title: boardName, data: { boardId, boardNo, canSecretPosting, usesAttachment, boardConfigs, isModify: false, }, onClose: ({ reason }) => { if (reason === 'DID_SUBMIT') { location.reload(); } }, }); }; const moduleActionHandler = { WRITE: ({ target }) => { const authorityType = target.closest('[shopby-authority-type]')?.getAttribute('shopby-authority-type'); const { profile, allBoardConfig } = shopbyCommonData; const { data: writable } = actions.queryBoardDisplayableStatus({ profile, boardNo, boardId, boardConfigs: allBoardConfig.boardConfigs, permissionType: constants.BOARD_PERMISSION_CONFIG_TYPE.WRITE_PERMISSION, }); const { message, modalType, nextUrl } = restrictionCauseMessageWithNextUrlMap[authorityType]?.(writable) ?? {}; if (message) { EventManager.fire(modalType, { message: `${message}`, noticeType: constants.NOTICE_MODAL_TYPE.WARNING, onConfirm: () => { if (!nextUrl) { return; } utils.moveTo({ url: `${nextUrl}?from=${encodeURIComponent(location.href)}` }); }, }); return; } const boardName = document.querySelector('[shopby-board-name]')?.getAttribute('shopby-board-name'); const canSecretPosting = target.closest('[shopby-can-secret-posting]')?.getAttribute('shopby-can-secret-posting'); const usesAttachment = target.closest('[shopby-uses-attachment]')?.getAttribute('shopby-uses-attachment'); openArticleWriteForm({ boardName, canSecretPosting, usesAttachment, }); }, GO_TO_DETAIL: (event) => { event.preventDefault(); const { target } = event; const linkEl = target?.href ? target : target.closest('[href]'); if (!linkEl) { return; } const { profile, allBoardConfig } = shopbyCommonData; const boardNo = linkEl.getAttribute('shopby-board-no'); const { data: readable } = actions.queryBoardDisplayableStatus({ profile, boardConfigs: allBoardConfig.boardConfigs, boardNo, boardId, permissionType: constants.BOARD_PERMISSION_CONFIG_TYPE.READ_PERMISSION, }); if (readable) { utils.moveTo({ url: linkEl.href }); } else { EventManager.fire('MODAL_ALERT_OPEN', { message: '게시글 읽기 권한이 없습니다.', noticeType: constants.NOTICE_MODAL_TYPE.WARNING, }); } }, }; document.querySelector('article-total-count-v2')?.addEventListener('click', ({ target }) => { const action = target.getAttribute('shopby-action'); moduleActionHandler[action]?.({ target }); }); document.querySelector('article-list-v2')?.addEventListener('click', (event) => { const action = event.target.getAttribute('shopby-action') ?? event.target.closest('[shopby-action]')?.getAttribute('shopby-action'); moduleActionHandler[action]?.(event); }); })();