/* - ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩ 자동완성기능 (ZMR00101.js) - Version : 1) : Ver.1.00.00 (2007-05-15) - 주의사항 : 본스크립트를 import 하기 전에 com/commonweb 에 위치한 common.js 를 import 하십시오 - ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩ */ /** * @group : * @ver : 2007.05.15 * @by : ??? * @--------------------------------------------------- * @type : function * @access : public * @desc : 자동완성 서브밋을 담당하는 함수 * @return : void * @--------------------------------------------------- */ //var submit_done = true; var submit_timer; var selected_index; var AClisboxObjID = null; // List Box 오브젝트 아이디 var ACinputObjID = null; // INPUT 컨트롤 아이디 var item_cnt=0; var LIST_HEIGHT = 82; function zscfsubmit(submitID) { model.send(submitID, false, true); window.clearinterval(submit_timer); //submit_done = false; } function createSearchListBox(trgID, orddeptcd, keywordflag, listWidth, col) { var trgObj = document.controls(trgID); var trgLeft = parseInt(trgObj.attribute("left")); var trgTop = parseInt(trgObj.attribute("top")); var trgWidth = parseInt(trgObj.attribute("width")); var trgHeight = parseInt(trgObj.attribute("height")); var parentObj = trgObj.parent; var listBoxID = "lbx_" + trgID + "_" +col; var listBoxLeft = trgLeft; var listBoxTop = trgTop + trgHeight + 1; var listBoxWidth = trgWidth; if( listWidth != null ) { listBoxWidth = listWidth; } // var listBoxHeight = 16 * 5; var listBoxHeight = 0; var listBoxRef = "/root/_search_info/" + trgID + "_" + col + "/send_data/keywordnm"; // 키워드 이름 var listBoxRef1 = "/root/_search_info/" + trgID + "_" + col + "/send_data/useyn"; // 사용여부 (기본값: true) var listBoxRef2 = "/root/_search_info/" + trgID + "_" + col + "/send_data/orddeptcd"; // 진료과코드 var listBoxRef3 = "/root/_search_info/" + trgID + "_" + col + "/send_data/keywordflag"; // 키워드구분자 model.makeNode(listBoxRef); model.makeNode(listBoxRef1); model.makeNode(listBoxRef2); model.makeNode(listBoxRef3); // 기본값 설정 (사용여부 = Y) model.setValue(listBoxRef1, "Y"); var listBoxNodeSet = "/root/_search_info/" + trgID + "_" + col + "/list/itemlist"; model.makeNode(listBoxNodeSet); model.setValue(listBoxRef2, orddeptcd); model.setValue(listBoxRef3, keywordflag); if( trgObj.elementName == "xforms:input" ) { trgObj.attribute("onkeyup") += ";searchGridOnkeyUp("+col+");"; //trgObj.attribute("DOMFocusOut") = "hiddenSearchListBox()"; } else if( trgObj.elementName == "xforms:datagrid" ) { trgObj.attribute("onkeyup") += ";searchGridOnkeyUp("+col+");"; //trgObj.attribute("onendedit") = ";setColtrol('"+trgID+"', "+col+")"; } //if(document.controls.item(listBoxID) != null) return; // 리스트 박스가 이미 만들어져 있으면 리턴 var searchListBoxObj = parentObj.createChild("xforms:select", "id:" + listBoxID + "; ref:" + listBoxRef + " ; sep:▦; overflow:scroll; scroll:vertical; appearance:compact; left:" + listBoxLeft + "px; top:" + listBoxTop + "px; width:" + listBoxWidth + "px; height:" + listBoxHeight + "px;"); var choicesObj = searchListBoxObj.createChild("xforms:choices", ""); var itemsetObj = choicesObj.createChild("xforms:itemset", "nodeset:" + listBoxNodeSet + ";"); itemsetObj.createChild("xforms:label", "ref:value;"); itemsetObj.createChild("xforms:value", "ref:value;"); searchListBoxObj.attribute("onclick") = "onClickSearchListBox()"; trgObj.attribute("DOMFocusIn") += ";setColtrol('"+trgID+"', "+col+")"; //alert(trgID); //trgObj.attribute("DOMFocusOut") = "unsetControl()"; } // 자동완성 컨트롤을 설정하는 메소드 function setColtrol(trgID, col) { //alert(trgID); //alert(AClisboxObjID+", "+ACinputObjID); // 이전 자동완성되었전 리스트 박스를 숨김 var trgObj = document.controls(trgID); if(trgObj.elementName == "xforms:datagrid") // 그리드 오브젝트이면 { if (trgObj.col != col) return; // 자신의 컬럼번호가 아니면 숨김 } if(AClisboxObjID != null) document.controls(AClisboxObjID).attribute("height") = 0; // 현재 자동완성 되고있는 컨트롤을 전역변수에 세팅 AClisboxObjID = "lbx_"+ trgID + "_" +col; ACinputObjID = trgID; } // 자동완성 컨트롤을 설정해제하는 메소드 function unsetControl() { AClisboxObjID = null; ACinputObjID = null; } function onClickSearchListBox() { var listBoxID = event.currentTarget; var listBoxObj = document.controls(listBoxID); var listBoxRef = listBoxObj.attribute("ref"); var InputBoxID = listBoxID.substr(4, listBoxID.lastIndexOf("_") - 4); var InputBoxObj = document.controls(InputBoxID); //alert(InputBoxID); if(listBoxObj.isCell(event.target)) { var curListBoxValue = listBoxObj.value; var curListBoxValueArray = curListBoxValue.split("▦"); //listBoxObj.value = curListBoxValueArray[curListBoxValueArray.length - 1]; if( InputBoxObj.elementName == "xforms:input" ) { InputBoxObj.value = curListBoxValueArray[curListBoxValueArray.length - 1]; } else { InputBoxObj.valueMatrix(InputBoxObj.row, InputBoxObj.col) = curListBoxValueArray[curListBoxValueArray.length - 1]; } model.setValue(listBoxRef, curListBoxValueArray[curListBoxValueArray.length - 1]); listBoxObj.attribute("height") = 0; selected_index = -1; //listBoxObj.value = listBoxObj.value; } } function selectItem() { //listBoxObj.attribute("height") = 0; //selected_index = -1; //listBoxObj.value = ""; } // submission 생성 function createSubmission(trgID, col) { var submitID = "sub_" + trgID +"_"+col; var submitObj = model1.createChild("xforms:submission","id:" + submitID + "; "); submitObj.attribute("mediatype") = "application/x-www-form-urlencoded"; submitObj.attribute("method") = "post"; submitObj.attribute("action") = getActionURL("TRZSC00101"); submitObj.attribute("encoding") = "utf-8"; submitObj.attribute("ref") = "/root/_search_info/" + trgID + "_" + col + "/send_data"; submitObj.attribute("resultref") = "/root/_search_info/" + trgID + "_" + col + "/list"; return submitObj; } // 자음 체크 function checkConsonant(lastText) { var start = "ㄱ".charCodeAt(0); var end = "ㅎ".charCodeAt(0); for(var i=0; i 40) && keyCode != 13 && curText.length != 0) { if(checkConsonant(lastText) || checkVowel(lastText)) return; //debug.value = inputObj.value.length; model.setValue(listBoxRef, inputObj.currentText); //listBoxObj.select(0); window.clearinterval(submit_timer); submit_timer = window.setInterval("zscfsubmit('"+submitID+"');", 1000); } // 방향키 ↑ : keyCdoe = 38 else if(keyCode == 38 && listBoxObj.attribute("height") != 0) { listBoxObj.deselect(selected_index); // 리스트를 숨기고 원래 검색어를 보여줌 listBoxObj.select(selected_index - 1); if(selected_index > 4) listBoxObj.vscroll.attribute("pos") = (selected_index - 5) * 16; selected_index--; //alert('키업'); if(selected_index < 0) { inputObj.value = listBoxObj.value.split("▦")[0]; listBoxObj.attribute("height") = 0; } else { //debug.value = listBoxObj.selectedIndex; inputObj.value = listBoxObj.value.split("▦")[1]; } inputObj.selBegin = inputObj.value.length; } // 방향키 ↓ : keyCdoe = 40 else if(keyCode == 40 && selected_index < item_cnt-1) { //debug.value = listBoxObj.length; //if(listBoxObj.length == 0) return; if(listBoxObj.attribute("height") == 0) { zscfsubmit(submitID); return; } if(listBoxObj.attribute("height") == 0) listBoxObj.attribute("height") = LIST_HEIGHT; if(selected_index >= 0) listBoxObj.deselect(selected_index); if(selected_index + 1 >4) { listBoxObj.vscroll.attribute("pos") = (selected_index - 3) * 16; } listBoxObj.select(++selected_index); //alert('키다운'); //debug.value = listBoxObj.selectedIndex; inputObj.value = listBoxObj.value.split("▦")[1]; inputObj.selBegin = inputObj.value.length; } //caption1.value = selected_index; // 엔터키 : keyCdoe = 13 if(keyCode == 13) { //selectItem(); //var listBoxID = event.currentTarget; //var listBoxObj = document.controls(listBoxID); //var InputBoxID = listBoxID.substr(4, listBoxID.lastIndexOf("_") - 4); //var InputBoxObj = document.controls(InputBoxID); //alert(InputBoxID); //if(listBoxObj.isCell(event.target)) { var curListBoxValue = listBoxObj.value; var curListBoxValueArray = curListBoxValue.split("▦"); //listBoxObj.value = curListBoxValueArray[curListBoxValueArray.length - 1]; //document.controls(trgID).value = curListBoxValueArray[curListBoxValueArray.length - 1]; if (inputObj.parent != null && inputObj.parent.elementName == "xforms:datagrid") { inputObj.valueMatrix(inputObj.row, inputObj.col) = curListBoxValueArray[curListBoxValueArray.length - 1]; } else { document.controls(trgID).value = curListBoxValueArray[curListBoxValueArray.length - 1]; } model.setValue(listBoxRef, curListBoxValueArray[curListBoxValueArray.length - 1]); listBoxObj.attribute("height") = 0; selected_index = -1; //listBoxObj.value = listBoxObj.value; //} } // curText.length == 0 if(curText.length == 0) { listBoxObj.attribute("height") = 0; model.setValue(listBoxRef, ""); window.clearinterval(submit_timer); } // 키업이벤트 카운트 (For Debug) //var keyUpCnt = model.getValue("/root/main/keyup_cnt"); //model.setValue("/root/main/keyup_cnt", ++keyUpCnt); //output1.refresh(); } function xforms_submit_done() { //if (submit_done == true) return; if(event.currentTarget.indexOf("sub_") != -1) { var submitID = event.target; //lastIndex = submitID.lastIndexOf("_"); var ctrlID = submitID.substr(4, submitID.lastIndexOf("_") - 4); var col = submitID.substr(submitID.lastIndexOf("_")+1, submitID.length -1); if(ACinputObjID != ctrlID) return; // 만약 현재 자동완성이 진행중인 컨트롤이 아니면 리턴 var listboxID = "lbx_" + ctrlID + "_" + col; var listboxObj = document.controls.item(listboxID); var gridObj = document.controls.item(ctrlID); if( gridObj.elementName == "xforms:datagrid") { var inputObj = gridObj.input; if (parseInt(col) != gridObj.col) return; // 자신의 컬럼이 아니면 리턴 listboxObj.attribute("top") = parseInt(gridObj.attribute("top")) + parseInt(inputObj.attribute("top")) + parseInt(inputObj.attribute("height")) + 1; listboxObj.attribute("left") = parseInt(gridObj.attribute("left")) + parseInt(inputObj.attribute("left")) -1; } listboxObj.attribute("height") = LIST_HEIGHT; listboxObj.refresh(); //전역변수 초기화 //submit_done = true; selected_index = -1; item_cnt = listboxObj.length; // 전역 //model.setValue(listboxObj.attribute("ref"), ""); //listboxObj.refresh(); // 서브밋던이벤트 카운트 //var doneCnt = model.getValue("/root/main/done_cnt"); //model.setValue("/root/main/done_cnt", ++doneCnt); //output2.refresh(); // event.stopPropagation(); } } /** * @group : * @ver : 2007.05.15 * @by : 이상준 * @--------------------------------------------------- * @type : function * @access : public * @desc : 컨트롤에 자동완성 기능을 부여하는 함수 * @return : void * @--------------------------------------------------- */ function zscfMakeAC(controlID, orddeptcd, keywordflag, listWidth, col) { // if (col == null) { col = 0; } // 컨트롤생성 createSearchListBox(controlID, orddeptcd, keywordflag, listWidth, col); // submission 생성 createSubmission(controlID, col); } /** * @group : * @ver : 2007.05.15 * @by : 이상준 * @--------------------------------------------------- * @type : function * @access : public * @desc : 컨트롤의 자동완성기능 여부를 리턴하는 함수 * @return : bool * @--------------------------------------------------- */ function zscfGetUseYN(controlID, col) { // if (col == null) { col = 0; } var useryn = model.getValue("/root/_search_info/" + controlID + "_" + col + "/send_data/useyn"); // 사용여부 (기본값: true) if (useryn == "Y") return true; else return false; } /** * @group : * @ver : 2007.05.15 * @by : 이상준 * @--------------------------------------------------- * @type : function * @access : public * @desc : 컨트롤의 자동완성기능을 설정하는 함수 * @return : bool * @--------------------------------------------------- */ function zscfSetUseYN(controlID, useAC, col) { if (col == null) { col = 0; } var userynXpath = "/root/_search_info/" + controlID + "_" + col + "/send_data/useyn"; // 사용여부 (기본값: true) if (useAC == true) { model.setValue(userynXpath, "N"); } else { model.setValue(userynXpath, "Y"); } }