var pollFunction = (function () { let limit = 10; let cursor = 0; return { getPollList: () => { commonFunction.aJax({ url: service_url + `/get-poll-list.php?limit=${limit}&cursor=${cursor}`, data: { }, type: "POST", done: function (response) { if (response.state) { const items = response.info.list; items.forEach((item) => { const buttons = (() => { // 진행중 if (item.status_code === '003') { return ` `; } else if (item.status_code === '004') { return ` `; } else { return ``; } })() const listItem = `
설문 관련 이미지
${item.category_name} | ${item.subject}
${item.status_name}

${item.contents}

설문 기간 ${item.start_date} ~ ${item.end_date} | 총 참여 ${commonFunction.addComma(item.votes_count)}명
${buttons}
`; $('#poll-list').append(listItem); }); cursor = response.info.next_cursor; if(!response.info.has_more) { $('#moreButtonBox').hide(); } } else { } $('#moreButtonBox').removeClass('invisible'); $('#loadingBar').addClass('invisible'); }, fail: function (error) { location.href = "/"; }, }); }, getPollDetail: ({mode}) => { commonFunction.aJax({ url: service_url + "/get-poll-detail.php?uid=" + pagePollUid, data: { }, type: "GET", done: function (response) { if (response.state) { const info = response.info; infoData = info; poll_id = infoData.poll_id; $('#poll_subject').append(info.poll_subject); $('#poll_created_at').append(`등록일 : ${info.poll_created_at}`); $('#poll_photo').append(`설문 관련 이미지`); $('#poll_contents').append(`${info.poll_contents}`); $('#poll_start_end').append(`${info.poll_start_date} ~ ${info.poll_end_date} |`); } else { } $('#poll-view').removeClass('invisible'); $('#loadingBar').addClass('invisible'); pollFunction.getPollOptions({mode: mode, poll_id: infoData.poll_id}); }, fail: function (error) { location.href = "/"; }, }); }, getPollOptions: ({mode, poll_id}) => { commonFunction.aJax({ url: service_url + "/get-poll-options.php?poll_id=" + poll_id, data: { }, type: "GET", done: function (response) { if (response.state) { const questions = response.info.questions[0]; $('#poll_vote_count').append(`총 참여 ${commonFunction.addComma(questions.total_votes)}명`); if(mode === 'status' || mode === 'result') { return; } let optionsHtml = ''; questions.options.forEach((option, index) => { optionsHtml += `
  • `; }); $('#poll-options-box').append(`

    Q. ${questions.question_text}

    `); } else { } }, fail: function (error) { location.href = "/"; }, }); }, getPollStatus: ({poll_id, poll_uid}) => { commonFunction.aJax({ // url: service_url + "/get-poll-status.php?poll_id=" + poll_id, url:(() => { if(poll_id) { return service_url + "/get-poll-status.php?poll_id=" + poll_id; } else if(poll_uid) { return service_url + "/get-poll-status.php?uid=" + poll_uid; } })(), data: { }, type: "GET", done: function (response) { if (response.state) { const info = response.info; const poll = info.poll; const questions = info.questions[0]; let optionsHtml = ""; questions.options.forEach((option, index) => { const optNum = index + 1 optionsHtml += `
  • ${optNum}. ${option.option_text}
    ${commonFunction.addComma(option.votes)}명 (${option.percent}%)
  • `; }); $('#poll-options-box').append(`

    Q. ${questions.question_text}

    `); } else { } $('#loadingBar').addClass('invisible'); }, fail: function (error) { location.href = "/"; }, }); }, }; })();