888 lines
37 KiB
JavaScript
888 lines
37 KiB
JavaScript
window.kon = window.kon || {}
|
||
|
||
kon.survey = (function () {
|
||
var url = "./survey.asp"
|
||
var userdata = {};
|
||
var PKEY = "";
|
||
var IDKEY = "";
|
||
var tv = {}; // 임시 저장 값
|
||
var jdata = ""; // 현재 페이지 값
|
||
var global_flag = "";
|
||
var global_variable = "";
|
||
function save(data, form, logic) {
|
||
$.ajax({
|
||
url: url,
|
||
data: data,
|
||
async: false, /* 동기 방식 */
|
||
method: "POST",
|
||
beforeSend: function () { /* 설문 페이지 안보이게 */
|
||
$("#wrapper").css("display", "none");
|
||
}, success: function (nextpage) {
|
||
|
||
var stringifydata = "";
|
||
var surveyType = form.find("input[name=SURVEYTYPE]").val();
|
||
var nextinput = form.find("input[name=NEXTPAGE]"); /* 다음페이지 찾기 */
|
||
var pagename = form.find("input[name=PAGENAME]").val();
|
||
var useprev = form.find("input[name=USEPREV]").val()?form.find("input[name=USEPREV]").val():pagename;
|
||
|
||
if (data.DATA !== "{}") { /* 데이터 있으면 저장 */
|
||
/* 페이지 입력 데이터들 정리 */
|
||
kon.survey.jdata = JSON.parse(data.DATA);
|
||
|
||
/* 입력 데이터 -> 전체 데이터에 씌움 */
|
||
Object.keys(kon.survey.jdata).forEach(function (key) {
|
||
kon.survey.tv[key] = kon.survey.jdata[key].replace(/,/g, "¸");
|
||
});
|
||
|
||
/* 문자열로 변환 */
|
||
stringifydata = JSON.stringify(kon.survey.tv);
|
||
stringifydata = stringifydata.replace(/'/g,"´");
|
||
ajax_call("./include/ajax.asp", { "DAT": stringifydata, "COMMAND": "SETDATA", "CODE": kon.survey.PKEY, "IDKEY": kon.survey.IDKEY })
|
||
}
|
||
|
||
/* 데이터 저장후 로직 체크 */
|
||
////////////////////////20230314 박준성 다음 페이지가 END 여도 로직 체크//////////////////////////////////////////
|
||
//if( nextpage !== "PREV" && nextpage !== "DOUBLE" && nextpage !== "NONE" && nextpage !== "SCREEN" && nextpage !== "QUOTA" && nextpage !== "CLOSE" && nextpage !== "ERROR" && nextpage !== "END")
|
||
if( nextpage !== "PREV" && nextpage !== "DOUBLE" && nextpage !== "NONE" && nextpage !== "SCREEN" && nextpage !== "QUOTA" && nextpage !== "CLOSE" && nextpage !== "ERROR" )
|
||
nextpage = logic_chk(logic, nextpage, "n");
|
||
|
||
|
||
/* 테스트 버전일 경우 SCREEN시 한 번 물어봄 */
|
||
if ($("input[name=SURVEYTYPE]").val() === "TEST" && nextpage === "SCREEN") {
|
||
if (!confirm(kon.qmake.alert["[설문 테스트 용] 선택하신 응답은 대상자 아님 입니다.\n 설문을 그대로 진행하시겠습니까?"])) {
|
||
/* 설문 진행안할 경우 데이터 삭제 */
|
||
Object.keys(kon.survey.jdata).forEach(function (key) {
|
||
kon.survey.tv[key] = ""
|
||
});
|
||
return false;
|
||
}
|
||
}
|
||
|
||
if (nextinput.val().trim() === "") {
|
||
switch (nextpage) {
|
||
case "PREV": case "DOUBLE": case "NONE": case "SCREEN": case "QUOTA": case "ERROR": case "END":
|
||
form.attr("action", "SurveyEnd.asp");
|
||
break;
|
||
}
|
||
nextinput.val(nextpage);
|
||
} else {
|
||
if (nextinput.val() === "END" || nextinput.val() === "SCREEN" || nextinput.val() === "QUOTA" ) {
|
||
form.attr("action", "SurveyEnd.asp");
|
||
}
|
||
}
|
||
|
||
if( nextinput.val() !== "PREV" && nextinput.val() !== "DOUBLE" && nextinput.val() !== "NONE" && nextinput.val() !== "SCREEN" && nextinput.val() !== "QUOTA" && nextinput.val() !== "ERROR" && nextinput.val() !== "END" ){
|
||
var plogicFunc = function(npg){
|
||
if(/Q[0-9]{1,4}/g.test(npg) === false){
|
||
return npg;
|
||
}
|
||
var qinfo = ajax_returnData("./include/ajax.asp", { "COMMAND": "QINFO", "CODE": kon.survey.PKEY, "QCODE": npg, "IDKEY": kon.survey.IDKEY }) /* 문항 정보 */
|
||
qinfo = qinfo[0];
|
||
var plgPage = kon.survey.logic_chk(qinfo.jx, npg, "p");
|
||
if(plgPage !== npg){
|
||
return plogicFunc(plgPage);
|
||
}else{
|
||
return plgPage;
|
||
}
|
||
}
|
||
var plogicpage = plogicFunc(nextinput.val());
|
||
nextinput.val(plogicpage);
|
||
if (nextinput.val() === "END" || nextinput.val() === "SCREEN" || nextinput.val() === "QUOTA" ) {
|
||
form.attr("action", "SurveyEnd.asp");
|
||
}
|
||
}
|
||
|
||
var p_page_arr = JSON.parse(sessionStorage.getItem("P_PAGE_"+kon.survey.IDKEY) || "[]");
|
||
if(p_page_arr.indexOf(useprev) == -1 && useprev != nextinput.val()){
|
||
p_page_arr.push(useprev);
|
||
sessionStorage.setItem("P_PAGE_"+kon.survey.IDKEY, JSON.stringify(p_page_arr));
|
||
}
|
||
sessionStorage.setItem("N_PAGE_"+kon.survey.IDKEY, nextinput.val());
|
||
|
||
var apiWaits = [];
|
||
if (nextinput.val() === "END") {
|
||
apiWaits.push(callKartDerived(kon.survey.PKEY, kon.survey.IDKEY));
|
||
}
|
||
|
||
if (surveyType === "LIST") {
|
||
var contactMappingList = ajax_returnData("/include/ajax_contact.asp", {
|
||
"CRUD": "SELECT",
|
||
"COMMAND": "CONTACT_SURVEY",
|
||
"PKEY": kon.survey.PKEY
|
||
});
|
||
|
||
if (Array.isArray(contactMappingList) && contactMappingList.length > 0) {
|
||
var statuses = [];
|
||
if (pagename === "INDEX") statuses.push("start");
|
||
if (["PREV", "END"].includes(nextinput.val())) statuses.push("complete");
|
||
else if (nextinput.val() === "SCREEN") statuses.push("screen");
|
||
else if (nextinput.val() === "QUOTA") statuses.push("quota");
|
||
|
||
if (statuses.length > 0) {
|
||
apiWaits.push(callContactStatusApi(contactMappingList, kon.survey.IDKEY, statuses));
|
||
}
|
||
}
|
||
}
|
||
|
||
submitNextPage(form, apiWaits);
|
||
}, error: function (x, h, r) {
|
||
console.log(x);
|
||
console.log(h);
|
||
console.log(r);
|
||
}
|
||
|
||
})
|
||
}
|
||
|
||
function submitNextPage(form, waits) {
|
||
|
||
// undefined 또는 잘못된 Promise 제거
|
||
waits = waits.filter(function (wait) {
|
||
return wait && typeof wait.always === "function";
|
||
});
|
||
|
||
var remaining = waits.length;
|
||
|
||
if (remaining === 0) {
|
||
form.attr("onsubmit", "");
|
||
form.submit();
|
||
return;
|
||
}
|
||
|
||
waits.forEach(function (wait) {
|
||
wait.always(function () {
|
||
remaining--;
|
||
|
||
if (remaining === 0) {
|
||
form.attr("onsubmit", "");
|
||
form.submit();
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
function logExternalApi(apiName, idkey, psidx, result, message) {
|
||
ajax_call("/include/ajax_contact.asp", {
|
||
"CRUD": "INSERT",
|
||
"COMMAND": "EXTERNAL_API_LOG",
|
||
"API_NAME": apiName,
|
||
"PKEY": kon.survey.PKEY,
|
||
"IDKEY": idkey,
|
||
"PSIDX": psidx == null ? "" : psidx,
|
||
"RESULT": result,
|
||
"HTTP_MESSAGE": message || ""
|
||
});
|
||
}
|
||
|
||
function apiErrorMessage(x, h, r) {
|
||
return "HTTP " + x.status + " | " + (r || h) + " | " + (x.responseText || "");
|
||
}
|
||
|
||
function callLoggedApi(url, apiName, idkey, psidx, message) {
|
||
var prefix = message ? message + " | " : "";
|
||
logExternalApi(apiName, idkey, psidx, "REQUEST", message);
|
||
return $.ajax({
|
||
url: url,
|
||
type: "POST",
|
||
contentType: "application/json; charset=utf-8",
|
||
cache: false,
|
||
async: true,
|
||
timeout: 30000,
|
||
success: function (data, h, x) {
|
||
logExternalApi(apiName, idkey, psidx, "SUCCESS", prefix + "HTTP " + x.status);
|
||
},
|
||
error: function (x, h, r) {
|
||
logExternalApi(apiName, idkey, psidx, "FAIL", prefix + apiErrorMessage(x, h, r));
|
||
console.log(x);
|
||
console.log(h);
|
||
console.log(r);
|
||
}
|
||
});
|
||
}
|
||
|
||
function callKartDerived(pkey, idkey) {
|
||
try{
|
||
var url = KART_BASE_URL
|
||
+ "/project/" + KART_PROJECT_TYPE
|
||
+ "/" + encodeURIComponent(pkey)
|
||
+ "/derived/respondent/" + encodeURIComponent(idkey)
|
||
+ "/recalculate";
|
||
|
||
logExternalApi("DERIVED", idkey, "", "REQUEST", "");
|
||
|
||
return $.ajax({
|
||
url: url,
|
||
type: "POST",
|
||
headers: {
|
||
"X-API-Key": KON_KIWI_API_KEY
|
||
},
|
||
dataType: "json",
|
||
cache: false,
|
||
timeout: 60000,
|
||
|
||
success: function (data, status, xhr) {
|
||
logExternalApi(
|
||
"DERIVED", idkey, "", "SUCCESS",
|
||
"HTTP " + xhr.status
|
||
);
|
||
},
|
||
|
||
error: function (xhr, status) {
|
||
logExternalApi(
|
||
"DERIVED", idkey, "", "FAIL",
|
||
"HTTP " + xhr.status + " / " + status
|
||
);
|
||
}
|
||
});
|
||
}
|
||
catch(ex){
|
||
return $.Deferred().resolve().promise();
|
||
}
|
||
}
|
||
|
||
function callContactStatusApi(contactMappingList, idkey, statuses) {
|
||
var allRequestsDone = $.Deferred();
|
||
var mappingsLeft = contactMappingList.length;
|
||
|
||
function finishMapping() {
|
||
mappingsLeft--;
|
||
if (mappingsLeft === 0) allRequestsDone.resolve();
|
||
}
|
||
|
||
contactMappingList.forEach(function (mapping) {
|
||
var targetSystem = String(mapping.TARGET_SYSTEM || "").toUpperCase();
|
||
var contactBaseUrl;
|
||
|
||
switch (targetSystem) {
|
||
case "PROD":
|
||
contactBaseUrl = "https://contact.kric.com";
|
||
break;
|
||
case "DEV":
|
||
contactBaseUrl = "https://test-contact.kric.com";
|
||
break;
|
||
case "LOCAL":
|
||
contactBaseUrl = "http://localhost:4000";
|
||
break;
|
||
default:
|
||
console.error("지원하지 않는 TARGET_SYSTEM:", mapping.TARGET_SYSTEM);
|
||
finishMapping();
|
||
return;
|
||
}
|
||
|
||
var nextStatusIndex = 0;
|
||
|
||
// 같은 매핑의 상태는 start 다음 complete 순서로 호출한다.
|
||
function sendNextStatus() {
|
||
if (nextStatusIndex >= statuses.length) {
|
||
finishMapping();
|
||
return;
|
||
}
|
||
|
||
var status = statuses[nextStatusIndex];
|
||
nextStatusIndex++;
|
||
|
||
var contactApiUrl = contactBaseUrl + "/api/external/" + status
|
||
+ "?psidx=" + encodeURIComponent(mapping.PSIDX)
|
||
+ "&sid=" + encodeURIComponent(idkey);
|
||
|
||
callLoggedApi(
|
||
contactApiUrl,
|
||
"CONTACT_" + status.toUpperCase(),
|
||
idkey,
|
||
mapping.PSIDX,
|
||
"TARGET_SYSTEM=" + targetSystem
|
||
).always(sendNextStatus);
|
||
}
|
||
|
||
sendNextStatus();
|
||
});
|
||
|
||
return allRequestsDone.promise();
|
||
}
|
||
|
||
function serializeform(form,arr) { /* 폼 데이터 정렬 */
|
||
var data = {}
|
||
var inputdata = {}
|
||
/* 기본 인풋 제외 */
|
||
var basis_info = ["USEPREV", "PAGENAME", "NEXTPAGE", "PCODE", "IDKEY", "SURVEYTYPE", "QNUMBER", "PCOLOR", "ROTATION","GLOBALVARIABLE","GLOBALSURVEY","CAMPAIGNID","TK","SPRINGID", "CONTACTPID"];
|
||
|
||
if(arr) {
|
||
if(typeof(arr) === "string") arr = [arr];
|
||
arr.forEach(function(v){ basis_info.push(v)})
|
||
}
|
||
form.find("input, select, textarea").each(function (id, ele) {
|
||
// disabled이거나 이름이 없으면 생략
|
||
if (!ele.name || ele.disabled) return true;
|
||
|
||
if (basis_info.indexOf(ele.name) < 0) {
|
||
if (ele.type === "radio" || ele.type === "checkbox") {
|
||
if (ele.checked) {
|
||
var chk_value = $(ele).val();
|
||
if( chk_value === "on" || chk_value === "ON") { /* on으로 저장할 경우 ERROR 처리 */
|
||
var error_to_end = function() {
|
||
go_post("./SurveyEnd.asp", { "IDKEY": kon.survey.IDKEY, "NEXTPAGE": "ERROR" });
|
||
}
|
||
var error_param = { "COMMAND": "ERROR_REPORT", "IDKEY": kon.survey.IDKEY , "QCODE": "-ON 에러", "CODE": kon.survey.PKEY }
|
||
var browername = isBrowerCheck();
|
||
error_param["ERRSTRING"] = "[ON 오류]" + "[B]" + browername;
|
||
ajax_call("./include/ajax.asp", error_param, error_to_end);
|
||
} else {
|
||
inputdata[ele.name] = chk_value;
|
||
}
|
||
}
|
||
|
||
} else {
|
||
inputdata[ele.name] = ele.value.replace(/,/g, "¸");
|
||
inputdata[ele.name] = inputdata[ele.name].replace(/'/g, "´");
|
||
}
|
||
} else {
|
||
data[ele.name] = ele.value.replace(/,/g, "¸");
|
||
}
|
||
})
|
||
|
||
if(form.find("input[name=PAGENAME]").val() == "INDEX"){
|
||
inputdata["TK"] = form.find("input[name=TK]").val();
|
||
}
|
||
|
||
data["DATA"] = JSON.stringify(inputdata);
|
||
return data;
|
||
}
|
||
|
||
function logic_chk(logic, nextpage, types) {
|
||
|
||
var page = nextpage;
|
||
if (logic) {
|
||
logic = JSON.parse(logic)
|
||
var logictarget = types === "n" ? logic.n : logic.p;
|
||
if (logictarget.length > 0) {
|
||
logictarget.some(function (l) {
|
||
var boolean = false;
|
||
l.condition.forEach(function (e) {
|
||
if (e.cd) {
|
||
if (e.cd === "or")
|
||
boolean = boolean || boolean_Expression(e.va, e.op, e.co);
|
||
else
|
||
boolean = boolean && boolean_Expression(e.va, e.op, e.co);
|
||
} else {
|
||
boolean = boolean_Expression(e.va, e.op, e.co);
|
||
}
|
||
})
|
||
|
||
if (boolean) {
|
||
page = l.nextpage;
|
||
return true;
|
||
}
|
||
})
|
||
}
|
||
};
|
||
return page;
|
||
}
|
||
/* va - 응답값 이름 , op - 조건, co - 비교값
|
||
* > 응답값이 없을 경우 주의 비교 연산자의 경우 +일때 0을 나타냄
|
||
*/
|
||
function boolean_Expression(va, op, co) {
|
||
var bools = false;
|
||
data = kon.survey.tv;
|
||
|
||
if (!data[va] && (op !== "=" && op !== "!=" ))
|
||
return false;
|
||
|
||
switch (op) {
|
||
case "=": bools = (data[va] || "") == co; break;
|
||
case ">": bools = +data[va] > +co; break;
|
||
case "<": bools = +data[va] < +co; break;
|
||
case ">=": bools = +data[va] >= +co; break;
|
||
case "<=": bools = +data[va] <= +co; break;
|
||
case "!=": bools = (data[va] || "") != co; break;
|
||
default: break;
|
||
}
|
||
|
||
return bools;
|
||
}
|
||
|
||
/* 라벨 치환 */
|
||
function replace_responed_label(qx, var_to_qid) {
|
||
if (!kon.survey.userdata) return false;
|
||
var rtitlevalue = regex_match(global.pattern.datalabel, qx.title); /* 타이틀에서 치환값 찾음 */
|
||
var rdesvalue = regex_match(global.pattern.datalabel, qx.description); /* 설명문에서 치환값 찾음 */
|
||
|
||
|
||
var rtitle = rtitlevalue.map(function (ele, id) { /* 타이틀에서 치환값에서 필요한 값 빼옴 */
|
||
var split_text = mid(ele.value, 2, ele.value.length - 4).split(",");
|
||
return {
|
||
"VAR": split_text[0],
|
||
"OPTION": split_text.length === 1 ? "" : split_text.slice(1),
|
||
"ALL": ele.value
|
||
}
|
||
});
|
||
|
||
var rdes = rdesvalue.map(function (ele, id) { /* 설명문에서 치환값에서 필요한 값 빼옴 */
|
||
var split_text = mid(ele.value, 2, ele.value.length - 4).split(",")
|
||
return {
|
||
"VAR": split_text[0], /* 가져올 값 */
|
||
"OPTION": split_text.length === 1 ? "" : split_text.slice(1), /* 옵션 */
|
||
"ALL": ele.value /* 전체 텍스트, replace 용 */
|
||
}
|
||
});
|
||
|
||
|
||
var r_title_variable = rtitle.map(function (item) { return item.VAR }); // 타이틀에서 문번 뽑기
|
||
var r_des_variable = rdes.map(function (item) { return item.VAR }); // 설명문에서 문번 뽑기
|
||
|
||
var totalreplace = r_title_variable.concat(r_des_variable); /* 타이틀 문번 + 설명문 문번 */
|
||
|
||
/* 중복 제거 및 문항 ID로 변환 */
|
||
totalreplace = totalreplace.gmap(function(v,id){
|
||
if(totalreplace.indexOf(v)===id)
|
||
return var_to_qid[v]; /* 문항 코드 => 문항 ID로 변환 */
|
||
else
|
||
return false;
|
||
});
|
||
|
||
var list = ajax_returnData(ajaxurl, { "COMMAND": "GETLINFO", "QLIST": totalreplace.join(","), "CODE": kon.survey.PKEY }) /* 변수 코드 매칭된 라벨 가져옴 */
|
||
|
||
for (var i = 0; i < list.length; i++) {
|
||
if (left(list[i].key, 1) !== "T")
|
||
list[i].value = JSON.parse(list[i].value); /* JSON 형은 JSON으로 파싱 */
|
||
}
|
||
|
||
list = array_filter_to_group(list, "key") /* 빠른 검색을 위해 Array -> Object */
|
||
|
||
|
||
if(kon.survey.global_flag === "1") { /* 다국어 번역 */
|
||
var qlist = totalreplace.map(function(v) { return "'" + v + "'"}).join(",")
|
||
var global_list = ajax_returnData(ajaxurl, { "COMMAND": "LINFOLIST", "QLIST": qlist , "CODE": kon.survey.PKEY, "LANGUAGE":kon.survey.userdata[kon.survey.global_variable] }) /* 변수 코드 매칭된 라벨 가져옴 */
|
||
global_list = JSON.parse(global_list);
|
||
global_list = array_filter_to_group(global_list,"QID")
|
||
|
||
////2023-03-231 박준성 다국어 값 치환 오류 수정 KON에 수정한 내용 같이 반영
|
||
Object.keys(list).forEach(function(key){
|
||
var gKey = key.split('_')[0];
|
||
////2023-03-231 박준성 다국어 값 치환 오류 수정 KON에 수정한 내용 같이 반영
|
||
if(global_list[gKey] != undefined){
|
||
global_list[gKey].forEach(function(v,i){
|
||
list[key][0].value[v.LCODE] = v.text
|
||
})
|
||
}
|
||
})
|
||
/*
|
||
Object.keys(global_list).forEach(function(key){
|
||
global_list[key].forEach(function(v,i){
|
||
list[key][0].value[v.LCODE] = v.text
|
||
})
|
||
})
|
||
*/
|
||
}
|
||
|
||
|
||
var replace_text = function (find, target) { /* 찾는 함수 */
|
||
/* 라벨 가져오기, */
|
||
var getLabel = function (variable, data) {
|
||
if (list[variable].length > 1) {
|
||
list[variable].some(function (item, id) {
|
||
if (data == item.key) {
|
||
rtitle = item.value;
|
||
return true;
|
||
}
|
||
})
|
||
} else {
|
||
rtitle = list[variable][0].value[data]
|
||
}
|
||
return rtitle;
|
||
}
|
||
|
||
find.forEach(function (ele) {
|
||
|
||
var variable = ele.VAR /* 문번 */
|
||
var qid = var_to_qid[variable]; /* 문번에 매칭된 QID */
|
||
ele.VAR = ele.VAR.replace(variable, qid); /* 문번 -> QID로 변경 */
|
||
var rtitle = "";
|
||
if (ele.OPTION) {
|
||
ele.OPTION.forEach(function (v) {
|
||
if (v === "all") { /* 문번에서 체크된 값 모두 가져오기 */
|
||
rtitle = Object.keys(list)
|
||
.filter(function (key) { if (key.split("_")[0] === qid && kon.survey.userdata[key]) return true })
|
||
.map(function (key) { return list[key][0].value[kon.survey.userdata[key]] });
|
||
} else if (regex_test(/\([\d\_]{1,5}\)/g,v)) { /* 복수 문항 가져오기 */
|
||
var m = regex_match(/\([\d\_]{1,5}\)/g,v);
|
||
rtitle = m.map(function(x){
|
||
var mvariable = qid+"_"+mid(x.value,1,x.value.length-2)
|
||
var mdata = kon.survey.userdata[mvariable];
|
||
if(mdata)
|
||
return list[mvariable][0].value[mdata]
|
||
else
|
||
return false;
|
||
}).filter(function(item){if(item) return true});
|
||
} else { /* 스필릿 필요한 문번 */
|
||
var spv = v.split("-");
|
||
if (rtitle === "") { /* all 없었음 */
|
||
var data = kon.survey.userdata[ele.VAR] || false;
|
||
if (data) {
|
||
rtitle = getLabel(ele.VAR, data).split(spv[0])[+spv[1]]
|
||
} else {
|
||
rtitle = ""
|
||
}
|
||
} else { /* all 있었음 */
|
||
rtitle = rtitle.map(function (text) {
|
||
return text.split(spv[0])[+spv[1]]
|
||
}).join(", ")
|
||
}
|
||
}
|
||
})
|
||
|
||
if(typeof(rtitle) !== "string" && rtitle) {
|
||
rtitle = rtitle.join(", ")
|
||
}
|
||
|
||
} else {
|
||
var data = kon.survey.userdata[ele.VAR] || false;
|
||
if (data) {
|
||
rtitle = getLabel(ele.VAR, data)
|
||
} else {
|
||
rtitle = ""
|
||
}
|
||
}
|
||
if (rtitle)
|
||
target = replaceAll(target, ele.ALL, "<span class='rptext'>" + rtitle + "</span>");
|
||
else
|
||
target = replaceAll(target, ele.ALL, "");
|
||
})
|
||
return target;
|
||
}
|
||
|
||
qx.title = replace_text(rtitle, qx.title);
|
||
qx.description = replace_text(rdes, qx.description);
|
||
}
|
||
|
||
function getResValue(variable) {
|
||
var target_value = ""
|
||
|
||
var this_value = kon.survey.userdata[variable]
|
||
var list
|
||
if (this_value === undefined) {
|
||
return "응답 " + variable + " 없음"
|
||
} else {
|
||
/* 기타일 경우 */
|
||
if(regex_test(/T/,variable)) return this_value
|
||
if(kon.survey.global_flag === "1") { /* 다국어 번역 */
|
||
list = ajax_returnData(ajaxurl, { "COMMAND": "LINFOLIST", "QLIST": "'"+ variable.split("_")[0] +"'" , "CODE": kon.survey.PKEY, "LANGUAGE":kon.survey.userdata[kon.survey.global_variable] }) /* 변수 코드 매칭된 라벨 가져옴 */
|
||
list = JSON.parse(list);
|
||
list = array_filter_to_group(list,"LCODE");
|
||
return list[this_value][0].text
|
||
} else {
|
||
list = ajax_returnData(ajaxurl, { "COMMAND": "GETLINFO", "QLIST": variable.split("_")[0], "CODE": kon.survey.PKEY });
|
||
if (list.length > 0) {
|
||
list.some(function (item, id) {
|
||
if (item.key == variable) {
|
||
target_value = item;
|
||
return true;
|
||
}
|
||
return false;
|
||
})
|
||
if(target_value.value === "open") {
|
||
return this_value
|
||
} else {
|
||
var value = JSON.parse(target_value.value)
|
||
return value[this_value];
|
||
}
|
||
} else {
|
||
return "응답 " + variable;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function translation_info(qid,language,qinfo,group) {
|
||
var linfo = ""
|
||
if(!group)
|
||
linfo = ajax_returnData(ajaxurl, { "COMMAND": "LINFO", "CODE": kon.survey.PKEY , "QCODE": qid , "LANGUAGE": language });
|
||
else
|
||
linfo = ajax_returnData(ajaxurl, { "COMMAND": "LINFOLISTALL", "CODE": kon.survey.PKEY , "QLIST": qid , "LANGUAGE": language });
|
||
|
||
var fn_transfer = function(qinfox,linfo) {
|
||
|
||
qinfox.qx.title = linfo.title[0].text
|
||
if(linfo.description) {
|
||
qinfox.qx.description = linfo.description[0].text
|
||
}
|
||
|
||
Object.keys(qinfox.qx.dataset).forEach(function (k1, id) {
|
||
var qd = qinfox.qx.dataset[k1];
|
||
var linfo_prev, linfo_after
|
||
if(k1 === "rank") return true;
|
||
if (k1 === "open") {
|
||
if (!linfo["open_prev"])
|
||
linfo_prev = false
|
||
else
|
||
linfo_prev = array_filter_to_group(linfo["open_prev"], "LCODE");
|
||
|
||
if (!linfo["open_after"])
|
||
linfo_after = false
|
||
else
|
||
linfo_after = array_filter_to_group(linfo["open_after"], "LCODE");
|
||
|
||
linfo[k1].forEach(function (v, i) {
|
||
qd[v["LCODE"]].label = v["text"];
|
||
if(linfo_prev){
|
||
qd[v["LCODE"]].prev = linfo_prev[v["LCODE"]] ? linfo_prev[v["LCODE"]][0].text : "";
|
||
} else {
|
||
qd[v["LCODE"]].prev = ""
|
||
}
|
||
if(linfo_after){
|
||
qd[v["LCODE"]].after = linfo_after[v["LCODE"]] ? linfo_after[v["LCODE"]][0].text : "";
|
||
} else {
|
||
qd[v["LCODE"]].after = ""
|
||
}
|
||
|
||
})
|
||
} else {
|
||
//20220124 박준성 value가 있어야 하는 곳에 value값
|
||
$.each(qd, function(qi,qe){
|
||
var matchLinfo = $.grep(linfo[k1], function(le ,li){ return le.LCODE == qe.value;});
|
||
if(matchLinfo.length > 0){
|
||
qe.label = matchLinfo[0].text;
|
||
}
|
||
});
|
||
//20220124 박준성
|
||
/*
|
||
linfo[k1].forEach(function (v, i) {
|
||
qd[v["LCODE"]].label = v["text"];
|
||
})
|
||
*/
|
||
}
|
||
})
|
||
|
||
if (qinfox.qx.datagroup) {
|
||
Object.keys(qinfox.qx.datagroup).forEach(function (k1, i) { // attr, open ...
|
||
Object.keys(qinfox.qx.datagroup[k1]).forEach(function (k2, i2) { // after, prev, header
|
||
var qdg = qinfox.qx.datagroup[k1][k2];
|
||
Object.keys(qdg).forEach(function (k3, i3) { // 1,2,3 Row Number
|
||
qdg[k3].forEach(function (v, i) {
|
||
v.label = linfo[k1 + "_" + k2 + "_" + k3][i].text
|
||
})
|
||
})
|
||
})
|
||
})
|
||
}
|
||
}
|
||
|
||
if (linfo) {
|
||
linfo = JSON.parse(linfo);
|
||
if(!group) {
|
||
linfo = array_filter_to_group(linfo, "LTYPE")
|
||
fn_transfer(qinfo,linfo)
|
||
} else {
|
||
|
||
linfo = array_filter_to_group(linfo, "QID")
|
||
qinfo = array_filter_to_group(qinfo.var, "QID")
|
||
|
||
Object.keys(linfo).forEach(function(key){
|
||
linfo[key] = array_filter_to_group(linfo[key], "LTYPE");
|
||
|
||
fn_transfer(qinfo[key][0],linfo[key])
|
||
})
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
function filter_example(data, fol, qtype) { /* 보기 이전 응답값에 따라 필터 걸기 */
|
||
var prev = fol || "NONE";
|
||
var Reg = /\[f\]|\[uf\]/gi /* f-> 선택한 것들 || 조건이 true, uf => 선택하지 않은 것들 조건이 false */
|
||
var WReg = /{[>=!<]{1,2}\S+}/gi
|
||
var text = ""
|
||
var condition = []
|
||
|
||
while ((text = Reg.exec(prev)) !== null) {
|
||
condition.push({ "type": text[0], "start": text["index"] })
|
||
}
|
||
if (!condition.length || (!kon.survey.userdata)) {
|
||
return false;
|
||
} else {
|
||
if (condition.length === 1) {
|
||
condition[0].var = prev.slice((+condition[0].start) + condition[0].type.length, prev.length)
|
||
} else {
|
||
condition.forEach(function (v, i) {
|
||
if (i < condition.length - 1)
|
||
condition[i].var = prev.slice((+condition[i].start) + condition[i].type.length, +condition[i + 1].start);
|
||
else
|
||
condition[i].var = prev.slice((+condition[i].start) + condition[i].type.length, prev.length);
|
||
})
|
||
}
|
||
|
||
condition.forEach(function (c) {
|
||
var wt = {}
|
||
|
||
if (regex_test(WReg, c.var)) {
|
||
var temp_where = WReg.exec(c.var);
|
||
var temp_reg;
|
||
c.var = left(c.var, temp_where.index);
|
||
temp_where = mid(temp_where[0], 1, temp_where[0].length - 2);
|
||
temp_reg = /[>=!<]{1,2}/.exec(temp_where);
|
||
wt.op = temp_reg[0];
|
||
wt.co = replaceAll(temp_where, temp_reg[0], "");
|
||
}
|
||
|
||
var var_len = c.var.length + 1
|
||
var single_flag = true; /* 단수 문항인지 체크 */
|
||
/* c.var 기준으로 입력되어있는 데이터 가져오기 */
|
||
var entered_data = Object.keys(kon.survey.userdata).gmap(function (key) {
|
||
if (key === c.var) {
|
||
return kon.survey.userdata[key];
|
||
} else if (left(key, var_len) === (c.var + "_")) {
|
||
single_flag = false;
|
||
return kon.survey.userdata[key]
|
||
} else {
|
||
return false;
|
||
}
|
||
})
|
||
|
||
/* 값 없으면 그대로 return */
|
||
if (!entered_data.length) return data;
|
||
|
||
var multi_value = ""
|
||
if(!single_flag && qtype === "r" ) multi_value = kon.survey.getValue(c.var,"m");
|
||
|
||
Object.keys(data).forEach(function (key) {
|
||
var dv = String(data[key].value);
|
||
|
||
/* 값이 있으면 true, 없으면 false */
|
||
var df; // 조건 체크
|
||
|
||
/* filter 제외일 경우 continue */
|
||
if (data[key].except === "1")
|
||
return true
|
||
|
||
if (isEmptyObject(wt)) { /* 조건 없을 경우 값이 있는 지 없는 지만 체크 */
|
||
if (single_flag) { /* 단일 응답일 경우 qid 형태 */
|
||
df = entered_data.indexOf(dv) === -1 ? false : true;
|
||
} else { /* 복수 응답이 있을 경우 qid + "_" + key 형태 */
|
||
|
||
if(qtype==="r") {
|
||
df = multi_value.indexOf(dv) === -1 ? false : true
|
||
|
||
} else {
|
||
df = kon.survey.userdata[c.var+"_"+dv] === undefined ? false : true;
|
||
}
|
||
|
||
}
|
||
} else {
|
||
if (single_flag) { /* 단일 응답일 경우 qid 형태 */
|
||
df = boolean_Expression(c.var, wt.op, wt.co);
|
||
} else { /* 복수 응답이 있을 경우 qid + "_" + key 형태 */
|
||
df = boolean_Expression(c.var + "_" + dv, wt.op, wt.co);
|
||
}
|
||
}
|
||
|
||
if (c.type === "[f]") { /* 선택한 것만 */
|
||
if (!df)
|
||
delete data[key]
|
||
} else {
|
||
if (df)
|
||
delete data[key]
|
||
}
|
||
})
|
||
|
||
})
|
||
}
|
||
return data;
|
||
}
|
||
|
||
/**
|
||
* @date 2020-10-16
|
||
* @param {*} qid => 문항 ID
|
||
* @param {*} type => { s = single (default), m = multi, "mn" = multi + name, "sn" = single + name }
|
||
*/
|
||
function getValue(qid, type){
|
||
type = type || "s";
|
||
|
||
if(left(type, 1)==="m") {
|
||
var return_value = []
|
||
var qlen = qid.length
|
||
var qid_m = qid+"_"
|
||
if(right(type, 1) === "n") {
|
||
Object.keys(kon.survey.userdata).forEach(function(key){
|
||
var obj = {}
|
||
|
||
if( key === qid || left(key.replace(/[AT]/g,""),qlen+1) === (qid_m) ){
|
||
obj[key] = kon.survey.userdata[key]
|
||
return_value.push( obj );
|
||
}
|
||
})
|
||
} else {
|
||
Object.keys(kon.survey.userdata).forEach(function(key){
|
||
//if( key === qid || left(key.replace(/[AT]/g,""),qlen+1) === (qid_m) ){
|
||
//20220127 박준성 기타값 안가져오게 수정
|
||
if( key === qid || left(key,qlen+1) === (qid_m) ){
|
||
return_value.push(kon.survey.userdata[key]);
|
||
}
|
||
})
|
||
}
|
||
|
||
|
||
return return_value
|
||
} else {
|
||
var obj = {}
|
||
right(type, 1) === "n" ? obj[qid] = kon.survey.userdata[qid] : obj = kon.survey.userdata[qid]
|
||
return obj
|
||
|
||
}
|
||
}
|
||
|
||
function middle_save(data, form) {
|
||
$.ajax({
|
||
url: url,
|
||
data: data,
|
||
method: "POST",
|
||
beforeSend: function () { /* 설문 페이지 안보이게 */
|
||
$("#wrapper").css("display", "none");
|
||
}, success: function (nextpage) {
|
||
|
||
var stringifydata = "";
|
||
|
||
if (data.DATA !== "{}") { /* 데이터 있으면 저장 */
|
||
/* 페이지 입력 데이터들 정리 */
|
||
kon.survey.jdata = JSON.parse(data.DATA);
|
||
|
||
/* 입력 데이터 -> 전체 데이터에 씌움 */
|
||
Object.keys(kon.survey.jdata).forEach(function (key) {
|
||
kon.survey.tv[key] = kon.survey.jdata[key].replace(/,/g, "¸");
|
||
});
|
||
|
||
/* 문자열로 변환 */
|
||
stringifydata = JSON.stringify(kon.survey.tv);
|
||
stringifydata = stringifydata.replace(/'/g,"´");
|
||
ajax_call("./include/ajax.asp", { "DAT": stringifydata, "COMMAND": "SETDATA", "CODE": kon.survey.PKEY, "IDKEY": kon.survey.IDKEY })
|
||
}
|
||
alert("저장되었습니다.");
|
||
|
||
}, error: function (x, h, r) {
|
||
console.log(x);
|
||
console.log(h);
|
||
console.log(r);
|
||
}
|
||
|
||
})
|
||
}
|
||
|
||
var module = {
|
||
save: save, // 저장
|
||
serializeform: serializeform, // 폼 정규화
|
||
userdata: userdata, // 입력 값
|
||
PKEY: PKEY, // 프로젝트 코드
|
||
IDKEY: IDKEY, // IDKEY
|
||
replace_responed_label: replace_responed_label, // title,descrition 이전 응답 값 가져오기
|
||
getResValue: getResValue,
|
||
logic_chk: logic_chk,
|
||
filter_example: filter_example,
|
||
tv: tv,
|
||
jdata: jdata,
|
||
translation_info:translation_info, // 번역
|
||
global_flag:global_flag,
|
||
global_variable:global_variable,
|
||
getValue:getValue,
|
||
middle_save:middle_save //임시저장(로직없이 데이터저장만 됨.)
|
||
}
|
||
|
||
return module;
|
||
})(); |