Javascript - examples
Jump to navigation
Jump to search
//------------------------------------------------------------------------------ // DBLookup section //------------------------------------------------------------------------------ var lookupOpened = false; //------------------------------------------------------------------------------ // !!!!!!!!!!! never call this procedure directly from your page !!!!!!!!!!!!! function DBLookup_popup( fieldHidden, fieldVisible, key, label, fields, nullable, multiple, pageSize, pageTitle, dataSourceType, dataSourceSpec, dataSourceParams, where, pageType, filtersDuplicatesBySQL) { var newWindowOptions; var newWindowTop; var openWindow; var winWidth, winHeight; var theForm; //var posX, posY; if (lookupOpened) { handle = window.open('','Lookup'); if (handle) // handle mac platform DOM window object behavior, #7300 if (!(handle.navigator && handle.navigator.platform && handle.navigator.platform.toUpperCase() == 'MACPPC')) handle.close(); } else lookupOpened = true; winWidth = 350; winHeight = 350; if (document.all) { // ****** Internet Explorer **** posX = event.screenX; posY = event.screenY; theForm = document.forms[0]; } else { // ****** Netscape *********** theForm = findFormForName(document, fieldHidden+'_Form'); if (theForm == null) { theForm = document.forms[0]; } if (navigator.vendorSub) { // Netscape 7 winWidth = 350; winHeight = 350; } else { winWidth = 525; winHeight = (multiple=="multiple") ? 610 : 450; } } eleX = posX; eleY = posY; if (theForm == null) { wbAlert(getLocalizedMessage_NO_FORM()); return; } // If the lookup is currently resolving, wait until complete. if (theForm.elements[fieldVisible].isResolving == true) { theForm.elements[fieldVisible].isLookupPending = true; return; } posX = posX + 20; posY = posY - (winHeight/2); if ((posX + winWidth) > window.screen.width) posX = eleX - winWidth - 100; if ((posY + winHeight) > window.screen.height) posY = posY - (posY + winHeight - window.screen.height)-32; if (posX < 0) posX = 0; if (posY < 0) posY = 0; var initialBlank = (theForm.elements[fieldHidden].getAttribute('initialBlank') ? theForm.elements[fieldHidden].getAttribute('initialBlank') : ''); // This string may exceed 2k. read this paramter directly from form by the opened window instead of passign it through. var resultSelected = ((multiple != 'multiple' && theForm.elements[fieldHidden].resultSelected) ? theForm.elements[fieldHidden].resultSelected : ''); var itemsCount = (theForm.elements[fieldHidden].itemsCount?theForm.elements[fieldHidden].itemsCount:''); var addwhere = (theForm.elements[fieldHidden].addwhere?theForm.elements[fieldHidden].addwhere:''); openWindow = contextPath + "/system/ui/DBLookupUI_" + multiple + ".jsp" + "?fieldHidden=" + fieldHidden + "&fieldVisible=" + fieldVisible + "&key=" + key + "&label=" + label + "&fields=" + fields + "&nullable=" + nullable + "&pageSize=" + pageSize + "&pageTitle=" + pageTitle + "&posX=" + posX + "&posY=" + posY + "&dataSourceType=" + dataSourceType + "&dataSourceSpec=" +escape(dataSourceSpec) + (resultSelected == '' ? '':"&resultSelected=" + resultSelected) + (initialBlank == '' ? '':"&initialBlank=" + initialBlank) + (itemsCount == ''? '':"&itemsCount=" + itemsCount) + (where == ''? '':"&where=" + escape(where)) + (addwhere == ''? '':"&addwhere=" + escape(addwhere)) + (pageType == '' ? '': "&pageType=" + pageType) + "&filtersDuplicatesBySQL=" + filtersDuplicatesBySQL + "&dataSourceParams=" + escape(dataSourceParams); newWindowOptions = "width=" + winWidth + ",height=" + winHeight + ",innerWidth=" + winWidth + ",innerHeight=" + winHeight + ",alwaysRaised=1,resizable=YES,screenX="+posX+",screenY="+posY+",left="+posX+",top="+posY+",scrollbars=1"; window.open(openWindow, "Lookup", newWindowOptions ).focus(); } //------------------------------------------------------------------------------ // A wrapper for customized calls function performDBLookup(fieldHidden, fieldVisible, key, label, fields, multiple, pageSize, pageTitle, dataSourceType, dataSourceSpec){ DBLookup_popup(fieldHidden, fieldVisible, key, label, fields, true, multiple, (pageSize==0?12:pageSize), pageTitle, dataSourceType, dataSourceSpec, "", "", "", "false"); } //------------------------------------------------------------------------------ resolveWindowsCount = 0; //------------------------------------------------------------------------------ function DBLookup_resolveLabels(fieldHidden, fieldVisible, key, label, selectedLabels, dataSourceType, dataSourceSpec, dataSourceParams, where, multiple, filtersDuplicatesBySQL) { resolveLabels(fieldHidden, fieldVisible, key, label, selectedLabels, dataSourceType, dataSourceSpec, dataSourceParams, where, multiple, 'DB', filtersDuplicatesBySQL); } //------------------------------------------------------------------------------ function MessagingLookup_resolveLabels(fieldHidden, fieldVisible, key, label, selectedLabels, dataSourceType, dataSourceSpec, where) { resolveLabels(fieldHidden, fieldVisible, key, label, selectedLabels, dataSourceType, dataSourceSpec, "", where, 'true', 'Messaging', false); } //------------------------------------------------------------------------------ function resolveLabels(fieldHidden, fieldVisible, key, label, selectedLabels, dataSourceType, dataSourceSpec, dataSourceParams, where, multiple, ui, filtersDuplicatesBySQL) { var newWindowOptions; var newWindowTop; var openWindow; var winWidth, winHeight; winWidth = 50; winHeight = 10; // **** Had to remove event.screenX // **** Because we switched to <iframe> for Internet Explorer // **** akaspersky **** posX = 200; posY = 200; if (document.all) { // ****** Internet Explorer **** theForm = document.forms[0]; } else { // ****** Netscape *********** theForm = findFormForName(document, fieldHidden+'_Form'); if (theForm == null) { theForm = document.forms[0]; } } if (theForm == null) { wbAlert(getLocalizedMessage_NO_FORM()); return; } var addwhere = (theForm.elements[fieldHidden].addwhere?theForm.elements[fieldHidden].addwhere:''); openWindow = contextPath + "/system/ui/" + ui + "LookupUIResolve.jsp?" + "&fieldHidden=" + fieldHidden + "&fieldVisible=" + fieldVisible + "&key=" + key + "&label=" + label + "&selectedLabels=" + escape(selectedLabels) + "&dataSourceType=" + dataSourceType + "&dataSourceSpec=" + escape(dataSourceSpec) + (where == ''? '':"&where=" + (ui=='DB' ? escape(where) : where)) + (addwhere == ''? '':"&addwhere=" + escape(addwhere)) + "&multiple=" + multiple + "&filtersDuplicatesBySQL=" + filtersDuplicatesBySQL + "&dataSourceParams=" + escape(dataSourceParams); newWindowOptions = "width=" + winWidth + ",height=" + winHeight + ",screenX="+posX+ ",screenY="+posY+ ",left="+posX+ ",top="+posY+ ",innerWidth=" + winWidth + ",innerHeight=" + winHeight + ",alwaysRaised=1,locationbar=0,statusbar=0,resizable=NO"; if (document.all) { // **** For IE we are using iFrame var frameName = 'if' + fieldHidden; document.all[frameName].src = openWindow; } else { // *** For Netscape Window is Fine window.open(openWindow, "resolveWindow_" + (resolveWindowsCount++), newWindowOptions).focus(); } } //------------------------------------------------------------------------------ var wbAlertWindow; // stores alert window parameters for NN function wbAlert(message) { var newWindowOptions; var newWindowTop; var openWindow; var winWidth, winHeight; winWidth = 200; winHeight = 10; var posX = 200; var posY = 200; openWindow= message; newWindowOptions = "width=" + winWidth + ",height=" + winHeight + ",innerWidth=" + winWidth + ",innerHeight=" + winHeight + ",alwaysRaised=0,locationbar=0,statusbar=0,resizable=NO"; if (document.all) { // **** For IE we are using iFrame alert(message); } else { // *** For Netscape Window is Fine if (!wbAlertWindow) { w = window.open("","Alert",newWindowOptions ); w.document.open(); w.document.write("<script>"); w.document.write("</script>"); w.document.write("<body onBlur='window.close();' onUnload='window.opener.wbAlertWindow = null;'>"); w.document.write("<form>"); w.document.write("<p>" + message + "</p>"); w.document.write("</form>"); w.document.write("</body>"); w.document.close(); w.focus(); } } } //------------------------------------------------------------------------------ // *** Sets the values in a DBLookup based on the default values provided **** function setDBLookup(controlName, defaultID, defaultName) { var form1, form2; form1 = getFormForName(controlName+"_Form"); form2 = getFormForName(controlName+"_Hidden_Form"); if (form1 == null || form2 == null) { alert(getLocalizedMessage_NO_FORM()); return; } setElementValue(form1.name, controlName, defaultID); setElementValue(form1.name, controlName+"_label", defaultName); setElementValue(form2.name, controlName+"_ID", defaultID); setElementValue(form2.name, controlName+"_NAME", defaultName); } //------------------------------------------------------------------------------ // *** Sets the values in a DBDropdown based on the default values provided **** function setDBDropdown(controlName, defaultID, defaultName) { var form1, form2, theDropdown, theValue; form1 = getFormForName(controlName+"_Form"); form2 = getFormForName(controlName+"_Hidden_Form"); if (form1 == null || form2 == null) { wbAlert(getLocalizedMessage_NO_FORM()); return; } setElementValue(form2.name, controlName+"_ID", defaultID); setElementValue(form2.name, controlName+"_NAME", defaultName); theDropdown = findElementForName(form1.name, controlName); theValue = defaultID+"!*!"+defaultName; if (theDropdown!=null && theDropdown.type.indexOf('select')==0) { for (i=0;i<theDropdown.options.length;i++) { if (theDropdown.options[i].value == theValue) { theDropdown.options[i].selected = true; return; } } theDropdown.options[theDropdown.options.length] = new Option(defaultName, theValue); theDropdown.options[theDropdown.options.length-1].selected = true; } } //------------------------------------------------------------------------------ function getDocument() { return document; } //------------------------------------------------------------------------------ function getFormForName(formName) { if (document.all) { // ****** Internet Explorer **** theForm = document.forms[0]; } else { // ****** Netscape *********** theForm = findFormForName(document, formName); if (theForm == null) { theForm = document.forms[0]; } } return theForm; } //------------------------------------------------------------------------------