awtEx_20121220.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. var AwtFirstPos = 0;
  2. var AwtLastPos = 0;
  3. var AwtCarrotPos = 0;
  4. var AwtSearchWord = null;
  5. var AwtObjId = null;
  6. var AwtMode = null;
  7. var AwtUserInfo = getUserInfo("userid");
  8. if (AwtUserInfo == "")
  9. AwtUserInfo = "test1";
  10. function AwtSearch_Form() {
  11. if (event.keyCode == 192 && event.ctrlkey == 1) {
  12. AwtMode = "CtrlTilt";
  13. } else if (event.keyCode == 32 && event.ctrlkey == 1) {
  14. AwtMode = "CtrlSpace";
  15. } else {
  16. return;
  17. }
  18. var ctrl = null;
  19. ctrl = document.controls(model.getFocus());
  20. //그리드에서 입력받은 경우에는 그리드의 input 박스를..
  21. if (document.controls(event.currentTarget).elementName == "xforms:datagrid") {
  22. ctrl = document.controls(event.currentTarget).input;
  23. }
  24. var text = ctrl.currentText;
  25. //캐럿 위치 표시
  26. AwtCarrotPos = ctrl.selEnd;
  27. AwtLastPos = AwtCarrotPos;
  28. for ( ; AwtLastPos < text.length; AwtLastPos++) {
  29. //alert("lastPos " + AwtLastPos + "-" + text.substr(AwtLastPos, 1));
  30. if ( text.substr(AwtLastPos, 1) == String.fromCharCode(32) //space
  31. || text.substr(AwtLastPos, 1) == String.fromCharCode(9) //tab
  32. || text.substr(AwtLastPos, 1) == String.fromCharCode(13) //cr
  33. || text.substr(AwtLastPos, 1) == String.fromCharCode(10) //lf
  34. ) {
  35. break;
  36. }
  37. }
  38. if (AwtFirstPos > text.length)
  39. AwtFirstPos = 0;
  40. AwtFirstPos = AwtLastPos - 1;
  41. for ( ; AwtFirstPos >= 0; AwtFirstPos--) {
  42. //alert("firstPos " + AwtFirstPos + "-" + text.substr(AwtFirstPos, 1));
  43. if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space
  44. || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab
  45. || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr
  46. || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf
  47. ) {
  48. AwtFirstPos++;
  49. break;
  50. }
  51. }
  52. if (AwtFirstPos < 0)
  53. AwtFirstPos = 0;
  54. AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos);
  55. //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos);
  56. if (AwtSearchWord != "") {
  57. AwtObjId = ctrl.attribute("id");
  58. xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  59. if (AwtMode == "CtrlSpace")
  60. send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //공용DB에서만 검색
  61. else if (AwtMode == "CtrlTilt")
  62. send(0, AwtSearchWord, "autocomplete", AwtUserInfo); //개인DB에서만 검색
  63. }
  64. }
  65. function AwtSearch_CtrlSpace() {
  66. if (event.keyCode == 192 && event.ctrlkey == 1) {
  67. AwtMode = "CtrlTilt";
  68. } else if (event.keyCode == 32 && event.ctrlkey == 1) {
  69. AwtMode = "CtrlSpace";
  70. } else {
  71. return;
  72. }
  73. var ctrl = null;
  74. ctrl = document.controls(event.currentTarget);
  75. //그리드에서 입력받은 경우에는 그리드의 input 박스를..
  76. if (document.controls(event.currentTarget).elementName == "xforms:datagrid") {
  77. ctrl = document.controls(event.currentTarget).input;
  78. }
  79. var text = ctrl.currentText;
  80. //캐럿 위치 표시
  81. AwtCarrotPos = ctrl.selEnd;
  82. AwtLastPos = AwtCarrotPos;
  83. for ( ; AwtLastPos < text.length; AwtLastPos++) {
  84. //alert(AwtLastPos + "-" + text.substr(AwtLastPos, 1));
  85. if ( text.substr(AwtLastPos, 1) == String.fromCharCode(32) //space
  86. || text.substr(AwtLastPos, 1) == String.fromCharCode(9) //tab
  87. || text.substr(AwtLastPos, 1) == String.fromCharCode(13) //cr
  88. || text.substr(AwtLastPos, 1) == String.fromCharCode(10) //lf
  89. ) {
  90. break;
  91. }
  92. }
  93. if (AwtFirstPos > text.length)
  94. AwtFirstPos = 0;
  95. AwtFirstPos = AwtLastPos - 1;
  96. for ( ; AwtFirstPos >= 0; AwtFirstPos--) {
  97. //alert(AwtFirstPos + "-" + text.substr(AwtFirstPos, 1));
  98. if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space
  99. || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab
  100. || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr
  101. || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf
  102. ) {
  103. AwtFirstPos++;
  104. break;
  105. }
  106. }
  107. if (AwtFirstPos < 0)
  108. AwtFirstPos = 0;
  109. AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos);
  110. //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos);
  111. if (AwtSearchWord != "") {
  112. AwtObjId = ctrl.attribute("id");
  113. xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  114. if (AwtMode == "CtrlSpace")
  115. send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //공용DB에서만 검색
  116. else if (AwtMode == "CtrlTilt")
  117. send(0, AwtSearchWord, "autocomplete", AwtUserInfo); //개인DB에서만 검색
  118. }
  119. }
  120. function AwtSearch_Space() {
  121. if (event.keyCode == 32 && event.ctrlkey != 1 && event.altkey != 1) {
  122. AwtMode = "Space";
  123. } else {
  124. return;
  125. }
  126. var ctrl = null;
  127. ctrl = document.controls(event.currentTarget);
  128. //그리드에서 입력받은 경우에는 그리드의 input 박스를..
  129. if (document.controls(event.currentTarget).elementName == "xforms:datagrid") {
  130. ctrl = document.controls(event.currentTarget).input;
  131. }
  132. var text = ctrl.currentText;
  133. //캐럿 위치 표시
  134. AwtCarrotPos = ctrl.selEnd;
  135. AwtLastPos = AwtCarrotPos - 1; //값
  136. AwtFirstPos = AwtLastPos - 1;
  137. for ( ; AwtFirstPos >= 0; AwtFirstPos--) {
  138. //alert(AwtFirstPos + "-" + text.substr(AwtFirstPos, 1));
  139. if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space
  140. || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab
  141. || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr
  142. || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf
  143. ) {
  144. AwtFirstPos++;
  145. break;
  146. }
  147. }
  148. if (AwtFirstPos < 0)
  149. AwtFirstPos = 0;
  150. AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos);
  151. //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos);
  152. if (AwtSearchWord != "") {
  153. AwtObjId = ctrl.attribute("id");
  154. xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  155. send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //공용DB에서만 검
  156. }
  157. }
  158. function replaceAll(str, org, nxt) {
  159. var rstl = "";
  160. for (var i = 0; i < str.length; i++) {
  161. if (str.substr(i, 1) == org)
  162. rstl = rstl + nxt;
  163. else
  164. rstl = rstl + str.substr(i, 1);
  165. }
  166. return rstl;
  167. }
  168. function SetAwtSelect(awtStr) {
  169. if (awtStr == "")
  170. return;
  171. if (awtStr == AwtSearchWord)
  172. return;
  173. awtStr = replaceAll(awtStr, "\r", "");
  174. var obj = null;
  175. var dotPos = AwtObjId.indexOf(".");
  176. var gridId = '';
  177. if (dotPos != -1) {
  178. gridId = AwtObjId.substr(0, dotPos);
  179. obj = document.controls(gridId);
  180. obj = obj.children("input");
  181. } else
  182. obj = document.controls(AwtObjId);
  183. var first = obj.currentText.substr(0,AwtFirstPos);
  184. var last = obj.currentText.substr(AwtLastPos, obj.currentText.length);
  185. //alert(AwtFirstPos + "-'" + first + "' len:" + first.length + "****" + AwtLastPos + "-'" + last + "' len:" + last.length);
  186. // if (dotPos != -1) {
  187. // var grd = document.controls(gridId);
  188. // grd.valueMatrix(grd.row, grd.col) = first + awtStr + last;
  189. // grd.editCell();
  190. // model.setFocus(gridId);
  191. // grd.editCell();
  192. // } else {
  193. obj.currentText = first + awtStr + last;
  194. // }
  195. if (AwtMode == "Space")
  196. AwtCarrotPos = AwtCarrotPos - AwtSearchWord.length + awtStr.length;
  197. else // if (AwtMode == "CtrlSpace")
  198. AwtCarrotPos = AwtFirstPos + awtStr.length;
  199. obj.selBegin = AwtCarrotPos;
  200. obj.selEnd = AwtCarrotPos;
  201. }
  202. ////////////////////////////
  203. var xmlHttpRequest = null;
  204. function send(nOption,strSpell,strFlag,strDomain)
  205. {
  206. var strPostValue = encodeURI("option="+nOption+"&strSpell="+strSpell+"&strFlag="+strFlag +"&domain=" + strDomain + "&searchCount=" + 1); //일치하는거 한개만..
  207. xmlHttpRequest.open('POST', AwtServerUrl, true);
  208. xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  209. xmlHttpRequest.onreadystatechange = function() {
  210. if (xmlHttpRequest.readyState == 4)
  211. {
  212. switch (xmlHttpRequest.status)
  213. {
  214. case 404:
  215. // alert('오류: ' + AwtServerUrl + '이 존재하지 않음');
  216. break;
  217. case 200:
  218. OnResult(xmlHttpRequest.responseText.trim());
  219. break;
  220. default:
  221. // alert('오류: ' + xmlHttpRequest.responseText);
  222. break;
  223. }
  224. }
  225. }
  226. xmlHttpRequest.send(strPostValue);
  227. }
  228. function OnResult(strVal)
  229. {
  230. nCurrent=0;
  231. if (strVal.length > 0) {
  232. if (AwtMode == "Space")
  233. SetAwtSelect(strVal.replace("▩", ""));
  234. else
  235. SetAwtSelect(strVal.replace("▩", ""));
  236. }
  237. }
  238. String.prototype.trim = function ()
  239. {
  240. return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  241. }