|
Author: jleroux
Date: Sun Jan 31 00:09:53 2010 New Revision: 904922 URL: http://svn.apache.org/viewvc?rev=904922&view=rev Log: Fix an issue when using the layer lookup with a fieldLookup3 style lookup (ie a lookup which shows name but uses and Id underneath). This last fix allow to use the layer lookup in any cases already covert by OFBiz Modified: ofbiz/trunk/framework/images/webapp/images/fieldlookup.js ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Modified: ofbiz/trunk/framework/images/webapp/images/fieldlookup.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/fieldlookup.js?rev=904922&r1=904921&r2=904922&view=diff ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/fieldlookup.js (original) +++ ofbiz/trunk/framework/images/webapp/images/fieldlookup.js Sun Jan 31 00:09:53 2010 @@ -1,66 +1,80 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ // ================= FIELD LOOKUP METHODS ============================ -var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false; -var IE4 = (document.all && !document.getElementById)? true : false; -var IE5 = (document.getElementById && document.all)? true : false; -var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false; +var NS4 = (navigator.appName.indexOf("Netscape") >= 0 && ! document.getElementById)? true: false; +var IE4 = (document.all && ! document.getElementById)? true: false; +var IE5 = (document.getElementById && document.all)? true: false; +var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape") >= 0)? true: false; var mx, my; var CURRENT_LOOKUP = null; function moveobj(evt) { if (NS4 || NS6) { - mx=evt.screenX; - my=evt.screenY; + mx = evt.screenX; + my = evt.screenY; } else if (IE5 || IE4) { - mx=event.screenX; - my=event.screenY; + mx = event.screenX; + my = event.screenY; } } var target = null; var target2 = null; -var lookups = []; +var lookups =[]; -function call_fieldlookup(target, viewName, formName,viewWidth,viewheight) { +function call_fieldlookup(target, viewName, formName, viewWidth, viewheight) { var fieldLookup = new fieldLookup1(target); if (! viewWidth) viewWidth = 350; if (! viewheight) viewheight = 200; fieldLookup.popup(viewName, formName, viewWidth, viewheight); } function call_fieldlookupLayer(target, viewName, lookupWidth, lookupHeight, lookupPosition) { - if(CURRENT_LOOKUP != null){ - if(CURRENT_LOOKUP.parentTarget == target){ + if (CURRENT_LOOKUP != null) { + if (CURRENT_LOOKUP.parentTarget == target) { CURRENT_LOOKUP.closeLookup(); return; } } - var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition); fieldLookupPopup.showLookup(); this.target = target; } + +function call_fieldlookupLayer3(target, target2, viewName, lookupWidth, lookupHeight, lookupPosition) { + if (CURRENT_LOOKUP != null) { + if (CURRENT_LOOKUP.parentTarget == target) { + CURRENT_LOOKUP.closeLookup(); + return; + } + } + var fieldLookupPopup2 = new FieldLookupPopup2(target, target2, viewName, lookupWidth, lookupHeight, lookupPosition); + fieldLookupPopup2.showLookup(); + this.target = target; + this.target2 = target2; +} + function call_fieldlookup2(target, viewName) { var fieldLookup = new fieldLookup1(target, arguments); fieldLookup.popup2(viewName); } + function call_fieldlookup3(target, target2, viewName) { var fieldLookup = new fieldLookup2(target, target2); fieldLookup.popup2(viewName); @@ -71,53 +85,53 @@ // passing methods this.popup = lookup_popup1; this.popup2 = lookup_popup2; - + // validate input parameters - if (!obj_target) - return lookup_error("Error calling the field lookup: no target control specified"); + if (! obj_target) + return lookup_error("Error calling the field lookup: no target control specified"); if (obj_target.value == null) - return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); + return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); //this.target = obj_target; target = obj_target; - + // register in global collections //this.id = lookups.length; //lookups[this.id] = this; } function fieldLookup2(obj_target, obj_target2) { // passing methods - this.popup = lookup_popup1; - this.popup2 = lookup_popup2; + this.popup = lookup_popup1; + this.popup2 = lookup_popup2; // validate input parameters - if (!obj_target) - return lookup_error("Error calling the field lookup: no target control specified"); + if (! obj_target) + return lookup_error("Error calling the field lookup: no target control specified"); if (obj_target.value == null) - return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); + return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); target = obj_target; // validate input parameters - if (!obj_target2) - return lookup_error("Error calling the field lookup: no target2 control specified"); + if (! obj_target2) + return lookup_error("Error calling the field lookup: no target2 control specified"); if (obj_target2.value == null) - return lookup_error("Error calling the field lookup: parameter specified is not valid target2 control"); + return lookup_error("Error calling the field lookup: parameter specified is not valid target2 control"); target2 = obj_target2; - - + + // register in global collections //this.id = lookups.length; //lookups[this.id] = this; } -function lookup_popup1 (view_name, form_name, viewWidth, viewheight) { - var obj_lookupwindow = window.open(view_name + '?formName=' + form_name + '&id=' + this.id,'_blank', 'width='+viewWidth+',height='+viewheight+',scrollbars=yes,status=no,resizable=yes,top='+my+',left='+mx+',dependent=yes,alwaysRaised=yes'); +function lookup_popup1(view_name, form_name, viewWidth, viewheight) { + var obj_lookupwindow = window.open(view_name + '?formName=' + form_name + '&id=' + this.id, '_blank', 'width=' + viewWidth + ',height=' + viewheight + ',scrollbars=yes,status=no,resizable=yes,top=' + my + ',left=' + mx + ',dependent=yes,alwaysRaised=yes'); obj_lookupwindow.opener = window; obj_lookupwindow.focus(); } -function lookup_popup2 (view_name) { +function lookup_popup2(view_name) { var argString = ""; if (this.args != null) { if (this.args.length > 2) { - for(var i=2; i < this.args.length; i++) { - argString += "&parm" + (i-2) + "=" + this.args[i]; + for (var i = 2; i < this.args.length; i++) { + argString += "&parm" + (i - 2) + "=" + this.args[i]; } } } @@ -125,418 +139,614 @@ if (view_name.indexOf("?") >= 0) { sep = "&"; } - var obj_lookupwindow = window.open(view_name + sep + 'id=' + this.id + argString,'_blank', 'width=700,height=550,scrollbars=yes,status=no,resizable=yes,top='+my+',left='+mx+',dependent=yes,alwaysRaised=yes'); + var obj_lookupwindow = window.open(view_name + sep + 'id=' + this.id + argString, '_blank', 'width=700,height=550,scrollbars=yes,status=no,resizable=yes,top=' + my + ',left=' + mx + ',dependent=yes,alwaysRaised=yes'); obj_lookupwindow.opener = window; obj_lookupwindow.focus(); } -function lookup_error (str_message) { - alert (str_message); +function lookup_error(str_message) { + alert(str_message); return null; } /************************************* - * Fieldlookup Class & Methods - *************************************/ +* Fieldlookup Class & Methods +*************************************/ //init KeyListener -window.onload=function(){ +window.onload = function () { //Observe Event.observe(document, "keypress", key_event); } //if ESC is pressed, remove draged portlet + hoverDiv -function key_event(evt) -{ - if(evt.keyCode == 27) { +function key_event(evt) { + if (evt.keyCode == 27) { //removes the hover div after the portlet is moved to another position - if(CURRENT_LOOKUP != null){ + if (CURRENT_LOOKUP != null) { lookupHide(); } } } /** - * Class to create a lookup layer - * target - target where the value should be passed - * viewName - view name which will be opened - * lookupWidth - layer width i.e. 500px, 27% ... [default: 700px] - * lookupHeight - layer height i.e. 500px, 27% ... [default: 550px] - * position - normal (under the target field), center (layer is centered) [default: normal] -- !work still in process - */ +* Class to create a lookup layer +* target - target where the value should be passed +* viewName - view name which will be opened +* lookupWidth - layer width i.e. 500px, 27% ... [default: 700px] +* lookupHeight - layer height i.e. 500px, 27% ... [default: 550px] +* position - normal (under the target field), center (layer is centered) [default: normal] -- !work still in process +*/ var FieldLookupPopup = Class.create({ - initialize: function(target, viewName, lookupWidth, lookupHeight, position){ - if(isEmpty(target) || isEmpty(viewName)){ - return lookup_error("Lookup can't created, variabels missing"); + initialize: function (target, viewName, lookupWidth, lookupHeight, position) { + if (isEmpty(target) || isEmpty(viewName)) { + return lookup_error("Lookup can't be created, variables missing"); } - + //removes a existing Lookup - if(CURRENT_LOOKUP != null){ + if (CURRENT_LOOKUP != null) { CURRENT_LOOKUP.removeLayer(); } - - - if(isEmpty(lookupWidth)){ + + + if (isEmpty(lookupWidth)) { lookupWidth = '700px'; } this.lookupWidth = lookupWidth; - - if(isEmpty(lookupHeight)){ + + if (isEmpty(lookupHeight)) { lookupHeight = '550px'; } this.lookupHeight = lookupHeight; - + this.parentTarget = target; this.viewName = viewName; this.position = position; - + this.createElement(); CURRENT_LOOKUP = this; }, - - showLookup: function(){ - if($('fieldLookup') != null){ - Effect.Appear('fieldLookup',{duration: 0.3}); + + showLookup: function () { + if ($('fieldLookup') != null) { + Effect.Appear('fieldLookup', {duration: 0.3}); } }, - - closeLookup: function(){ - if($('fieldLookup') != null){ - Effect.Fade('fieldLookup',{duration: 0.3}); + + closeLookup: function () { + if ($('fieldLookup') != null) { + Effect.Fade('fieldLookup', {duration: 0.3}); } // removes the layer after fading window.setTimeout('CURRENT_LOOKUP.removeLayer()', 400); - - }, - - createElement: function(){ + + createElement: function () { var parent = this.parentTarget; + + //creates the lookup dom element + var lookupDiv = new Element('DIV', { + id: "fieldLookup", + style: "width: " + this.lookupWidth + "; height: " + this.lookupHeight + "" + }); + lookupDiv.setAttribute("class", "fieldLookup"); + lookupDiv.setAttribute("className", "fieldLookup"); + //IE7 Hack + + //creates lookupHeader + var headerDiv = new Element('DIV', { + id: "fieldLookupHeader" + }); + headerDiv.setAttribute("class", "fieldLookupHeader"); + headerDiv.setAttribute("className", "fieldLookupHeader"); + // IE 7 Hack + + //create close Button + var closeButton = new Element('SPAN', { + }); + var closeButtonImg = new Element('DIV', { + onClick: "lookupHide()" + }); + closeButtonImg.onclick = function () { + lookupHide(); + }; + + closeButton.appendChild(closeButtonImg); + headerDiv.appendChild(closeButton); + lookupDiv.appendChild(headerDiv); + + //get the lookup from an anjax request + this.loadContent(lookupDiv); + + lookupDiv.style.display = "none"; + //creates the div as child of the form element (parent --> input field; parentNode --> form) + var pn = parent.parentNode; + + //set layer position + var bdy = document.body; + if (this.position == "center") { + bdy.appendChild(lookupDiv); + var dimensions = lookupDiv.getDimensions(); + lookupLeft = (bdy.offsetWidth / 2) - (dimensions.width / 2); + lookupTop = ((bdy.offsetHeight / 2) - (dimensions.height / 2)) + window.pageYOffset; + lookupDiv.style.left = lookupLeft + "px"; + lookupDiv.style.top = lookupTop + "px"; + } else if (this.position == "right") { + bdy.appendChild(lookupDiv); + var dimensions = lookupDiv.getDimensions(); + lookupLeft = (bdy.offsetWidth) - (dimensions.width + 5); + lookupTop = (bdy.offsetHeight / 2) - (dimensions.height / 2); + lookupDiv.style.left = lookupLeft + "px"; + lookupDiv.style.top = lookupTop + "px"; + } else if (this.position == "left") { + bdy.appendChild(lookupDiv); + var dimensions = lookupDiv.getDimensions(); + lookupLeft = 5; + lookupTop = (bdy.offsetHeight / 2) - (dimensions.height / 2); + lookupDiv.style.left = lookupLeft + "px"; + lookupDiv.style.top = lookupTop + "px"; + } else if (this.position == "topright") { + bdy.appendChild(lookupDiv); + var dimensions = lookupDiv.getDimensions(); + lookupLeft = (bdy.offsetWidth) - (dimensions.width + 5); + lookupTop = 5; + lookupDiv.style.left = lookupLeft + "px"; + lookupDiv.style.top = lookupTop + "px"; + } else if (this.position == "topleft") { + bdy.appendChild(lookupDiv); + var dimensions = lookupDiv.getDimensions(); + lookupLeft = 5; + lookupTop = 5; + lookupDiv.style.left = lookupLeft + "px"; + lookupDiv.style.top = lookupTop + "px"; + } else { + //for 'normal', empty etc. + if (pn != null) { + // IE Fix + pn.appendChild(lookupDiv); + } + } + this.divRef = lookupDiv; + + //make layer draggable + this.makeDraggable(lookupDiv); + + //make the window resiable + this.makeResizeable(lookupDiv); + }, + + loadContent: function (lookupDiv) { + new Ajax.Request(this.viewName, { + onSuccess: function (transport) { + var lookupContent = transport.responseText; + lookupDiv.insert({ + bottom: "<div id='fieldLookupContent'>" + lookupContent + "</div>" + }); + modifySubmitButton(); + } + }); + }, + + makeDraggable: function (lookupDiv) { + this.loopupDrag = new Draggable(lookupDiv, { + handle: 'fieldLookupHeader', revert: false, ghosting: false + }); + }, + + makeResizeable: function (lookupDiv) { + new Resizeable(lookupDiv, { + top: 0, + left: 50, + resize: function (el) { + $('fieldLookupContent').setStyle({ + width: "100%", + height: "90%" + }); + } + }); + }, + + removeLayer: function () { + this.loopupDrag.destroy(); + Element.stopObserving(document, "keypress"); + CURRENT_LOOKUP.divRef.parentNode.removeChild(CURRENT_LOOKUP.divRef); + CURRENT_LOOKUP = null; + this.target = null; + } +}); +/** +* Class to create a lookup layer +* target - target where the 1st value should be passed +* target2 - target2 where the 2d value should be passed +* viewName - view name which will be opened +* lookupWidth - layer width i.e. 500px, 27% ... [default: 700px] +* lookupHeight - layer height i.e. 500px, 27% ... [default: 550px] +* position - normal (under the target field), center (layer is centered) [default: normal] -- !work still in process +*/ +var FieldLookupPopup2 = Class.create({ + initialize: function (target, target2, viewName, lookupWidth, lookupHeight, position) { + if (isEmpty(target) || isEmpty(target2) || isEmpty(viewName)) { + return lookup_error("Lookup can't be created, variables missing"); + } + + //removes a existing Lookup + if (CURRENT_LOOKUP != null) { + CURRENT_LOOKUP.removeLayer(); + } + + + if (isEmpty(lookupWidth)) { + lookupWidth = '700px'; + } + this.lookupWidth = lookupWidth; + + if (isEmpty(lookupHeight)) { + lookupHeight = '550px'; + } + this.lookupHeight = lookupHeight; + + this.parentTarget = target; + this.parentTarget2 = target2; + this.viewName = viewName; + this.position = position; + + this.createElement(); + CURRENT_LOOKUP = this; + }, + + showLookup: function () { + if ($('fieldLookup') != null) { + Effect.Appear('fieldLookup', {duration: 0.3}); + } + }, + + closeLookup: function () { + if ($('fieldLookup') != null) { + Effect.Fade('fieldLookup', {duration: 0.3}); + } + // removes the layer after fading + window.setTimeout('CURRENT_LOOKUP.removeLayer()', 400); + }, + + createElement: function () { + var parent = this.parentTarget; + var parent2 = this.parentTarget2; + //creates the lookup dom element var lookupDiv = new Element('DIV', { id: "fieldLookup", style: "width: " + this.lookupWidth + "; height: " + this.lookupHeight + "" - }); + }); lookupDiv.setAttribute("class", "fieldLookup"); lookupDiv.setAttribute("className", "fieldLookup"); //IE7 Hack - + //creates lookupHeader var headerDiv = new Element('DIV', { id: "fieldLookupHeader" - }); + }); headerDiv.setAttribute("class", "fieldLookupHeader"); headerDiv.setAttribute("className", "fieldLookupHeader"); // IE 7 Hack - + //create close Button var closeButton = new Element('SPAN', {}); var closeButtonImg = new Element('DIV', { onClick: "lookupHide()" - }); - closeButtonImg.onclick = function(){ lookupHide(); }; - + }); + closeButtonImg.onclick = function () { + lookupHide(); + }; + closeButton.appendChild(closeButtonImg); headerDiv.appendChild(closeButton); lookupDiv.appendChild(headerDiv); - + //get the lookup from an anjax request this.loadContent(lookupDiv); - + lookupDiv.style.display = "none"; //creates the div as child of the form element (parent --> input field; parentNode --> form) var pn = parent.parentNode; - + //set layer position var bdy = document.body; - if(this.position == "center"){ + if (this.position == "center") { bdy.appendChild(lookupDiv); var dimensions = lookupDiv.getDimensions(); - lookupLeft = (bdy.offsetWidth/2) - (dimensions.width/2); - lookupTop = ((bdy.offsetHeight/2) - (dimensions.height/2)) + window.pageYOffset; + lookupLeft = (bdy.offsetWidth / 2) - (dimensions.width / 2); + lookupTop = ((bdy.offsetHeight / 2) - (dimensions.height / 2)) + window.pageYOffset; lookupDiv.style.left = lookupLeft + "px"; lookupDiv.style.top = lookupTop + "px"; - - }else if(this.position == "right"){ + } else if (this.position == "right") { bdy.appendChild(lookupDiv); var dimensions = lookupDiv.getDimensions(); lookupLeft = (bdy.offsetWidth) - (dimensions.width + 5); - lookupTop = (bdy.offsetHeight/2) - (dimensions.height/2); + lookupTop = (bdy.offsetHeight / 2) - (dimensions.height / 2); lookupDiv.style.left = lookupLeft + "px"; lookupDiv.style.top = lookupTop + "px"; - - }else if(this.position == "left"){ + } else if (this.position == "left") { bdy.appendChild(lookupDiv); var dimensions = lookupDiv.getDimensions(); lookupLeft = 5; - lookupTop = (bdy.offsetHeight/2) - (dimensions.height/2); + lookupTop = (bdy.offsetHeight / 2) - (dimensions.height / 2); lookupDiv.style.left = lookupLeft + "px"; lookupDiv.style.top = lookupTop + "px"; - - }else if(this.position == "topright"){ + } else if (this.position == "topright") { bdy.appendChild(lookupDiv); var dimensions = lookupDiv.getDimensions(); lookupLeft = (bdy.offsetWidth) - (dimensions.width + 5); lookupTop = 5; lookupDiv.style.left = lookupLeft + "px"; lookupDiv.style.top = lookupTop + "px"; - - }else if(this.position == "topleft"){ + } else if (this.position == "topleft") { bdy.appendChild(lookupDiv); var dimensions = lookupDiv.getDimensions(); lookupLeft = 5; lookupTop = 5; lookupDiv.style.left = lookupLeft + "px"; lookupDiv.style.top = lookupTop + "px"; - - }else{ + } else { //for 'normal', empty etc. if(pn != null){ // IE Fix pn.appendChild(lookupDiv); } } this.divRef = lookupDiv; - + //make layer draggable this.makeDraggable(lookupDiv); - + //make the window resiable this.makeResizeable(lookupDiv); - }, - - loadContent: function(lookupDiv){ - new Ajax.Request(this.viewName,{ - onSuccess: function(transport){ + + loadContent: function (lookupDiv) { + new Ajax.Request(this.viewName, { + onSuccess: function (transport) { var lookupContent = transport.responseText; lookupDiv.insert({bottom: "<div id='fieldLookupContent'>" + lookupContent + "</div>"}); modifySubmitButton(); } }); }, - - makeDraggable: function(lookupDiv){ - this.loopupDrag = new Draggable(lookupDiv, - {handle: 'fieldLookupHeader',revert: false, ghosting: false} - ); + + makeDraggable: function (lookupDiv) { + this.loopupDrag = new Draggable(lookupDiv, { + handle: 'fieldLookupHeader', revert: false, ghosting: false + }); }, - - makeResizeable: function(lookupDiv){ - new Resizeable(lookupDiv, - {top: 0, - left: 50, - resize: function(el){ - $('fieldLookupContent').setStyle({ - width: "100%", - height: "90%" - }); - } - }); + + makeResizeable: function (lookupDiv) { + new Resizeable(lookupDiv, { + top: 0, + left: 50, + resize: function (el) { + $('fieldLookupContent').setStyle({ + width: "100%", + height: "90%" + }); + } + }); }, - - removeLayer: function(){ - this.loopupDrag.destroy(); - Element.stopObserving(document, "keypress"); - CURRENT_LOOKUP.divRef.parentNode.removeChild(CURRENT_LOOKUP.divRef); - CURRENT_LOOKUP = null; - this.target = null; + + removeLayer: function () { + this.loopupDrag.destroy(); + Element.stopObserving(document, "keypress"); + CURRENT_LOOKUP.divRef.parentNode.removeChild(CURRENT_LOOKUP.divRef); + CURRENT_LOOKUP = null; + this.target = null; + this.target2 = null; } - }); -function lookupHide(){ - if(CURRENT_LOOKUP != null){ +function lookupHide() { + if (CURRENT_LOOKUP != null) { CURRENT_LOOKUP.closeLookup(); } } /** - * returns true if a Stirng is empty - * @param value - String value - * @return - */ -function isEmpty(value){ - if(value == null || value == ""){ +* returns true if a Stirng is empty +* @param value - String value +* @return +*/ +function isEmpty(value) { + if (value == null || value == "") { return true; } return false; } /** - * Modify the Submit Button for the new lookup layer - * @return - */ -function modifySubmitButton(){ +* Modify the Submit Button for the new lookup layer +* @return +*/ +function modifySubmitButton() { /* changes form/submit behavior for Lookup Layer */ - if($('fieldLookup')) { - //find the lookup form - var forms = $('fieldLookup').getElementsByTagName('form'); - for(var i =0; i<forms.length; i++){ - if(!isEmpty(forms[i].getAttribute('id'))){ - var lookupForm = $(forms[i].getAttribute('id')); - } - } - - //diable the form action - var formAction = lookupForm.getAttribute('action'); - lookupForm.setAttribute('action',''); - - //modify the form submit button - for (var i=0;i<lookupForm.length;i++) { - var ele = lookupForm.elements[i]; - if ((ele.getAttribute('type')) == "submit") { - ele.style.display = "none"; - var txt = ele.value; - var submit = new Element('A',{ - - }); - submit.onclick = function(){ - lookupFormAjaxRequest(formAction, lookupForm.getAttribute('id'));return false; - }; - submit.setAttribute("class", "smallSubmit"); + if ($('fieldLookup')) { + //find the lookup form + var forms = $('fieldLookup').getElementsByTagName('form'); + for (var i = 0; i < forms.length; i++) { + if (! isEmpty(forms[i].getAttribute('id'))) { + var lookupForm = $(forms[i].getAttribute('id')); + } + } + + //diable the form action + var formAction = lookupForm.getAttribute('action'); + lookupForm.setAttribute('action', ''); + + //modify the form submit button + for (var i = 0; i < lookupForm.length; i++) { + var ele = lookupForm.elements[i]; + if ((ele.getAttribute('type')) == "submit") { + ele.style.display = "none"; + var txt = ele.value; + var submit = new Element('A', { + }); + submit.onclick = function () { + lookupFormAjaxRequest(formAction, lookupForm.getAttribute('id')); + return false; + }; + submit.setAttribute("class", "smallSubmit"); submit.setAttribute("className", "smallSubmit"); // IE 7 Hack - submit.href = ""; - - var textNode = document.createTextNode(txt); - submit.appendChild(textNode); - ele.parentNode.appendChild(submit); - Event.observe(document, "keypress", function(evt){if(Event.KEY_RETURN == evt.keyCode){lookupFormAjaxRequest(formAction, lookupForm.getAttribute('id'));}}); - ele.parentNode.removeChild(ele); - //modifay nav-pager - var navPager = $('fieldLookup').getElementsByClassName("nav-pager"); - if(navPager.length > 0){ - - for (var j=0;j<navPager.length;j++) { - var eleChild = navPager[j].getElementsByTagName("ul")[0].getElementsByTagName("li"); - for (var k=0;k<eleChild.length;k++) { - var link = eleChild[k].getElementsByTagName("A"); - var select = eleChild[k].getElementsByTagName("SELECT"); - - if(link.length > 0){ - link[0].href = "javascript:lookupPaginationAjaxRequest('" + link[0].href + "', '" + lookupForm.getAttribute('id') + "', 'link')"; - }else if(select.length > 0){ - try{ - var oc = select[0].getAttribute("onchange"); + submit.href = ""; + + var textNode = document.createTextNode(txt); + submit.appendChild(textNode); + ele.parentNode.appendChild(submit); + Event.observe(document, "keypress", function (evt) { + if (Event.KEY_RETURN == evt.keyCode) { + lookupFormAjaxRequest(formAction, lookupForm.getAttribute('id')); + } + }); + ele.parentNode.removeChild(ele); + //modifay nav-pager + var navPager = $('fieldLookup').getElementsByClassName("nav-pager"); + if (navPager.length > 0) { + + for (var j = 0; j < navPager.length; j++) { + var eleChild = navPager[j].getElementsByTagName("ul")[0].getElementsByTagName("li"); + for (var k = 0; k < eleChild.length; k++) { + var link = eleChild[k].getElementsByTagName("A"); + var select = eleChild[k].getElementsByTagName("SELECT"); + + if (link.length > 0) { + link[0].href = "javascript:lookupPaginationAjaxRequest('" + link[0].href + "', '" + lookupForm.getAttribute('id') + "', 'link')"; + } else if (select.length > 0) { + try { + var oc = select[0].getAttribute("onchange"); if((typeof oc) == "function"){ // IE6/7 Fix - oc = oc.toString(); - var ocSub = oc.substring((oc.indexOf('=')+2),(oc.length - 4)); - var searchPattern = /'\+this.value\+'/g; - var searchPattern2 = /'\+this.valu/g; - - if(searchPattern.test(ocSub)){ - var viewSize = select[0].value; - var spl = ocSub.split(searchPattern); - select[0].onchange = function(){lookupPaginationAjaxRequest(spl[0] + this.value + spl[1], lookupForm.getAttribute('id'), 'select');}; - }else if(searchPattern2.test(ocSub)){ - ocSub = ocSub.replace(searchPattern2, ""); - if(searchPattern.test(ocSub)){ - ocSub.replace(searchPattern, viewSize); - } - select[0].onchange = function(){lookupPaginationAjaxRequest(ocSub + this.value, lookupForm.getAttribute('id'), 'select');}; - } - }else{ - var ocSub = oc.substring((oc.indexOf('=')+1),(oc.length - 1)); - select[0].setAttribute("onchange", "lookupPaginationAjaxRequest(" + ocSub + ", '" + lookupForm.getAttribute('id') + "')"); - } - }catch(ex){} - } - } - } - - } - + oc = oc.toString(); + var ocSub = oc.substring((oc.indexOf('=') + 2),(oc.length - 4)); + var searchPattern = /'\+this.value\+'/g; + var searchPattern2 = /'\+this.valu/g; + + if (searchPattern.test(ocSub)) { + var viewSize = select[0].value; + var spl = ocSub.split(searchPattern); + select[0].onchange = function () { + lookupPaginationAjaxRequest(spl[0] + this.value + spl[1], lookupForm.getAttribute('id'), 'select'); + }; + } else if (searchPattern2.test(ocSub)) { + ocSub = ocSub.replace(searchPattern2, ""); + if (searchPattern.test(ocSub)) { + ocSub.replace(searchPattern, viewSize); + } + select[0].onchange = function () { + lookupPaginationAjaxRequest(ocSub + this.value, lookupForm.getAttribute('id'), 'select'); + }; + } + } else { + var ocSub = oc.substring((oc.indexOf('=') + 1),(oc.length - 1)); + select[0].setAttribute("onchange", "lookupPaginationAjaxRequest(" + ocSub + ", '" + lookupForm.getAttribute('id') + "')"); + } + } + catch (ex) { + } + } + } + } + } } } } } /** - * Create an ajax request to get the search results - * @param formAction - action target - * @param form - formId - * @return - */ -function lookupFormAjaxRequest(formAction, form){ - new Ajax.Request(formAction,{ +* Create an ajax request to get the search results +* @param formAction - action target +* @param form - formId +* @return +*/ +function lookupFormAjaxRequest(formAction, form) { + new Ajax.Request(formAction, { method: 'post', - parameters: $(form).serialize(), requestHeaders: {Accept: 'application/json'}, - onSuccess: function(transport){ + parameters: $(form).serialize(), requestHeaders: { + Accept: 'application/json' + }, + onSuccess: function (transport) { var formRequest = transport.responseText; $('fieldLookupContent').remove(); - $('fieldLookup').insert({bottom: "<div id='fieldLookupContent'>" + formRequest + "</div>"}); + $('fieldLookup').insert({ + bottom: "<div id='fieldLookupContent'>" + formRequest + "</div>" + }); modifySubmitButton(); } }); } -function lookupPaginationAjaxRequest(navAction, form, type){ - if(type == 'link'){ - navAction = navAction.substring(0, navAction.length-1); +function lookupPaginationAjaxRequest(navAction, form, type) { + if (type == 'link') { + navAction = navAction.substring(0, navAction.length - 1); } - new Ajax.Request(navAction,{ + new Ajax.Request(navAction, { method: 'get', - requestHeaders: {Accept: 'application/json'}, - onSuccess: function(transport){ + requestHeaders: { + Accept: 'application/json' + }, + onSuccess: function (transport) { var formRequest = transport.responseText; $('fieldLookupContent').remove(); - $('fieldLookup').insert({bottom: "<div id='fieldLookupContent'>" + formRequest + "</div>"}); + $('fieldLookup').insert({ + bottom: "<div id='fieldLookupContent'>" + formRequest + "</div>" + }); modifySubmitButton(); } }); } /******************************************************************************************************* - * This code inserts the value lookedup by a popup window back into the associated form element - *******************************************************************************************************/ +* This code inserts the value lookedup by a popup window back into the associated form element +*******************************************************************************************************/ var re_id = new RegExp('id=(\\d+)'); -var num_id = (re_id.exec(String(window.location)) - ? new Number(RegExp.$1) : 0); -var obj_caller = (window.opener ? window.opener.lookups[num_id] : null); -if (obj_caller == null && window.opener != null){ +var num_id = (re_id.exec(String(window.location))? new Number(RegExp.$1): 0); +var obj_caller = (window.opener? window.opener.lookups[num_id]: null); +if (obj_caller == null && window.opener != null) { obj_caller = window.opener; -} -else if(obj_caller == null && window.opener == null){ +} else if (obj_caller == null && window.opener == null) { obj_caller = parent; } var bkColor = "yellow"; -function setSourceColor(src){ -if(src != null) - src.style.backgroundColor = bkColor; - } +function setSourceColor(src) { + if (src != null) + src.style.backgroundColor = bkColor; +} // function passing selected value to calling window function set_value(value) { - if (!obj_caller) return; - setSourceColor(obj_caller.target); - obj_caller.target.value = value; - closeLookup(); + if (! obj_caller) return; + setSourceColor(obj_caller.target); + obj_caller.target.value = value; + closeLookup(); } // function passing selected value to calling window function set_values(value, value2) { - set_value(value); - if (!obj_caller.target2) return; - if (obj_caller.target2 == null) return; - setSourceColor(obj_caller.target2); - obj_caller.target2.value = value2; + set_value(value); + if (! obj_caller.target2) return; + if (obj_caller.target2 == null) return; + setSourceColor(obj_caller.target2); + obj_caller.target2.value = value2; } function set_multivalues(value) { obj_caller.target.value = value; var thisForm = obj_caller.target.form; var evalString = ""; - - if (arguments.length > 2 ) { - for(var i=1; i < arguments.length; i=i+2) { + + if (arguments.length > 2) { + for (var i = 1; i < arguments.length; i = i + 2) { evalString = "setSourceColor(thisForm." + arguments[i] + ")"; eval(evalString); - evalString = "thisForm." + arguments[i] + ".value='" + arguments[i+1] + "'"; + evalString = "thisForm." + arguments[i] + ".value='" + arguments[i + 1] + "'"; eval(evalString); } } closeLookup(); - } -//close the window after passing the value -function closeLookup(){ - if(window.opener != null){ - window.close(); - } else { - parent.lookupHide(); - } } +//close the window after passing the value +function closeLookup() { + if (window.opener != null) { + window.close(); + } else { + parent.lookupHide(); + } +} \ No newline at end of file Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=904922&r1=904921&r2=904922&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Sun Jan 31 00:09:53 2010 @@ -411,7 +411,9 @@ <#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName lookupFieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled lookupPresentation lookupWidth lookupHeight lookupPosition> <div class="field-lookup"><ul> <li><input type="text" <@renderClass className alert /><#if name?has_content> name="${name}"</#if><#if value?has_content> value="${value}"</#if><#if size?has_content> size="${size}"</#if><#if maxlength?has_content> maxlength="${maxlength}"</#if><#if id?has_content> id="${id}"</#if><#rt/><#if disabled?has_content && disabled> disabled="disabled"</#if><#rt/><#if event?has_content && action?has_content> ${event}="${action}"</#if><#rt/><#if autocomplete?has_content> autocomplete="off"</#if>/><#rt/></li> -<li><#if lookupPresentation?has_content && lookupPresentation == "layer"> +<li><#if lookupPresentation?has_content && descriptionFieldName?has_content && lookupPresentation == "layer"> + <a href="javascript:call_fieldlookupLayer3(document.${formName?html}.${name?html}, document.${formName?html}.${descriptionFieldName},'${lookupFieldFormName}','${lookupWidth}','${lookupHeight}','${lookupPosition}'<#rt/> +<#elseif lookupPresentation?has_content && lookupPresentation == "layer"> <a href="javascript:call_fieldlookupLayer(document.${formName?html}.${name?html},'${lookupFieldFormName}','${lookupWidth}','${lookupHeight}','${lookupPosition}'<#rt/> <#elseif descriptionFieldName?has_content> <a href="javascript:call_fieldlookup3(document.${formName?html}.${name?html}, document.${formName?html}.${descriptionFieldName},'${lookupFieldFormName}'<#rt/> |
| Free forum by Nabble | Edit this page |
