ZSC001.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. - ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩
  3. 자동완성기능 (ZMR00101.js)
  4. - Version :
  5. 1) : Ver.1.00.00 (2007-05-15)
  6. - 주의사항 : 본스크립트를 import 하기 전에 com/commonweb 에 위치한 common.js 를 import 하십시오
  7. - ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩
  8. */
  9. /**
  10. * @group :
  11. * @ver : 2007.05.15
  12. * @by : ???
  13. * @---------------------------------------------------
  14. * @type : function
  15. * @access : public
  16. * @desc : 자동완성 서브밋을 담당하는 함수
  17. * @return : void
  18. * @---------------------------------------------------
  19. */
  20. //var submit_done = true;
  21. var submit_timer;
  22. var selected_index;
  23. var AClisboxObjID = null; // List Box 오브젝트 아이디
  24. var ACinputObjID = null; // INPUT 컨트롤 아이디
  25. var item_cnt=0;
  26. var LIST_HEIGHT = 82;
  27. function zscfsubmit(submitID) {
  28. model.send(submitID, false, true);
  29. window.clearinterval(submit_timer);
  30. //submit_done = false;
  31. }
  32. function createSearchListBox(trgID, orddeptcd, keywordflag, listWidth, col) {
  33. var trgObj = document.controls(trgID);
  34. var trgLeft = parseInt(trgObj.attribute("left"));
  35. var trgTop = parseInt(trgObj.attribute("top"));
  36. var trgWidth = parseInt(trgObj.attribute("width"));
  37. var trgHeight = parseInt(trgObj.attribute("height"));
  38. var parentObj = trgObj.parent;
  39. var listBoxID = "lbx_" + trgID + "_" +col;
  40. var listBoxLeft = trgLeft;
  41. var listBoxTop = trgTop + trgHeight + 1;
  42. var listBoxWidth = trgWidth;
  43. if( listWidth != null ) {
  44. listBoxWidth = listWidth;
  45. }
  46. // var listBoxHeight = 16 * 5;
  47. var listBoxHeight = 0;
  48. var listBoxRef = "/root/_search_info/" + trgID + "_" + col + "/send_data/keywordnm"; // 키워드 이름
  49. var listBoxRef1 = "/root/_search_info/" + trgID + "_" + col + "/send_data/useyn"; // 사용여부 (기본값: true)
  50. var listBoxRef2 = "/root/_search_info/" + trgID + "_" + col + "/send_data/orddeptcd"; // 진료과코드
  51. var listBoxRef3 = "/root/_search_info/" + trgID + "_" + col + "/send_data/keywordflag"; // 키워드구분자
  52. model.makeNode(listBoxRef);
  53. model.makeNode(listBoxRef1);
  54. model.makeNode(listBoxRef2);
  55. model.makeNode(listBoxRef3);
  56. // 기본값 설정 (사용여부 = Y)
  57. model.setValue(listBoxRef1, "Y");
  58. var listBoxNodeSet = "/root/_search_info/" + trgID + "_" + col + "/list/itemlist";
  59. model.makeNode(listBoxNodeSet);
  60. model.setValue(listBoxRef2, orddeptcd);
  61. model.setValue(listBoxRef3, keywordflag);
  62. if( trgObj.elementName == "xforms:input" )
  63. {
  64. trgObj.attribute("onkeyup") += ";searchGridOnkeyUp("+col+");";
  65. //trgObj.attribute("DOMFocusOut") = "hiddenSearchListBox()";
  66. }
  67. else if( trgObj.elementName == "xforms:datagrid" )
  68. {
  69. trgObj.attribute("onkeyup") += ";searchGridOnkeyUp("+col+");";
  70. //trgObj.attribute("onendedit") = ";setColtrol('"+trgID+"', "+col+")";
  71. }
  72. //if(document.controls.item(listBoxID) != null) return; // 리스트 박스가 이미 만들어져 있으면 리턴
  73. 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;");
  74. var choicesObj = searchListBoxObj.createChild("xforms:choices", "");
  75. var itemsetObj = choicesObj.createChild("xforms:itemset", "nodeset:" + listBoxNodeSet + ";");
  76. itemsetObj.createChild("xforms:label", "ref:value;");
  77. itemsetObj.createChild("xforms:value", "ref:value;");
  78. searchListBoxObj.attribute("onclick") = "onClickSearchListBox()";
  79. trgObj.attribute("DOMFocusIn") += ";setColtrol('"+trgID+"', "+col+")";
  80. //alert(trgID);
  81. //trgObj.attribute("DOMFocusOut") = "unsetControl()";
  82. }
  83. // 자동완성 컨트롤을 설정하는 메소드
  84. function setColtrol(trgID, col)
  85. {
  86. //alert(trgID);
  87. //alert(AClisboxObjID+", "+ACinputObjID);
  88. // 이전 자동완성되었전 리스트 박스를 숨김
  89. var trgObj = document.controls(trgID);
  90. if(trgObj.elementName == "xforms:datagrid") // 그리드 오브젝트이면
  91. {
  92. if (trgObj.col != col) return; // 자신의 컬럼번호가 아니면 숨김
  93. }
  94. if(AClisboxObjID != null) document.controls(AClisboxObjID).attribute("height") = 0;
  95. // 현재 자동완성 되고있는 컨트롤을 전역변수에 세팅
  96. AClisboxObjID = "lbx_"+ trgID + "_" +col;
  97. ACinputObjID = trgID;
  98. }
  99. // 자동완성 컨트롤을 설정해제하는 메소드
  100. function unsetControl()
  101. {
  102. AClisboxObjID = null;
  103. ACinputObjID = null;
  104. }
  105. function onClickSearchListBox() {
  106. var listBoxID = event.currentTarget;
  107. var listBoxObj = document.controls(listBoxID);
  108. var listBoxRef = listBoxObj.attribute("ref");
  109. var InputBoxID = listBoxID.substr(4, listBoxID.lastIndexOf("_") - 4);
  110. var InputBoxObj = document.controls(InputBoxID);
  111. //alert(InputBoxID);
  112. if(listBoxObj.isCell(event.target)) {
  113. var curListBoxValue = listBoxObj.value;
  114. var curListBoxValueArray = curListBoxValue.split("▦");
  115. //listBoxObj.value = curListBoxValueArray[curListBoxValueArray.length - 1];
  116. if( InputBoxObj.elementName == "xforms:input" )
  117. {
  118. InputBoxObj.value = curListBoxValueArray[curListBoxValueArray.length - 1];
  119. }
  120. else
  121. {
  122. InputBoxObj.valueMatrix(InputBoxObj.row, InputBoxObj.col) = curListBoxValueArray[curListBoxValueArray.length - 1];
  123. }
  124. model.setValue(listBoxRef, curListBoxValueArray[curListBoxValueArray.length - 1]);
  125. listBoxObj.attribute("height") = 0;
  126. selected_index = -1;
  127. //listBoxObj.value = listBoxObj.value;
  128. }
  129. }
  130. function selectItem() {
  131. //listBoxObj.attribute("height") = 0;
  132. //selected_index = -1;
  133. //listBoxObj.value = "";
  134. }
  135. // submission 생성
  136. function createSubmission(trgID, col) {
  137. var submitID = "sub_" + trgID +"_"+col;
  138. var submitObj = model1.createChild("xforms:submission","id:" + submitID + "; ");
  139. submitObj.attribute("mediatype") = "application/x-www-form-urlencoded";
  140. submitObj.attribute("method") = "post";
  141. submitObj.attribute("action") = getActionURL("TRZSC00101");
  142. submitObj.attribute("encoding") = "utf-8";
  143. submitObj.attribute("ref") = "/root/_search_info/" + trgID + "_" + col + "/send_data";
  144. submitObj.attribute("resultref") = "/root/_search_info/" + trgID + "_" + col + "/list";
  145. return submitObj;
  146. }
  147. // 자음 체크
  148. function checkConsonant(lastText) {
  149. var start = "ㄱ".charCodeAt(0);
  150. var end = "ㅎ".charCodeAt(0);
  151. for(var i=0; i<lastText.length; i++) {
  152. if(start <= lastText.charCodeAt(i) && lastText.charCodeAt(i) <= end) {
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. // 모음 체크
  159. function checkVowel(lastText) {
  160. var start = "ㅏ".charCodeAt(0);
  161. var end = "ㅣ".charCodeAt(0);
  162. for(var i=0; i<lastText.length; i++) {
  163. if(start <= lastText.charCodeAt(i) && lastText.charCodeAt(i) <= end) {
  164. return true;
  165. }
  166. }
  167. return false;
  168. }
  169. function searchGridOnkeyUp(col) {
  170. //if (submit_done = false) return;
  171. var keyCode = event.keyCode;
  172. //caption2.value = keyCode;
  173. var trgID = event.target;
  174. var inputObj = document.controls(trgID);
  175. var inputObjRef = inputObj.attribute("ref");
  176. var curText = inputObj.currentText;
  177. var curTextLength = curText.length;
  178. var lastText = curText.substr(curTextLength-1, curTextLength);
  179. if (inputObj.parent != null && inputObj.parent.elementName == "xforms:datagrid")
  180. {
  181. var gridCol = inputObj.parent.col;
  182. trgID = inputObj.parent.attribute("id");
  183. if ( gridCol != col)
  184. {
  185. return;
  186. }
  187. }
  188. var useYN = model.getValue("/root/_search_info/" + event.target + "_0/send_data/useyn");
  189. if (useYN == "N")
  190. {
  191. return;
  192. }
  193. var listBoxID = "lbx_" + trgID + "_"+col;
  194. var listBoxObj = document.controls(listBoxID);
  195. var listBoxRef = listBoxObj.attribute("ref");
  196. var listBoxNodeSet = "/root/_search_info/" + trgID + "_0/list/itemlist"
  197. var submitID = "sub_" + trgID + "_"+col;
  198. //inputObj.value = inputObj.currentText;
  199. // 현재 자동완성 되고있는 컨트롤을 전역변수에 세팅
  200. AClisboxObjID = listBoxID;
  201. ACinputObjID = trgID;
  202. // 방향키, 엔터키, curText.length = 0 아닐경우 Submit
  203. // + cashing
  204. if((keyCode < 37 || keyCode > 40) && keyCode != 13 && curText.length != 0) {
  205. if(checkConsonant(lastText) || checkVowel(lastText))
  206. return;
  207. //debug.value = inputObj.value.length;
  208. model.setValue(listBoxRef, inputObj.currentText);
  209. //listBoxObj.select(0);
  210. window.clearinterval(submit_timer);
  211. submit_timer = window.setInterval("zscfsubmit('"+submitID+"');", 1000);
  212. }
  213. // 방향키 ↑ : keyCdoe = 38
  214. else if(keyCode == 38 && listBoxObj.attribute("height") != 0) {
  215. listBoxObj.deselect(selected_index);
  216. // 리스트를 숨기고 원래 검색어를 보여줌
  217. listBoxObj.select(selected_index - 1);
  218. if(selected_index > 4)
  219. listBoxObj.vscroll.attribute("pos") = (selected_index - 5) * 16;
  220. selected_index--;
  221. //alert('키업');
  222. if(selected_index < 0)
  223. {
  224. inputObj.value = listBoxObj.value.split("▦")[0];
  225. listBoxObj.attribute("height") = 0;
  226. }
  227. else
  228. {
  229. //debug.value = listBoxObj.selectedIndex;
  230. inputObj.value = listBoxObj.value.split("▦")[1];
  231. }
  232. inputObj.selBegin = inputObj.value.length;
  233. }
  234. // 방향키 ↓ : keyCdoe = 40
  235. else if(keyCode == 40 && selected_index < item_cnt-1) {
  236. //debug.value = listBoxObj.length;
  237. //if(listBoxObj.length == 0) return;
  238. if(listBoxObj.attribute("height") == 0)
  239. {
  240. zscfsubmit(submitID);
  241. return;
  242. }
  243. if(listBoxObj.attribute("height") == 0) listBoxObj.attribute("height") = LIST_HEIGHT;
  244. if(selected_index >= 0)
  245. listBoxObj.deselect(selected_index);
  246. if(selected_index + 1 >4) {
  247. listBoxObj.vscroll.attribute("pos") = (selected_index - 3) * 16;
  248. }
  249. listBoxObj.select(++selected_index);
  250. //alert('키다운');
  251. //debug.value = listBoxObj.selectedIndex;
  252. inputObj.value = listBoxObj.value.split("▦")[1];
  253. inputObj.selBegin = inputObj.value.length;
  254. }
  255. //caption1.value = selected_index;
  256. // 엔터키 : keyCdoe = 13
  257. if(keyCode == 13) {
  258. //selectItem();
  259. //var listBoxID = event.currentTarget;
  260. //var listBoxObj = document.controls(listBoxID);
  261. //var InputBoxID = listBoxID.substr(4, listBoxID.lastIndexOf("_") - 4);
  262. //var InputBoxObj = document.controls(InputBoxID);
  263. //alert(InputBoxID);
  264. //if(listBoxObj.isCell(event.target)) {
  265. var curListBoxValue = listBoxObj.value;
  266. var curListBoxValueArray = curListBoxValue.split("▦");
  267. //listBoxObj.value = curListBoxValueArray[curListBoxValueArray.length - 1];
  268. //document.controls(trgID).value = curListBoxValueArray[curListBoxValueArray.length - 1];
  269. if (inputObj.parent != null && inputObj.parent.elementName == "xforms:datagrid")
  270. {
  271. inputObj.valueMatrix(inputObj.row, inputObj.col) = curListBoxValueArray[curListBoxValueArray.length - 1];
  272. }
  273. else
  274. {
  275. document.controls(trgID).value = curListBoxValueArray[curListBoxValueArray.length - 1];
  276. }
  277. model.setValue(listBoxRef, curListBoxValueArray[curListBoxValueArray.length - 1]);
  278. listBoxObj.attribute("height") = 0;
  279. selected_index = -1;
  280. //listBoxObj.value = listBoxObj.value;
  281. //}
  282. }
  283. // curText.length == 0
  284. if(curText.length == 0) {
  285. listBoxObj.attribute("height") = 0;
  286. model.setValue(listBoxRef, "");
  287. window.clearinterval(submit_timer);
  288. }
  289. // 키업이벤트 카운트 (For Debug)
  290. //var keyUpCnt = model.getValue("/root/main/keyup_cnt");
  291. //model.setValue("/root/main/keyup_cnt", ++keyUpCnt);
  292. //output1.refresh();
  293. }
  294. function xforms_submit_done() {
  295. //if (submit_done == true) return;
  296. if(event.currentTarget.indexOf("sub_") != -1) {
  297. var submitID = event.target;
  298. //lastIndex = submitID.lastIndexOf("_");
  299. var ctrlID = submitID.substr(4, submitID.lastIndexOf("_") - 4);
  300. var col = submitID.substr(submitID.lastIndexOf("_")+1, submitID.length -1);
  301. if(ACinputObjID != ctrlID) return; // 만약 현재 자동완성이 진행중인 컨트롤이 아니면 리턴
  302. var listboxID = "lbx_" + ctrlID + "_" + col;
  303. var listboxObj = document.controls.item(listboxID);
  304. var gridObj = document.controls.item(ctrlID);
  305. if( gridObj.elementName == "xforms:datagrid") {
  306. var inputObj = gridObj.input;
  307. if (parseInt(col) != gridObj.col) return; // 자신의 컬럼이 아니면 리턴
  308. listboxObj.attribute("top") = parseInt(gridObj.attribute("top")) + parseInt(inputObj.attribute("top")) + parseInt(inputObj.attribute("height")) + 1;
  309. listboxObj.attribute("left") = parseInt(gridObj.attribute("left")) + parseInt(inputObj.attribute("left")) -1;
  310. }
  311. listboxObj.attribute("height") = LIST_HEIGHT;
  312. listboxObj.refresh();
  313. //전역변수 초기화
  314. //submit_done = true;
  315. selected_index = -1;
  316. item_cnt = listboxObj.length;
  317. // 전역
  318. //model.setValue(listboxObj.attribute("ref"), "");
  319. //listboxObj.refresh();
  320. // 서브밋던이벤트 카운트
  321. //var doneCnt = model.getValue("/root/main/done_cnt");
  322. //model.setValue("/root/main/done_cnt", ++doneCnt);
  323. //output2.refresh();
  324. // event.stopPropagation();
  325. }
  326. }
  327. /**
  328. * @group :
  329. * @ver : 2007.05.15
  330. * @by : 이상준
  331. * @---------------------------------------------------
  332. * @type : function
  333. * @access : public
  334. * @desc : 컨트롤에 자동완성 기능을 부여하는 함수
  335. * @return : void
  336. * @---------------------------------------------------
  337. */
  338. function zscfMakeAC(controlID, orddeptcd, keywordflag, listWidth, col) { //
  339. if (col == null)
  340. {
  341. col = 0;
  342. }
  343. // 컨트롤생성
  344. createSearchListBox(controlID, orddeptcd, keywordflag, listWidth, col);
  345. // submission 생성
  346. createSubmission(controlID, col);
  347. }
  348. /**
  349. * @group :
  350. * @ver : 2007.05.15
  351. * @by : 이상준
  352. * @---------------------------------------------------
  353. * @type : function
  354. * @access : public
  355. * @desc : 컨트롤의 자동완성기능 여부를 리턴하는 함수
  356. * @return : bool
  357. * @---------------------------------------------------
  358. */
  359. function zscfGetUseYN(controlID, col) { //
  360. if (col == null)
  361. {
  362. col = 0;
  363. }
  364. var useryn = model.getValue("/root/_search_info/" + controlID + "_" + col + "/send_data/useyn"); // 사용여부 (기본값: true)
  365. if (useryn == "Y")
  366. return true;
  367. else
  368. return false;
  369. }
  370. /**
  371. * @group :
  372. * @ver : 2007.05.15
  373. * @by : 이상준
  374. * @---------------------------------------------------
  375. * @type : function
  376. * @access : public
  377. * @desc : 컨트롤의 자동완성기능을 설정하는 함수
  378. * @return : bool
  379. * @---------------------------------------------------
  380. */
  381. function zscfSetUseYN(controlID, useAC, col)
  382. {
  383. if (col == null)
  384. {
  385. col = 0;
  386. }
  387. var userynXpath = "/root/_search_info/" + controlID + "_" + col + "/send_data/useyn"; // 사용여부 (기본값: true)
  388. if (useAC == true)
  389. {
  390. model.setValue(userynXpath, "N");
  391. }
  392. else
  393. {
  394. model.setValue(userynXpath, "Y");
  395. }
  396. }