Edit C:\galaxie\Back\galaxie\js\ac\fobAC_js.jsp
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl"%><% response.setContentType("application/x-javascript"); %> // These are the currently active fob fields. // These two variables are set by the fields' onFocus() method var acCurDisplayField; var acCurIDField; var acCurFieldName; // The last key that was pressed while the focus was on a FOB field var acLastKeyPressed; // The cache of all the results received thus far. Helpful on slow connections var acResultCache = new Object(); // The link that will be called by ajax var acAjaxURL = '<fl:webapp/>/AjaxAutoComplete'; // xml http object used to call home var xmlHTTP; // Each fob field has its own div to hold results. This array holds these divs // Index is the field name, ie. "lblEntActID" var acResultDivs = new Object(); // The old and new display values for each fob field. Old values become new values after each timeout period, // not after each keypress. // Index is the field name, ie. "lblEntActID" var acLastDisplayValues = new Object(); var acCurrentDisplayValues = new Object(); // acLastCompleteValues is an array storing the last "good" values of a field. Both the ID and // display value are stored here, as two seperate strings. var acLastCompleteValues = new Array(); // acDisplayDivs is used to store the divs and iframes. When a user clicks on // a text field, the position of the AC elements are recalculated. This is // because fobAC fields that are contained in small tabs need this. var acDisplayDivs = new Array(); // The number of suggestions a given fob field currently has. // Index is the field name, ie. "lblEntActID" var acNumResults = new Object(); // The currently highlighted suggestion var acCurHighlightedIndex = -1; // The complete list of suggestions var acCurSuggestionList; // The div which contains the currently highlighted suggestion. // This div is a subcomponent of the acCurSuggestionList div var acCurHighlightedDiv; // Variable used to calculate how much time we should give for a timeout. Useful // on slower connections var acTimeoutAdjustment = 0; // Mouse click handler function var acOnMouseDown; function doBlurThenGetFocus() { blurThenGetFocus=true; acCurDisplayField.blur(); setTimeout("setInputFieldFocus();",10); } /** * 'Unconverts' a string that has been formatted to the web. See the method to see which * characters are currently converted */ function formatFromWeb(pStr) { return pStr.replace('&','&').replace('"','"').replace('<','<').replace('>','>'); } function selectEntry(newValue, newID) { if (!newID || newID == '' || newID.length != 16) { return; } if (!newValue || newValue == '') { return; } var displayVar = formatFromWeb(newValue); acCurDisplayField.value = displayVar; acCurIDField.value = newID; acLastCompleteValues[acCurDisplayField.name] = displayVar; acLastCompleteValues[acCurIDField.name] = newID; // Is there a field change function? var changeFuncName = 'do' + acCurDisplayField.name.substring(3) + 'Change'; if (changeFuncName.indexOf('-')<0) { eval('try{' + changeFuncName + '();}catch(error){}'); } // Add doTriggerChange for new grid edition mode if (typeof(doTriggerChangeFromAc) == 'function') { doTriggerChangeFromAc(acCurDisplayField.name.substring(3)); } } // This method restores the display and id field of the given edeal field to the // last known "good" value. This is only called from the onBlur method. function restoreCurrentEntries() { // Added for the edit_selection2 action. if (!acCurDisplayField) { return; } acCurDisplayField.value = acLastCompleteValues[acCurDisplayField.name]; acLastDisplayValues[acCurDisplayField.name] = acLastCompleteValues[acCurDisplayField.name]; acCurrentDisplayValues[acCurDisplayField.name] = acLastCompleteValues[acCurDisplayField.name]; acCurIDField.value = acLastCompleteValues[acCurIDField.name]; } function checkKeypress(localCompleteDiv){ var localInputField = acCurDisplayField; var T=false; acCurHighlightedIndex = -1; acCurSuggestionList = localCompleteDiv.getElementsByTagName("div"); var listLength = acCurSuggestionList.length; if(acCurrentDisplayValues[acCurDisplayField.name] == "" || listLength == 0) { hideFieldDiv(); } else { showFieldDiv(); } acCurHighlightedIndex = -1; acCurHighlightedDiv = null; } // This onBlurHandler is responsable for maintaining the integrity of the two fields of a // FOB input. function acOnBlurHandler(event) { if(!event && window.event) { event=window.event; } if (acLastKeyPressed != 38 && acLastKeyPressed != 40) { hideFieldDiv(); restoreCurrentEntries(); } } function acResizeDisplayDiv(targetField) { setCompleteDivSize(acDisplayDivs[targetField.name], targetField); setCompleteDivSize(acDisplayDivs["shim_" + targetField.name], targetField); } var acKeyPressHandler = function(e) { acLastKeyPressed = e.keyCode; //JSA prevent event to bubble if (acCurHighlightedDiv!=null) { if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } } acHandleKey(); }; setInputFieldFocus=function(){ acCurDisplayField.focus(); }; function acGetRange(n){ var N=-1; if (n.createTextRange) { var fa=document.selection.createRange().duplicate(); N=fa.text.length } else if (n.setSelectionRange) { N=n.selectionEnd-n.selectionStart } return N } function acGetSelection(n){ var v=0; if(n.createTextRange){ var fa=document.selection.createRange().duplicate(); fa.moveEnd("textedit",1); v=n.value.length-fa.text.length }else if(n.setSelectionRange){ v=n.selectionStart }else{ v=-1 } return v } function handleCursorUpDownEnter(eventCode) { if(eventCode == 40){ highlightNewValue(acCurHighlightedIndex + 1); return false; } else if(eventCode == 38) { highlightNewValue(acCurHighlightedIndex - 1); return false; } else if(eventCode == 13 || eventCode == 3) { selectEntry(valueOfCAutoComplete(acCurHighlightedDiv), valueOfDAutoComplete(acCurHighlightedDiv)); hideFieldDiv(); return false; } return true; } function findSpanValueForClass(i,dc){ var ga=i.getElementsByTagName("span"); if(ga){ for(var f=0; f<ga.length; ++f){ if(ga[f].className==dc){ var value=ga[f].innerHTML; if(value==" ") { return ""; } else{ return stripCRFromString(value); } } } } else { return ""; } } function valueOfCAutoComplete(i){ if(!i) { return null; } return findSpanValueForClass(i,"cAutoComplete") } function valueOfDAutoComplete(i){ if(!i) { return null; } return findSpanValueForClass(i,"dAutoComplete") } function acHandleKey() { // 38 is up cursor key, 40 is down cursor key... if(acLastKeyPressed == 40 || acLastKeyPressed == 38) { doBlurThenGetFocus(); } var isSpecialKey = false; switch(acLastKeyPressed) { //case 8: case 9: case 13: case 33: case 34: case 35: case 35: case 36: case 37: case 39: case 45: //case 46: isSpecialKey = true; break; default: break; } acCurrentDisplayValues[acCurDisplayField.name] = acCurDisplayField.value; if(handleCursorUpDownEnter(acLastKeyPressed) && acLastKeyPressed != 0) { checkKeypress(acCurDisplayField); } } function acCalcDisplayOffset(displayFld, offsetType) { var rtrn = 0; while(displayFld) { rtrn += displayFld[offsetType]; displayFld = displayFld.offsetParent; } return rtrn; } function calculateDisplayWidth(displayFld) { if (displayFld == null) { return; } if(isMSIE()) { return displayFld.offsetWidth; } else { return displayFld.offsetWidth - 2; } } function acCacheResults(inputName, index, val1, val2){ var cache = acResultCache[inputName]; if (!cache) { acResultCache[inputName] = new Object(); cache = acResultCache[inputName]; } cache[index] = new Array(val1, val2); } function setStyleForElement(domObject, name) { if (domObject == null) { return; } var bottom = calculateDisplayWidth(domObject); var p; if (bottom == 0) { p = 125; } else { p = (calculateDisplayWidth(domObject) - 110) / bottom * 100; } domObject.className = name; // See displaySuggestedList() for more info switch(name.charAt(0)){ case "m": domObject.style.fontSize="10px"; domObject.style.fontFamily="arial,sans-serif"; domObject.style.wordWrap="break-word"; break; case "l": domObject.style.display="block"; domObject.style.paddingLeft="3"; domObject.style.paddingRight="3"; domObject.style.height="16px"; domObject.style.overflow="hidden"; break; case "a": domObject.style.backgroundColor="white"; domObject.style.color="black"; if(domObject.displaySpan){ domObject.displaySpan.style.color="green" } break; case "b": domObject.style.backgroundColor="#3366cc"; domObject.style.color="white"; if(domObject.displaySpan){ domObject.displaySpan.style.color="white" } break; case "c": domObject.style.width="100%"; domObject.style.cssFloat="left"; break; case "d": // This one is for the IDs, which we don't want to display anyway. domObject.style.display = "none"; break; } } function installFobAC(displayFld) { acCurFieldName = displayFld.name; displayFld.autocomplete = "off"; displayFld.onblur = acOnBlurHandler; if (displayFld.createTextRange) { displayFld.onkeyup = new Function("return acKeyPressHandler(event);"); } else { displayFld.onkeyup = acKeyPressHandler; } var newDiv = document.createElement("DIV"); newDiv.id = "resultDiv_" + displayFld.name; //newDiv.style.borderRight = "black 1px solid"; //newDiv.style.borderLeft = "black 1px solid"; //newDiv.style.borderTop = "black 1px solid"; //newDiv.style.borderBottom = "black 1px solid"; newDiv.style.zIndex = "100"; newDiv.style.paddingRight = "0"; newDiv.style.paddingLeft = "0"; newDiv.style.paddingTop = "0"; newDiv.style.paddingBottom = "0"; setCompleteDivSize(newDiv, displayFld); newDiv.style.visibility = "hidden"; newDiv.style.position = "absolute"; newDiv.style.backgroundColor = "white"; document.body.appendChild(newDiv); acLastDisplayValues[displayFld.name] = displayFld.value; acLastCompleteValues[displayFld.name] = displayFld.value; acDisplayDivs[displayFld.name] = newDiv; var _idField = document.getElementById(displayFld.name.substring(3)); acLastCompleteValues[displayFld.name.substring(3)] = _idField.value; acCacheResults(displayFld.name, "", "", ""); setStyleForElement(newDiv,"oldAutoComplete"); var shim = document.createElement("IFRAME"); shim.id = "shim_" + displayFld.name; shim.name = "shim_" + displayFld.name; shim.src="javascript:false"; shim.style.zIndex = "99"; shim.style.border = "none"; shim.style.overflow = "hidden"; shim.style.padding = "0px"; shim.style.height = "0px"; setCompleteDivSize(shim, displayFld); shim.style.visibility = "hidden"; shim.style.position = "absolute"; document.body.appendChild(shim); acDisplayDivs["shim_" + displayFld.name] = shim; // Hack for the the div to align itself with the iFrame. // This bug shows itself in single column bigTabs // (ie. Person->Create Event) newDiv.style.left = shim.style.left; var secondDiv = document.createElement("DIV"); secondDiv.style.visibility = "hidden"; secondDiv.style.position = "absolute"; secondDiv.style.left="-10000"; secondDiv.style.top="-10000"; secondDiv.style.width="0"; secondDiv.style.height="0"; var iFrame = document.createElement("IFRAME"); iFrame.completeDiv = newDiv; iFrame.shim = shim; iFrame.name = "completionFrame_" + displayFld.name; iFrame.id = "completionFrame_" + displayFld.name; iFrame.src = acAjaxURL; secondDiv.appendChild(iFrame); document.body.appendChild(secondDiv); acResultDivs[displayFld.name] = iFrame; } function getXMLHTTP(){ var A=null; try { A=new ActiveXObject("Msxml2.XMLHTTP") }catch(e){ try{ A=new ActiveXObject("Microsoft.XMLHTTP") } catch(oc){ A=null } } if(!A && typeof XMLHttpRequest != "undefined") { A=new XMLHttpRequest() } return A } var acSuggestionMouseOver = function() { //if(_highlightedSuggestionDiv) { //setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete"); //} setStyleForElement(this,"bAutoComplete") }; var acSuggestionMouseOut = function() { setStyleForElement(this,"aAutoComplete") }; // Called by parseAjaxResponse to display the suggestions function displaySuggestedList(acDiv, listResults, listIDs){ while(acDiv.childNodes.length > 0) { acDiv.removeChild(acDiv.childNodes[0]); } acNumResults[acCurDisplayField.name] = listResults.length; // For each element in our list, we create: // <DIV (u) - mousedown/mouseover/mouseout aAutoComplete> // <SPAN (ka) lAutoComplete> // <SPAN (ua) cAutoComplete> // M. KREULEN Brian // </SPAN (ua)> // <SPAN (ea) dAutoComplete> // This span is hidden // 0000d50000001fdb // </SPAN (ea)> // </SPAN> // </DIV (u)> for(var f = 0; f < listResults.length; ++f) { var u=document.createElement("DIV"); setStyleForElement(u,"aAutoComplete"); u.onmousedown = acOnMouseDown; u.onmouseover = acSuggestionMouseOver; u.onmouseout = acSuggestionMouseOut; var ka=document.createElement("SPAN"); setStyleForElement(ka,"lAutoComplete"); var ua=document.createElement("SPAN"); ua.innerHTML=listResults[f]; // the text for the suggested result... var ea=document.createElement("SPAN"); setStyleForElement(ea,'dAutoComplete'); setStyleForElement(ua,"cAutoComplete"); u.displaySpan=ea; ea.innerHTML=listIDs[f]; // The ID of the suggested result ka.appendChild(ua); ka.appendChild(ea); u.appendChild(ka); acDiv.appendChild(u); } } function hideFieldDiv(){ if (!acCurDisplayField) { return; } if (!acResultDivs[acCurDisplayField.name]) { return; } acResultDivs[acCurDisplayField.name].completeDiv.style.visibility = "hidden"; acResultDivs[acCurDisplayField.name].shim.style.visibility = "hidden"; acResultDivs[acCurDisplayField.name].shim.style.display = "none"; acCurHighlightedDiv = null; } function showFieldDiv(){ if (!acCurDisplayField) { return; } if (!acResultDivs[acCurDisplayField.name]) { return; } acResultDivs[acCurDisplayField.name].completeDiv.style.visibility = "visible"; acResultDivs[acCurDisplayField.name].shim.style.visibility = "visible"; acResultDivs[acCurDisplayField.name].shim.style.display = "block"; } function setCompleteDivSize(divToSet, sourceField){ if(divToSet){ divToSet.style.left = acCalcDisplayOffset(sourceField, "offsetLeft") + "px"; divToSet.style.top = acCalcDisplayOffset(sourceField, "offsetTop") + sourceField.offsetHeight - 1 + "px"; divToSet.style.width = calculateDisplayWidth(sourceField) + "px"; } } // Called in resposne to a successfull ajax phone home parseAjaxResponse = function(iFrame, searchTerm, listResults, listIDs) { if(acTimeoutAdjustment > 0) { acTimeoutAdjustment--; } acCacheResults(acCurDisplayField.name, searchTerm, listResults, listIDs); var b = iFrame.completeDiv; var s = iFrame.shim; b.completeStrings = listResults; b.displayStrings = listIDs; //b.prefixStrings=pr; displaySuggestedList(b,b.completeStrings,b.displayStrings); checkKeypress(b); if(acCurrentDisplayValues[acCurDisplayField.name] == "" || 0 == listResults.length) { hideFieldDiv() }else{ showFieldDiv() } if(listResults.length > 0) { s.style.width = b.offsetWidth; b.height = 16 * listResults.length + 4; s.style.height = b.height; } else { hideCompleteDiv(); } } // Function that calls home and gets the data. function callEDeal(escapedSearchTerm) { if(xmlHTTP && xmlHTTP.readyState!=0){ xmlHTTP.abort() } if (!acCurDisplayField) { return; } var fldName = acCurDisplayField.name; var acField = fldName.substring(3,fldName.length); //JSA if (acField.indexOf('-')>0) { acField=acField.substring(0,acField.indexOf('-')); } var url = acAjaxURL + '?field=' + acField + '&search=' + escapedSearchTerm; var querField = '_' + acField + '_query'; try { eval('url += \'&query=\' + escape(' + querField + ');'); } catch (error) { } xmlHTTP=getXMLHTTP(); if(xmlHTTP){ // We end up calling: // /complete/search?hl=en&js=true&qu=<my query string...> ... xmlHTTP.open("GET", url, true); // Note that this function will ONLY be called when we get a complete // response back from google!! xmlHTTP.onreadystatechange=function() { if(xmlHTTP.readyState == 4 && xmlHTTP.responseText) { var frameElement = acResultDivs[acCurDisplayField.name]; if(xmlHTTP.responseText.charAt(0) == "<") { acTimeoutAdjustment--; } else { // The response text gets executed as javascript... eval(xmlHTTP.responseText); } } }; // DON'T TRY TO TALK WHEN WE'RE LOCAL... // Comment out when running from a local file... xmlHTTP.send(null); } } function recalculateTimeout(Mb){ var H=100; for(var o=1; o<=(Mb-2)/2; o++){ H=H*2 } H=H+50; return H } // Main timeout based loop var mainLoop = function() { if (!acCurDisplayField) { setTimeout("mainLoop()",recalculateTimeout(acTimeoutAdjustment)); return true; } var lastValue; try { lastValue = acLastDisplayValues[acCurDisplayField.name]; } catch (err) { lastValue = ""; } var newValue; try { newValue = acCurrentDisplayValues[acCurDisplayField.name]; } catch (err) { newValue = ""; } if (newValue != '' && lastValue != newValue) { var escapedValue = escapeURI(newValue); var ourCache = acResultCache[acCurDisplayField.name]; var ma = null; if (ourCache) { ma = ourCache[newValue]; } if (ma) { parseAjaxResponse(acResultDivs[acCurDisplayField.name], newValue, ma[0], ma[1], acResultDivs[acCurDisplayField.name].completeDiv.prefixStrings); } else { acTimeoutAdjustment++; callEDeal(escapedValue); } acCurDisplayField.focus(); } acLastDisplayValues[acCurDisplayField.name] = acCurrentDisplayValues[acCurDisplayField.name]; setTimeout("mainLoop()",recalculateTimeout(acTimeoutAdjustment)); return true; }; setTimeout("mainLoop()", 10); function escapeURI(toEncode) { if (escape) { return escape(toEncode); } if(encodeURIComponent) { return encodeURIComponent(toEncode); } return toEncode; } function isMSIE() { return (navigator && navigator.userAgent.toLowerCase().indexOf("msie") >= 0); } function displayOnFocus(dispField) { var f = document.forms[0]; var nameID = dispField.name.substring(3, dispField.name.length); acCurDisplayField = dispField; acCurIDField = f[nameID]; if (acCurIDField==null) { acCurIDField=document.getElementById(nameID); } acLastCompleteValues[acCurDisplayField.name] = acCurDisplayField.value; acLastCompleteValues[acCurIDField.name] = acCurIDField.value; acCurDisplayField.value = ''; acCurIDField.value = ''; acLastDisplayValues[acCurDisplayField.name] = ''; acCurrentDisplayValues[acCurDisplayField.name] = ''; } function displayOnFocusTwo(dispField,formIndex) { var f = document.forms[formIndex]; var nameID = dispField.name.substring(3, dispField.name.length); acCurDisplayField = dispField; acCurIDField = f[nameID]; if (acCurIDField==null) { acCurIDField=document.getElementById(nameID); } acCurDisplayField.value = ''; acCurIDField.value = ''; acLastDisplayValues[acCurDisplayField.name] = ''; acCurrentDisplayValues[acCurDisplayField.name] = ''; } function stripCRFromString(strToStrip){ var rtrn = ''; var crVal = "\n\r"; for(var cnt = 0; cnt < strToStrip.length; cnt++) { if (crVal.indexOf(strToStrip.charAt(cnt)) == -1) { rtrn += strToStrip.charAt(cnt); } else { rtrn += " "; } } return rtrn; } acOnMouseDown = function() { selectEntry(valueOfCAutoComplete(this), valueOfDAutoComplete(this)); hideFieldDiv(); }; function highlightNewValue(newValueIndex) { var resultDiv = acResultDivs[acCurDisplayField.name]; var numResults = acNumResults[acCurDisplayField.name]; if (!resultDiv || !numResults || !acCurSuggestionList) { return; } if(newValueIndex >= numResults){ newValueIndex = numResults - 1; } if(acCurHighlightedIndex != -1 && newValueIndex != acCurHighlightedIndex){ setStyleForElement(acCurHighlightedDiv,"aAutoComplete"); acCurHighlightedIndex = -1; } if(newValueIndex < 0){ acCurHighlightedIndex = -1; acCurDisplayField.focus(); return; } acCurHighlightedIndex = newValueIndex; acCurHighlightedDiv = acCurSuggestionList.item(newValueIndex); setStyleForElement(acCurHighlightedDiv,"bAutoComplete"); } // Just a bad hack: as all the Autocomplete stuff is based on the .name, and that for some reason we wish to be based on the id // instead => we just replace the name by the id. The correct value replacement will be done as usual // but at the end the doTriggerChangeFromAC will put back the correct name, stored in an arbitrary attribute function installFobACbasedOnID(displayFld) { var realElement=document.getElementById(displayFld.id.substr(3)); $(displayFld).attr("ed:realname",displayFld.name); $(realElement).attr("ed:realname",realElement.name); displayFld.name=displayFld.id; realElement.name=realElement.id; installFobAC(displayFld); }
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de