first commit
This commit is contained in:
433
module/Qmodule/group.js
Normal file
433
module/Qmodule/group.js
Normal file
@@ -0,0 +1,433 @@
|
||||
window.kon = window.kon || {}
|
||||
|
||||
kon.group = (function () {
|
||||
var variable;
|
||||
var dataset;
|
||||
var datagroup;
|
||||
var qtype;
|
||||
var stype;
|
||||
var title;
|
||||
var description;
|
||||
var option;
|
||||
var logic_arr =[];
|
||||
|
||||
function setTitle(titles) { kon.group.title = titles; }
|
||||
function setDescription(descriptions) { kon.group.description = descriptions; }
|
||||
function setVariable(vars) { kon.group.variable = vars; }
|
||||
function setData(datasets) { kon.group.dataset = datasets; }
|
||||
function setDatagroup(datagroups) { kon.group.datagroup = datagroups; }
|
||||
function setQtype(qtypes) { kon.group.qtype = qtypes; }
|
||||
function setStype(stypes) { kon.group.stype = stypes; }
|
||||
function setOption(option) { kon.group.option = option; }
|
||||
|
||||
function getVariable() { return kon.group.variable }
|
||||
function getDataset() { return kon.group.dataset }
|
||||
function getDatagroup() { return kon.group.datagroup }
|
||||
function getQtype() { return kon.group.qtype }
|
||||
function getStype() { return kon.group.stype }
|
||||
function getTitle() { return kon.group.title }
|
||||
function getDescription() { return kon.group.description }
|
||||
function getOption() { return kon.group.option }
|
||||
|
||||
|
||||
function GM1() {
|
||||
|
||||
kon.group.qtype.forEach(function (v, i) {
|
||||
kon.qmake.setTitle(kon.group.title[i], kon.group.variable[i])
|
||||
kon.qmake.setDescription(kon.group.description[i], kon.group.variable[i])
|
||||
kon.qmake.setPageName(kon.group.variable[i])
|
||||
kon.qmake.setData(kon.group.dataset[i]);
|
||||
kon.qmake.setGroup(kon.group.datagroup[i] || "");
|
||||
var a = kon.qmake[v]();
|
||||
kon.group.logic_arr.push(a[kon.group.stype[i]](kon.group.option[i] || ""));
|
||||
})
|
||||
|
||||
var nextFunc = function () {
|
||||
var bools = true;
|
||||
$.each(kon.group.logic_arr, function (i, logic) {
|
||||
if(!logic) return true;
|
||||
var vars = kon.group.variable[i]
|
||||
var option = kon.group.option[i]
|
||||
switch(kon.group.qtype[i]){
|
||||
case "rank" :
|
||||
var max = kon.group.dataset[i].rank.max
|
||||
if(!logic(vars, max)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "open":
|
||||
var data = kon.group.dataset[i].open
|
||||
if(!logic(vars, data)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case "com":
|
||||
var data = kon.group.dataset[i]
|
||||
if(!logic(vars, data)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "attr":
|
||||
var data = kon.group.dataset[i]
|
||||
var attr = kon.group.dataset[i].attr
|
||||
var order = Object.keys(data).map(function (k) { return k === "attr" ? false : k })
|
||||
if(!logic(vars, attr, data, order)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
if(!logic(vars, option)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
return bools
|
||||
};
|
||||
return nextFunc
|
||||
}
|
||||
|
||||
function GM_ROTA(option) {
|
||||
var keyarr = Array(kon.group.qtype.length).fill(0).map(function (v, i) { return i });
|
||||
|
||||
if (option) {
|
||||
keyarr = arr_rota(keyarr, +option.rota);
|
||||
}
|
||||
|
||||
keyarr.forEach(function (v, i) {
|
||||
kon.qmake.setTitle(kon.group.title[v]);
|
||||
kon.qmake.setDescription(kon.group.description[v]);
|
||||
kon.qmake.setPageName(kon.group.variable[v]);
|
||||
kon.qmake.setData(kon.group.dataset[v]);
|
||||
kon.qmake.setGroup(kon.group.datagroup[v] || "");
|
||||
var a = kon.qmake[kon.group.qtype[v]]();
|
||||
kon.group.logic_arr.push(a[kon.group.stype[v]](kon.group.option[v] || ""));
|
||||
})
|
||||
|
||||
var nextFunc = function () {
|
||||
var bools = true;
|
||||
$.each(kon.group.logic_arr, function (i, logic) {
|
||||
if(!logic) return true;
|
||||
var vars = kon.group.variable[i]
|
||||
switch(kon.group.qtype[i]){
|
||||
case "rank" :
|
||||
var max = kon.group.dataset[i].rank.max
|
||||
if(!logic(vars, max)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "open":
|
||||
var data = kon.group.dataset[i].open.data
|
||||
if(!logic(vars, data)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "attr":
|
||||
var data = kon.group.dataset[i]
|
||||
var attr = kon.group.datset[i].attr
|
||||
var order = Object.keys(data).map(function (k) { return k === "attr" ? false : k })
|
||||
if(!logic(vars, attr, data, order)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "com":
|
||||
var data = kon.group.dataset[i]
|
||||
if(!logic(vars, data)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
if(!logic(vars)) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
return bools
|
||||
};
|
||||
return nextFunc
|
||||
}
|
||||
|
||||
/* 속성 한 열로 합치기. */
|
||||
function GM2() {
|
||||
kon.qmake.setTitle(kon.group.title[0])
|
||||
kon.qmake.setDescription(kon.group.description[0])
|
||||
var div = createnode("div", "", { "class": "m-1" })
|
||||
var table = createnode("TABLE", "", { "class": "table table-sm table-bordered", "style":"table-layout:fixed" });
|
||||
var toplable = []
|
||||
var grp = kon.group.datagroup[0] || {};
|
||||
|
||||
var gheader = get(grp, ["header"]) || {} // 헤더 정보
|
||||
|
||||
var attr = kon.group.dataset[0].attr
|
||||
|
||||
kon.group.dataset.forEach(function (e, id) {
|
||||
Object.keys(e).forEach(function (type, iid) {
|
||||
if (type === "attr") return true;
|
||||
Object.keys(e[type]).forEach(function (key) {
|
||||
toplable.push(e[type][key].label);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
if (!isEmptyObject(gheader)) { /* 합친 헤더 그리기 */
|
||||
var headertr = {}
|
||||
var last_key = ""
|
||||
kon.group.datagroup.forEach(function(dg,id){
|
||||
var dgh = dg["header"];
|
||||
if(isEmptyObject(dgh) || !dgh) return true;
|
||||
Object.keys(dgh).forEach(function (key, id2) {
|
||||
if(!headertr[key]) headertr[key] = createnode("TR", "", { "class": "text-center" });
|
||||
var th = dgh[key].gmap(function (item,id3) {
|
||||
if(id>0 && id3===0) return false;
|
||||
return createnode("TD", item.label, { "colspan": item.cols, "rowspan": item.rows, "class": "bg-light" })
|
||||
});
|
||||
headertr[key].appendM(th);
|
||||
last_key = key;
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
headertr[last_key].appendM(toplable.map(function (v) { return createnode("TD", v) }))
|
||||
|
||||
Object.keys(headertr).forEach(function(key){
|
||||
table.appendChild(headertr[key])
|
||||
})
|
||||
|
||||
} else {
|
||||
var headertr = createnode("TR", "", { "class": "text-center" });
|
||||
headertr.appendChild(createnode("TD", "항목",{"class":"bg-light"}))
|
||||
headertr.appendM(toplable.map(function (v) { return createnode("TH", v) }))
|
||||
table.appendChild(headertr);
|
||||
}
|
||||
|
||||
Object.keys(attr).forEach(function (key, id) { // 속성 값 기준으로 반복 속성 개수 = 행 개수
|
||||
var tr = createnode("TR", "", { "id": "row_attr_" + attr[key].value });
|
||||
|
||||
var prev = get(grp, [ "prev", id]) // 해당 열에 이전 속성 라벨 있는 지
|
||||
var after = get(grp, [ "after", id]) // 해당 열에 이후 속성 라벨 있는 지
|
||||
|
||||
if (prev) { //해당 열 이전 속성
|
||||
prev.forEach(function (ele) {
|
||||
var td = createnode("TD", ele.label, { "colspan": ele.cols, "rowspan": ele.rows, "class": "bg-light align-middle text-center" });
|
||||
tr.appendChild(td);
|
||||
})
|
||||
}
|
||||
|
||||
if (attr[key].etc === "1") {
|
||||
var input_text = createnode("INPUT", "", { "type": "text", "name": kon.group.variable[0] + "_" + key + "_AT", "class": "d-block w-100", "disabled": "true" });
|
||||
mainlabel = createnode("TD", attr[key].label, { "class": "bg-light text-left align-middle", "style": "font-size:calc(9px + 0.8vw);", "id": "attr_" + key }); // 해당 열 메인 속성 삽입
|
||||
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_" + key }); // 해당 열 메인 속성 삽입
|
||||
}
|
||||
|
||||
tr.appendChild(mainlabel);
|
||||
if (after) { //해당 열 이후 보기
|
||||
after.forEach(function (ele) {
|
||||
var td = createnode("TD", ele.label, { "colspan": ele.cols, "rowspan": ele.rows });
|
||||
tr.appendChild(td);
|
||||
})
|
||||
}
|
||||
var s = 0
|
||||
kon.group.dataset.forEach(function (e, _id) {
|
||||
Object.keys(e).forEach(function (type, iid) {
|
||||
if (type === "attr") return true;
|
||||
var target = e[type];
|
||||
var td = Object.keys(target).map(function (key2, id) {
|
||||
var t;
|
||||
if (Object.keys(target).length - 1 > id || s > 0)
|
||||
t = createnode("TD", "", { "class": "text-center" });
|
||||
else
|
||||
t = createnode("TD", "", { "class": "text-center", "style": "border-right:3px double" });
|
||||
|
||||
var ipat = {}
|
||||
var input
|
||||
if (type === "multi") {
|
||||
ipat["type"] = "checkbox"
|
||||
ipat["name"] = kon.group.variable[_id] + "_" + key2 + "_" + key
|
||||
input = createnode("INPUT", "", { "type": ipat.type, "name": ipat.name, "value": key2 });
|
||||
} else if (type === "open") {
|
||||
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.group.variable[_id] + "_" + key2 + "_" + key
|
||||
ipat["prev"] = target[key2].prev || ""
|
||||
ipat["after"] = target[key2].after || ""
|
||||
ipat["label"] = ""
|
||||
|
||||
input = createnode("DIV", [make_input_text(ipat, kon.group.variable[_id] + "_" + key2 + "_" + key)]);
|
||||
}
|
||||
else {
|
||||
ipat["type"] = "radio"
|
||||
ipat["name"] = kon.group.variable[_id] + "_" + key
|
||||
input = createnode("INPUT", "", { "type": ipat.type, "name": ipat.name, "value": key2 });
|
||||
}
|
||||
t.appendChild(input);
|
||||
return t;
|
||||
})
|
||||
s++;
|
||||
tr.appendM(td)
|
||||
});
|
||||
})
|
||||
table.appendChild(tr);
|
||||
})
|
||||
div.appendChild(table)
|
||||
$("#question_body").append(div);
|
||||
|
||||
var nextFunc = function () {
|
||||
var bools = true
|
||||
$.each(kon.group.variable, function (i, v) {
|
||||
$.each(Object.keys(kon.group.dataset[i]), function (i2, key) {
|
||||
if( !kon.group.gm2_page_logic(v, key, kon.group.dataset[i]["attr"], kon.group.dataset[i][key]) ) {
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
})
|
||||
if(!bools) return false;
|
||||
})
|
||||
|
||||
if (bools) {
|
||||
$("input[type=text]:not(:disabled)").each(function (id, item) {
|
||||
if (item.value === "") {
|
||||
$.alert(kon.qmake.alert["문항에 응답해주세요."]);
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
})
|
||||
}
|
||||
return bools;
|
||||
};
|
||||
return nextFunc
|
||||
}
|
||||
|
||||
function gm2_page_logic(vars, type, attr, typedata) {
|
||||
var bools = true;
|
||||
|
||||
switch (type) {
|
||||
case "scale": case "single":
|
||||
$.each(Object.keys(attr), function (id, key) {
|
||||
if ($("input[name=" + vars + "_" + key + "]:checked").length === 0) {
|
||||
if ($("input[name=" + vars + "_" + key + "]").prop("disabled")) return true;
|
||||
$.alert(kon.qmake.alert["문항에 응답해주세요."]);
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "multi":
|
||||
$.each(Object.keys(typedata), function (id, key) {
|
||||
if ($("input[type=checkbox][name^="+vars+"_"+key+"]:checked").length === 0) {
|
||||
$.alert(kon.qmake.alert["문항에 응답해주세요."]);
|
||||
bools = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "open":
|
||||
$.each(Object.keys(typedata), function (id, key) {
|
||||
var attr_option = typedata[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 + "]");
|
||||
|
||||
if (target.length === 0) return true;
|
||||
if (target.prop("disabled")) return true;
|
||||
|
||||
if (target.val().trim() === "") {
|
||||
target.focus();
|
||||
$.alert(kon.qmake.alert["문항에 응답해주세요."]);
|
||||
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 오픈 */
|
||||
})
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return bools; /* 속성 보기 들 */
|
||||
}
|
||||
|
||||
var module = {
|
||||
/* variable */
|
||||
variable: variable,
|
||||
dataset: dataset,
|
||||
datagroup: datagroup,
|
||||
qtype: qtype,
|
||||
stype: stype,
|
||||
title: title,
|
||||
description: description,
|
||||
option: option,
|
||||
logic_arr:logic_arr,
|
||||
/* function */
|
||||
setVariable: setVariable,
|
||||
setData: setData,
|
||||
setDatagroup: setDatagroup,
|
||||
setQtype: setQtype,
|
||||
setStype: setStype,
|
||||
setTitle: setTitle,
|
||||
setDescription: setDescription,
|
||||
setOption: setOption,
|
||||
gm2_page_logic: gm2_page_logic,
|
||||
GM1: GM1,
|
||||
GM2: GM2,
|
||||
GM_ROTA: GM_ROTA,
|
||||
getVariable: getVariable,
|
||||
getDataset: getDataset,
|
||||
getDatagroup: getDatagroup,
|
||||
getQtype: getQtype,
|
||||
getStype: getStype,
|
||||
getTitle: getTitle,
|
||||
getDescription: getDescription,
|
||||
getOption: getOption
|
||||
|
||||
}
|
||||
|
||||
return module;
|
||||
})();
|
||||
Reference in New Issue
Block a user