123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- var AwtFirstPos = 0;
- var AwtLastPos = 0;
- var AwtCarrotPos = 0;
- var AwtSearchWord = null;
- var AwtObjId = null;
- var AwtMode = null;
- var AwtUserInfo = getUserInfo("userid");
- if (AwtUserInfo == "")
- AwtUserInfo = "test1";
- function AwtSearch_Form() {
-
- if (event.keyCode == 192 && event.ctrlkey == 1) {
- AwtMode = "CtrlTilt";
- } else if (event.keyCode == 32 && event.ctrlkey == 1) {
- AwtMode = "CtrlSpace";
- } else {
- return;
- }
-
- var ctrl = null;
-
- ctrl = document.controls(model.getFocus());
- //그리드에서 입력받은 경우에는 그리드의 input 박스를..
- if (document.controls(event.currentTarget).elementName == "xforms:datagrid") {
- ctrl = document.controls(event.currentTarget).input;
- }
-
- var text = ctrl.currentText;
-
- //캐럿 위치 표시
- AwtCarrotPos = ctrl.selEnd;
-
- AwtLastPos = AwtCarrotPos;
- for ( ; AwtLastPos < text.length; AwtLastPos++) {
- //alert("lastPos " + AwtLastPos + "-" + text.substr(AwtLastPos, 1));
- if ( text.substr(AwtLastPos, 1) == String.fromCharCode(32) //space
- || text.substr(AwtLastPos, 1) == String.fromCharCode(9) //tab
- || text.substr(AwtLastPos, 1) == String.fromCharCode(13) //cr
- || text.substr(AwtLastPos, 1) == String.fromCharCode(10) //lf
- ) {
- break;
- }
- }
-
- if (AwtFirstPos > text.length)
- AwtFirstPos = 0;
-
- AwtFirstPos = AwtLastPos - 1;
- for ( ; AwtFirstPos >= 0; AwtFirstPos--) {
- //alert("firstPos " + AwtFirstPos + "-" + text.substr(AwtFirstPos, 1));
- if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf
- ) {
- AwtFirstPos++;
- break;
- }
- }
-
- if (AwtFirstPos < 0)
- AwtFirstPos = 0;
-
- AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos);
-
- //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos);
-
- if (AwtSearchWord != "") {
- AwtObjId = ctrl.attribute("id");
-
- xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
- if (AwtMode == "CtrlSpace")
- send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //공용DB에서만 검색
- else if (AwtMode == "CtrlTilt")
- send(0, AwtSearchWord, "autocomplete", AwtUserInfo); //개인DB에서만 검색
- }
- }
- function AwtSearch_CtrlSpace() {
- if (event.keyCode == 192 && event.ctrlkey == 1) {
- AwtMode = "CtrlTilt";
- } else if (event.keyCode == 32 && event.ctrlkey == 1) {
- AwtMode = "CtrlSpace";
- } else {
- return;
- }
-
- var ctrl = null;
-
- ctrl = document.controls(event.currentTarget);
- //그리드에서 입력받은 경우에는 그리드의 input 박스를..
- if (document.controls(event.currentTarget).elementName == "xforms:datagrid") {
- ctrl = document.controls(event.currentTarget).input;
- }
-
- var text = ctrl.currentText;
-
- //캐럿 위치 표시
- AwtCarrotPos = ctrl.selEnd;
-
- AwtLastPos = AwtCarrotPos;
- for ( ; AwtLastPos < text.length; AwtLastPos++) {
- //alert(AwtLastPos + "-" + text.substr(AwtLastPos, 1));
- if ( text.substr(AwtLastPos, 1) == String.fromCharCode(32) //space
- || text.substr(AwtLastPos, 1) == String.fromCharCode(9) //tab
- || text.substr(AwtLastPos, 1) == String.fromCharCode(13) //cr
- || text.substr(AwtLastPos, 1) == String.fromCharCode(10) //lf
- ) {
- break;
- }
- }
-
- if (AwtFirstPos > text.length)
- AwtFirstPos = 0;
-
- AwtFirstPos = AwtLastPos - 1;
- for ( ; AwtFirstPos >= 0; AwtFirstPos--) {
- //alert(AwtFirstPos + "-" + text.substr(AwtFirstPos, 1));
- if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf
- ) {
- AwtFirstPos++;
- break;
- }
- }
-
- if (AwtFirstPos < 0)
- AwtFirstPos = 0;
-
- AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos);
-
- //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos);
-
- if (AwtSearchWord != "") {
- AwtObjId = ctrl.attribute("id");
-
- xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
- if (AwtMode == "CtrlSpace")
- send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //공용DB에서만 검색
- else if (AwtMode == "CtrlTilt")
- send(0, AwtSearchWord, "autocomplete", AwtUserInfo); //개인DB에서만 검색
- }
- }
- function AwtSearch_Space() {
- if (event.keyCode == 32 && event.ctrlkey != 1 && event.altkey != 1) {
- AwtMode = "Space";
- } else {
- return;
- }
-
- var ctrl = null;
-
- ctrl = document.controls(event.currentTarget);
- //그리드에서 입력받은 경우에는 그리드의 input 박스를..
- if (document.controls(event.currentTarget).elementName == "xforms:datagrid") {
- ctrl = document.controls(event.currentTarget).input;
- }
-
- var text = ctrl.currentText;
- //캐럿 위치 표시
- AwtCarrotPos = ctrl.selEnd;
- AwtLastPos = AwtCarrotPos - 1; //값
-
- AwtFirstPos = AwtLastPos - 1;
- for ( ; AwtFirstPos >= 0; AwtFirstPos--) {
- //alert(AwtFirstPos + "-" + text.substr(AwtFirstPos, 1));
- if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr
- || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf
- ) {
- AwtFirstPos++;
- break;
- }
- }
-
- if (AwtFirstPos < 0)
- AwtFirstPos = 0;
-
- AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos);
-
- //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos);
-
- if (AwtSearchWord != "") {
- AwtObjId = ctrl.attribute("id");
-
- xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
- send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //공용DB에서만 검
- }
- }
- function replaceAll(str, org, nxt) {
- var rstl = "";
- for (var i = 0; i < str.length; i++) {
- if (str.substr(i, 1) == org)
- rstl = rstl + nxt;
- else
- rstl = rstl + str.substr(i, 1);
- }
- return rstl;
- }
- function SetAwtSelect(awtStr) {
- if (awtStr == "")
- return;
-
- if (awtStr == AwtSearchWord)
- return;
-
- awtStr = replaceAll(awtStr, "\r", "");
- var obj = null;
- var dotPos = AwtObjId.indexOf(".");
- var gridId = '';
-
- if (dotPos != -1) {
- gridId = AwtObjId.substr(0, dotPos);
- obj = document.controls(gridId);
- obj = obj.children("input");
- } else
- obj = document.controls(AwtObjId);
-
- var first = obj.currentText.substr(0,AwtFirstPos);
- var last = obj.currentText.substr(AwtLastPos, obj.currentText.length);
-
- //alert(AwtFirstPos + "-'" + first + "' len:" + first.length + "****" + AwtLastPos + "-'" + last + "' len:" + last.length);
- // if (dotPos != -1) {
- // var grd = document.controls(gridId);
- // grd.valueMatrix(grd.row, grd.col) = first + awtStr + last;
- // grd.editCell();
- // model.setFocus(gridId);
- // grd.editCell();
- // } else {
- obj.currentText = first + awtStr + last;
- // }
- if (AwtMode == "Space")
- AwtCarrotPos = AwtCarrotPos - AwtSearchWord.length + awtStr.length;
- else // if (AwtMode == "CtrlSpace")
- AwtCarrotPos = AwtFirstPos + awtStr.length;
- obj.selBegin = AwtCarrotPos;
- obj.selEnd = AwtCarrotPos;
- }
- ////////////////////////////
- var xmlHttpRequest = null;
- function send(nOption,strSpell,strFlag,strDomain)
- {
-
- var strPostValue = encodeURI("option="+nOption+"&strSpell="+strSpell+"&strFlag="+strFlag +"&domain=" + strDomain + "&searchCount=" + 1); //일치하는거 한개만..
- xmlHttpRequest.open('POST', AwtServerUrl, true);
- xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
-
- xmlHttpRequest.onreadystatechange = function() {
- if (xmlHttpRequest.readyState == 4)
- {
- switch (xmlHttpRequest.status)
- {
- case 404:
- // alert('오류: ' + AwtServerUrl + '이 존재하지 않음');
- break;
- case 200:
- OnResult(xmlHttpRequest.responseText.trim());
- break;
- default:
- // alert('오류: ' + xmlHttpRequest.responseText);
- break;
- }
- }
- }
-
- xmlHttpRequest.send(strPostValue);
- }
- function OnResult(strVal)
- {
- nCurrent=0;
- if (strVal.length > 0) {
- if (AwtMode == "Space")
- SetAwtSelect(strVal.replace("▩", ""));
- else
- SetAwtSelect(strVal.replace("▩", ""));
- }
- }
- String.prototype.trim = function ()
- {
- return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
- }
|