function initTemplete(type) { switch(type) { case 'poll': if(typeof window.template == 'undefined') { var source = jQuery("#entry-template").html(); window.template = Handlebars.compile(source); } break; case 'result': if(typeof window.template_result == 'undefined') { var source = jQuery("#entry-template-result").html(); window.template_result = Handlebars.compile(source); } break; case 'members': if(typeof window.template_member == 'undefined') { var source = jQuery("#entry-template-members").html(); window.template_member = Handlebars.compile(source); } break; } } /* 설문 참여 함수 */ function doPoll(fo_obj) { var checkcount = new Array(); var item = new Array(); for(var i=0;i-1) { var t = name.split('_'); var poll_srl_index = parseInt(t[1],10); checkcount[poll_srl_index] = obj.value; item[poll_srl_index] = new Array(); } else if(name.indexOf('item_')>-1) { var t = name.split('_'); var poll_srl = parseInt(t[1],10); var poll_srl_index = parseInt(t[2],10); if(obj.checked == true) item[poll_srl_index][item[poll_srl_index].length] = obj.value; } } var poll_srl_indexes = ""; for(var poll_srl_index in checkcount) { if(!checkcount.hasOwnProperty(poll_srl_index)) continue; var count = checkcount[poll_srl_index]; var items = item[poll_srl_index]; if(items.length < 1 || count < items.length) { alert(poll_alert_lang); return false; } poll_srl_indexes += items.join(',')+','; } fo_obj.poll_srl_indexes.value = poll_srl_indexes; jQuery.exec_json("poll.procPoll", {"poll_srl":poll_srl,"poll_srl_indexes":poll_srl_indexes}, function(data){ if(data.error!=0) alert(data.message); else { loadPollResult(poll_srl); jQuery("#poll_" + poll_srl + "_gotoresult_button").css({ display: "none" }); jQuery("#poll_" + poll_srl + "_result_nobutton").css({ display: "table-row" }); jQuery("#poll_" + poll_srl + "_result_yesbutton").css({ display: "none" }); } }); return false; } /* 항목 추가 함수 */ function addItem(poll_srl,poll_srl_indexes) { jQuery.exec_json("poll.procPollInsertItem", {"srl":poll_srl,"index_srl":poll_srl_indexes,"title":jQuery("#new_item_" + poll_srl_indexes).val()}, function(data){ if(data.error!=0) alert(data.message); else { jQuery("#poll_" + poll_srl + "_result_button").css({ display: "none" }); jQuery("#poll_" + poll_srl + "_result_nobutton").css({ display: "table-row" }); jQuery("#poll_" + poll_srl + "_result_yesbutton").css({ display: "none" }); loadPoll(poll_srl); } }); return false; } /* 항목 삭제 함수 */ function deleteItem(poll_srl,poll_srl_indexes,poll_item_srl) { jQuery.exec_json("poll.procPollDeleteItem", {"srl":poll_srl,"index_srl":poll_srl_indexes,"item_srl":poll_item_srl}, function(data){ if(data.error!=0) alert(data.message); else { jQuery("#poll_" + poll_srl + "_result_button").css({ display: "none" }); jQuery("#poll_" + poll_srl + "_result_nobutton").css({ display: "table-row" }); jQuery("#poll_" + poll_srl + "_result_yesbutton").css({ display: "none" }); loadPoll(poll_srl); } }); return false; } function loadPoll(poll_srl,data) { if(typeof data == 'undefined') { jQuery.exec_json("poll.getPollinfo", {"poll_srl":poll_srl}, function(data){ loadPoll(parseInt(data.poll.poll_srl),data); } } else { jQuery("#stop_date_"+poll_srl).html(data.poll.stop_date); initTemplete('poll'); var template = window.template; var context = Object; var additem = data.caniadditem; context.questions = {}; for (var i in data.poll.poll) { var poll = data.poll.poll[i]; context.questions[i] = {}; context.questions[i].poll_index_srl = poll.poll_index_srl; context.questions[i].checkcount = poll.checkcount; context.questions[i].title = poll.title; context.questions[i].items = poll.item; context.questions[i].poll_srl = poll_srl; context.questions[i].isMultipleChoice = (poll.checkcount>1); context.questions[i].additem = additem; } var html = template(context); jQuery("#poll_content_" + poll_srl).html(html); jQuery("#poll_" + poll_srl).css({ display: "block" }); jQuery("#poll_" + poll_srl + '_result').css({ display: "none" }); } } function showPollMemberNext(poll_srl,poll_item_srl) { if(typeof window.cur_page == 'undefined') { window.cur_page = 1; } window.cur_page++; jQuery.exec_json("poll.getPollitemInfo", {"poll_srl":poll_srl,"poll_item":poll_item_srl,"page":window.cur_page}, function(data){ initTemplete('members'); var template = window.template_member; var context = Object; context.poll_srl = poll_srl; context.poll_item_srl = poll_item_srl; context.page = window.cur_page; context.isPage = ((data.page.total_count>5) && (window.cur_page