window.kon = window.kon || {} kon.attr = (function () { var variable; var data; var grp; var order; function setVariable(vars) { kon.attr.variable = vars; } function setData(dataset) { kon.attr.data = dataset; } function setGroup(group) { kon.attr.grp = group; } /* 기본 */ function AM1(option) { var div = createnode("div", "", { "class": "m-1" }) var table = createnode("TABLE", "", { "class": "table table-sm table-bordered", "style": "table-layout:fixed" }), attr = kon.attr.data.attr var oflag = option.oflag || "0"; // 순차보기 상태값 var colgroup = "" if (option.labelWidths) { /* 너비 지정 */ var a = option.labelWidths.split(","); var col = a.map(function (e) { if ($.isNumeric(+e)) { return createnode("col", "", { "width": e + "%" }) } else { return createnode("col", "", { "width": "" }) } }) colgroup = createnode("colgroup", col, ""); table.appendChild(colgroup) } kon.attr.order = Object.keys(kon.attr.data).map(function (k) { return k === "attr" ? false : k }) var attrheader = get(kon.attr.grp, ["header"]) || {}; if (!isEmptyObject(attrheader)) { Object.keys(attrheader).forEach(function (key, id) { var headertr = createnode("TR", "", {"class":"scale_label"}); attrheader[key].forEach(function (element) { headertr.appendChild(createnode("TD", element.label, { "colspan": element.cols, "rowspan": element.rows, "class": "bg-light text-center align-middle", "style": "font-size:calc(9px + 0.8vw);" })); }); if (Object.keys(attrheader).length !== id + 1) { table.appendChild(headertr); } else { kon.attr.order.map(function (type) { // 헤더에 보기 추가 if (!kon.attr.data[type]) return false; var target = kon.attr.data[type]; Object.keys(target).forEach(function (key,i) { headertr.appendChild(createnode("TD", target[key].label, { "class": "bg-light text-center align-middle", "style": "font-size:calc(9px + 0.8vw);", "id": "header_" + (i+1) })); }); }) table.appendChild(headertr); } }) } else { var headertr = createnode("TR", "", { "class": "bg-light text-center align-middle scale_label", "style": "font-size:calc(9px + 0.8vw);" }); headertr.appendChild(createnode("TD", "", { "style": "min-width:200px" })) kon.attr.order.map(function (type) { // 헤더에 보기 추가 if (!kon.attr.data[type]) return false; var target = kon.attr.data[type]; Object.keys(target).forEach(function (key) { headertr.appendChild(createnode("TD", target[key].label, { "class": "bg-light text-center align-middle", "style": "font-size:calc(9px + 0.8vw);", "id": "header_" + (target[key].value || key) })); }) }) table.appendChild(headertr); } Object.keys(attr).forEach(function (key, id) { // 속성 값 기준으로 반복 속성 개수 = 행 개수 var tr if (oflag === "1" && id > 0) tr = createnode("TR", "", { "id": "row_attr_" + attr[key].value, "style": "display:none" }) else tr = createnode("TR", "", { "id": "row_attr_" + attr[key].value }); var prev = get(kon.attr.grp, ["prev", id]) // 해당 열에 이전 속성 라벨 있는 지 var after = get(kon.attr.grp, ["after", id]) // 해당 열에 이후 속성 라벨 있는 지 if (prev) { //해당 열 이전 속성 prev.forEach(function (ele) { var td = createnode("TD", ele.label, { "colspan": ele.cols, "rowspan": ele.rows, "class": "bg-light text-left align-middle", "style": "font-size:calc(9px + 0.8vw);" }); tr.appendChild(td); }) } var mainlabel if (attr[key].etc === "1") { var input_text = createnode("INPUT", "", { "type": "text", "name": kon.attr.variable + "_" + attr[key].value + "_AT", "class": "d-block w-100", "disabled": "true" }); var input_chck = createnode("INPUT", "", { "type": "checkbox"}); mainlabel = createnode("TD", attr[key].label, { "class": "bg-light text-left align-middle", "style": "font-size:calc(9px + 0.8vw);", "id": "attr_" + attr[key].value }); // 해당 열 메인 속성 삽입 $(input_chck).click(function(e){ var $target = $(e.target); if(e.target.checked) { $target.next().val("").prop("disabled",false); $target.closest("TR").find("[data-etc-attr=1]").prop("disabled",false); } else { $target.next().val("").prop("disabled",true); $target.closest("TR").find("[data-etc-attr=1]").prop("disabled",true); $target.closest("TR").find("input[type=text], input[type=number]").val("") } }) mainlabel.appendChild(input_chck); mainlabel.appendChild(input_text); } else { mainlabel = createnode("TD", attr[key].label, { "class": "bg-light text-left align-middle", "style": "font-size:calc(9px + 0.8vw);", "id": "attr_" + attr[key].value }); // 해당 열 메인 속성 삽입 } tr.appendChild(mainlabel); if (after) { //해당 열 이후 보기 after.forEach(function (ele) { var td = createnode("TD", ele.label, { "colspan": ele.cols, "rowspan": ele.rows, "class": "bg-light text-left align-middle", "style": "font-size:calc(9px + 0.8vw);" }); tr.appendChild(td); }) } var td = kon.attr.order.map(function (type) { if (!kon.attr.data[type]) return false; var target = kon.attr.data[type]; var td = Object.keys(target).map(function (key2) { var t = createnode("TD", "", { "class": "text-center align-middle bg-white" }); var ipat = {}; var input; if (type === "open") { // 2025-06-26 권민서 - 기능 추가 및 수정 // if(target[key2].option === "inputHangulOnly") { // 한글만 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s]/g, '')"; // } else if(target[key2].option === "inputEnglishOnly") { // 영문만 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^a-zA-Z\\s]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^a-zA-Z\\s]/g, '')"; // } else if(target[key2].option === "inputNumberOnly") { // 숫자만 입력 // ipat["type"] = "number"; // ipat["onkeyup"] = "value = value.replace(/[^0-9]/g,'')"; // ipat["onchange"] = "value = value.replace(/[^0-9]/g,'')"; // } else if(target[key2].option === "inputHangulWithSymbols") { // 한글과 특수문자 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // } else if(target[key2].option === "inputEnglishWithSymbols") { // 영문과 특수문자 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^a-zA-Z\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^a-zA-Z\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // } else if(target[key2].option === "inputAllAllowed") { // 모든 문자 입력 // ipat["type"] = "text"; // } else { // ipat["type"] = "text" // } if (target[key2].option === "num") { ipat["type"] = "number" ipat["onkeyup"] = "value = value.replace(/[^0-9]/g,'')"; ipat["onchange"] = "value = value.replace(/[^0-9]/g,'')"; } else { ipat["type"] = "text" } ipat["style"] = "width:100%" ipat["name"] = kon.attr.variable + "_" + key2 + "_" + attr[key].value ipat["prev"] = target[key2].prev || "" ipat["after"] = target[key2].after || "" ipat["label"] = "" } else { ipat["type"] = type === "multi" ? "checkbox" : "radio"; //20220125 박준성 value가 있어야 하는 곳에 value값 ipat["name"] = type === "multi" ? kon.attr.variable + "_" + target[key2].value + "_" + attr[key].value : kon.attr.variable + "_" + attr[key].value //ipat["name"] = type === "multi" ? kon.attr.variable + "_" + key2 + "_" + attr[key].value : kon.attr.variable + "_" + attr[key].value } if(target[key2].etc === "1") { ipat["data-etc"] = "1" ipat["data-etc-name"] = "T"+ipat["name"] } if (type === "open") input = createnode("DIV", [make_input_text(ipat, kon.attr.variable + "_" + key2 + "_" + attr[key].value)]); else { ipat["value"] = target[key2].value input = createnode("INPUT", "", ipat); } if (attr[key].etc === "1") { if(type === "open") { $(input).find("input").attr("data-etc-attr", "1"); $(input).find("input").prop("disabled",true); } else { input.setAttribute("data-etc-attr", "1"); $(input).prop("disabled",true); } } t.appendChild(input); return t; }) return td; }) td.forEach(function (tdele) { if (tdele) appendChild_m(tr, tdele); }) table.appendChild(tr); }) div.appendChild(table) $("#question_body").append(div); attr_etc_open() if (oflag === "1") attr_order(); // 순차보기 이벤트 var nextFunc = function (pvar, pattr, pdataset, porder) { var vars = pvar || kon.attr.variable var attr = pattr || kon.attr.data.attr var dataset = pdataset || kon.attr.data var order = porder || kon.attr.order return kon.attr.attr_page_logic(vars, attr, dataset, order); }; return nextFunc } /* 보기 - 속성 뒤집기 */ function AM2(option) { var div = createnode("div", "", { "class": "m-1" }) var table = createnode("TABLE", "", { "class": "table table-sm table-bordered m-1", "style": "table-layout:fixed;word-break:break-word" }), attr = kon.attr.data.attr var oflag = option.oflag || "0"; // 순차보기 상태값 var colgroup = "" if (option.labelWidths) { /* 너비 지정 */ var a = option.labelWidths.split(","); var col = a.map(function (e) { if ($.isNumeric(+e)) { return createnode("col", "", { "width": e + "%" }) } else { return createnode("col", "", { "width": "" }) } }) colgroup = createnode("colgroup", col, ""); table.appendChild(colgroup) } kon.attr.order = Object.keys(kon.attr.data).map(function (k) { return k === "attr" ? false : k }) var headertr = createnode("TR", "", { "class": "bg-light text-center align-middle scale_label", "style": "font-size:calc(9px + 0.8vw);" }); headertr.appendChild(createnode("TD", " ", { "style": "min-width:200px" })) Object.keys(attr).forEach(function (key) { headertr.appendChild(createnode("TD", attr[key].label, { "class": "bg-light text-center align-middle scale_label", "style": "font-size:calc(9px + 0.8vw);", "id": "header_" + (attr[key].value || key) })); }) table.appendChild(headertr); kon.attr.order.forEach(function (type) { if (!kon.attr.data[type]) return false; var target = kon.attr.data[type]; Object.keys(target).forEach(function (key2, id) { var tr if (oflag === "1" && id > 0) tr = createnode("TR", "", { "style": "display:none" }) else tr = createnode("TR", ""); var td = Object.keys(attr).map(function (key) { var t = createnode("TD", "", { "class": "text-center align-middle bg-white" }); var ipat = {} var input if (type === "multi") { ipat["type"] = "checkbox" ipat["name"] = kon.attr.variable + "_" + target[key2].value + "_" + attr[key].value//////박준성 20221004 name 수정 } else if (type === "open") { // 2025-06-26 권민서 - 기능 추가 및 수정 // if(target[key2].option === "inputHangulOnly") { // 한글만 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s]/g, '')"; // } else if(target[key2].option === "inputEnglishOnly") { // 영문만 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^a-zA-Z\\s]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^a-zA-Z\\s]/g, '')"; // } else if(target[key2].option === "inputNumberOnly") { // 숫자만 입력 // ipat["type"] = "number"; // ipat["onkeyup"] = "value = value.replace(/[^0-9]/g,'')"; // ipat["onchange"] = "value = value.replace(/[^0-9]/g,'')"; // } else if(target[key2].option === "inputHangulWithSymbols") { // 한글과 특수문자 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^ㄱ-ㅎ가-힣\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // } else if(target[key2].option === "inputEnglishWithSymbols") { // 영문과 특수문자 입력 // ipat["type"] = "text"; // ipat["onkeyup"] = "value = value.replace(/[^a-zA-Z\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // ipat["onchange"] = "value = value.replace(/[^a-zA-Z\\s!@#\\$%\\^&\\*\\(\\)_\\+=\\-\\.,]/g, '')"; // } else if(target[key2].option === "inputAllAllowed") { // 모든 문자 입력 // ipat["type"] = "text"; // } else { // ipat["type"] = "text" // } if (target[key2].option === "num") { ipat["type"] = "number" ipat["onkeyup"] = "value = value.replace(/[^0-9]/g,'')"; ipat["onchange"] = "value = value.replace(/[^0-9]/g,'')"; } else ipat["type"] = "text" ipat["style"] = "width:100%" ipat["name"] = kon.attr.variable + "_" + key2 + "_" + attr[key].value ipat["prev"] = target[key2].prev || "" ipat["after"] = target[key2].after || "" ipat["label"] = "" } else { ipat["type"] = "radio" ipat["name"] = kon.attr.variable + "_" + attr[key].value } if (type === "open") input = createnode("DIV", [make_input_text(ipat, kon.attr.variable + "_" + key2 + "_" + attr[key].value)]); else input = createnode("INPUT", "", { "type": ipat.type, "name": ipat.name, "value": target[key2].value }); t.appendChild(input); if (target[key2].etc === "1") { /* 기타 처리 */ input.setAttribute("data-etc-bogi", "1"); /* input에 기타 코드 => (있음 : 1) 부여 */ t.appendChild(createnode("INPUT", "", { "type": "text", "name": "T" + ipat["name"], "disabled": "true", "class": "d-block w-100" })); /* 기타 입력란 */ } return t; }) //////박준성 20221004 id 수정 td.splice(0, 0, createnode("TD", target[key2].label, { "class": "bg-light text-left align-middle", "style": "font-size:calc(9px + 0.8vw);", "id": "attr_" + (target[key2].value!=undefined?target[key2].value:key2) })) tr.appendM(td); table.appendChild(tr); }) }) div.appendChild(table) $("#question_body").append(div); attr_etc_open(); if (oflag === "1") attr_order(); // 순차보기 이벤트 var nextFunc = function (pvar, pattr, pdataset, porder) { var vars = pvar || kon.attr.variable var attr = pattr || kon.attr.data.attr var dataset = pdataset || kon.attr.data var order = porder || kon.attr.order return kon.attr.attr_page_logic(vars, attr, dataset, order); }; return nextFunc } function AM_ROTA_FOLLOW(option) { var keyarr if (option) { if (option.prev) kon.survey.filter_example(kon.attr.data.attr, option.prev) var temp = {} if ((option.rota || "") !== "") { var keys = Object.keys(kon.attr.data.attr) option.rota = option.rota.trim() /* 항목별 로테이션 */ if (option.rota[0].toLocaleUpperCase() === "G") { /* EX) G[1~3/0] 형식 맞는 지 확인 */ if (regex_test(/[gG]\[[\d\~\/\,\-]+\]$/, option.rota)) { /* G[] 생략 */ var rota_option = option.rota.replace(/[\[\]gG]/g, ""); var cnt = 1 /* "," 로 구별 */ rota_option = rota_option.split(","); /* 구분된 값 돌려~ */ rota_option.forEach(function (txt) { txt = txt.split("/"); /* 범위와 로테이션 옵션 나눔 */ number = txt[0].split("~"); /* 범위 min , max 나눔 */ fkey = keys.gmap(function (k) { /* (gmap = map + filter) 범위에 맞는 키 filter and map */ if ((+k) >= +number[0] && (+k) <= +number[1]) return k; return false; }) fkey = arr_rota(fkey, +txt[1]) /* 키별 로테이션 */ fkey.forEach(function (fk) { temp[cnt] = kon.attr.data.attr[fk]; cnt += 1; }) }) kon.attr.data.attr = temp; } } else { keyarr = arr_rota(Object.keys(kon.attr.data.attr), +option.rota); keyarr.forEach(function (v, i) { temp[i + 1] = kon.attr.data.attr[v]; }) kon.attr.data.attr = temp; } } } return kon.attr[option.stype || "AM1"](option); } /* 속성 기타 오픈 */ function attr_etc_open() { $("body").on("click", "input[type=checkbox][data-etc-attr=1]", function (e) { $target = $(e.target); if ($target.prop("checked")) { $target.closest("TR").find("input[type=text]").prop("disabled", false) } else { $target.closest("TR").find("input[type=text]").prop("disabled", true).val("") } }); $("body").on("click", "input[type=checkbox][data-etc-bogi=1]", function (e) { $target = $(e.target); if ($target.prop("checked")) { $target.closest("TD").find("input[type=text]").prop("disabled", false) } else { $target.closest("TD").find("input[type=text]").prop("disabled", true).val("") } }); } /* 순차 보기 */ function attr_order() { $("body").on("click change input", "input[name^=" + kon.attr.variable + "]", function (e) { var $target = $(e.target); var $next = $target.closest("TR").next(); if($next.length > 0){ $next.css("display", "table-row"); var y = $next.position().top - 10; $("html, body").animate( {scrollTop: y + "px"}, 200); } }) } /* 속성 기본로직 */ function attr_page_logic(vars, attr, dataset, order) { var bools = true; //var attr = kon.attr.data.attr; $.each(order, function (id, type) { if (!dataset[type]) return true; if (type === "scale" || type === "single") { $.each(Object.keys(attr), function (id, key) { if ($("input[name=" + vars + "_" + attr[key].value + "]:checked").length === 0) { //박준성 20220222 disabled 수정 if ($("input[name=" + vars + "_" + attr[key].value + "]:not(:disabled)").length === 0 ) return true; //if ($("input[name=" + vars + "_" + attr[key].value + "]").prop("disabled") || $("input[name=" + vars + "_" + attr[key].value + "]").length === 0 ) return true; alert(kon.qmake.alert["문항에 응답해주세요."]); $("input[name=" + vars + "_" + attr[key].value + "][value=1]").focus(); $("#row_attr_"+attr[key].value).find("td:has(input)").removeClass("bg-white").css("background-color","#d9ffd685"); bools = false; return false; } }); } else if (type === "multi") { $.each(Object.keys(attr), function (id, key) { if ($("input[type=checkbox][name^="+ vars +"_][name$=_" + attr[key].value + "]:checked").length === 0) { //박준성 20220222 disabled 수정 if ($("input[type=checkbox][name^="+ vars +"_][name$=_" + attr[key].value + "]:not(:disabled)").length === 0 ) return true; //if ($("input[type=checkbox][name^="+ vars +"_][name$=_" + attr[key].value + "]").prop("disabled") || $("input[type=checkbox][name^="+ vars +"_][name$=_" + attr[key].value + "]").length === 0 ) return true; alert(kon.qmake.alert["문항에 응답해주세요."]); $("input[type=checkbox][name^="+ vars +"_][name$=_" + attr[key].value + "][value=1]").focus(); console.log("----multi") bools = false; return false; } }); } else if (type === "open") { $.each(Object.keys(dataset[type]), function (id, key) { var attr_option = dataset[type][key] if (attr_option.min !== undefined && !$.isNumeric(attr_option.min)) { var min = kon.survey.tv[attr_option.min] if (min) attr_option.min = min else attr_option.min = 0 } if (attr_option.max !== undefined && !$.isNumeric(attr_option.max)) { var max = kon.survey.tv[attr_option.max] if (max) attr_option.max = max else attr_option.max = 100 } $.each(Object.keys(attr), function (id, key2) { if (attr_option["must"] === "1") { //var target = $("input[name=" + vars + "_" + key + "_" + key2 + "]:not(:disabled)"); //박준성 20220426 attr open 속성 Value 사용 수정 var target = $("input[name=" + vars + "_" + key + "_" + attr[key2].value + "]:not(:disabled)"); if (target.length === 0) return true; if (target.val().trim() === "") { target.focus(); alert(kon.qmake.alert["문항에 응답해주세요."]); console.log("----open") bools = false; return false; } if ($.isNumeric(attr_option.min) && $.isNumeric(attr_option.max)) { var number = (+target.val()); if (+(attr_option.min) > number || +(attr_option.max) < number) { alert(kon.qmake.alert["[min] ~ [max] 사이로 응답해주세요."].replace("[min]", attr_option.min).replace("[max]", attr_option.max)); bools = false; return false; } } } return bools; /* 오픈 조건 for 속성 */ }); return bools; /* 오픈 for 오픈 */ }) } return bools; /* 속성 보기 들 */ }) if (bools) { $("input[type=text][name^=T"+vars+"_]:not(:disabled), input[type=text][name^="+ vars +"_][name$=_AT]:not(:disabled)").each(function (id, item) { if (item.value === "") { alert(kon.qmake.alert["문항에 응답해주세요."]); bools = false; return false; } }) } return bools; } var module = { /* variable */ variable: variable, data: data, grp: grp, order: order, /* function */ setVariable: setVariable, setData: setData, setGroup: setGroup, attr_page_logic: attr_page_logic, AM1: AM1, AM2: AM2, AM_ROTA_FOLLOW: AM_ROTA_FOLLOW } return module; })();