Author: jleroux
Date: Wed Jun 2 10:44:16 2010 New Revision: 950481 URL: http://svn.apache.org/viewvc?rev=950481&view=rev Log: Allows to initially collapse the search screenlet of a layered lookup, default to false. It was harder than I though because of the async nature of Ajax. So I had to use a setTimeout with a 400 ms timeout. Hopefully it will work in any environments. I chose 400 because I found it worked well on my machine, 300 also but to be sure I picked 400, 200 was too low it seems. Modified: ofbiz/trunk/framework/images/webapp/images/fieldlookup.js ofbiz/trunk/framework/widget/dtd/widget-form.xsd ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.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=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/fieldlookup.js (original) +++ ofbiz/trunk/framework/images/webapp/images/fieldlookup.js Wed Jun 2 10:44:16 2010 @@ -24,6 +24,8 @@ var IE5 = (document.getElementById && do var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape") >= 0)? true: false; var mx, my; var ACTIVATED_LOOKUP = null; +var LOOKUP_DIV = null; +INITIALLY_COLLAPSED = null; function moveobj(evt) { if (NS4 || NS6) { @@ -46,22 +48,22 @@ function call_fieldlookup(target, viewNa if (! viewheight) viewheight = 200; fieldLookup.popup(viewName, formName, viewWidth, viewheight); } -function call_fieldlookupLayer(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground) { +function call_fieldlookupLayer(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed) { if (isEmpty(target) || isEmpty(viewName)) { return lookup_error("Lookup can't be created, one of these variables is missing: target=" + target + " viewName=" + viewName); } - var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, arguments); + var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed, arguments); fieldLookupPopup.showLookup(); this.target = target; } -function call_fieldlookupLayer3(target, target2, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground) { +function call_fieldlookupLayer3(target, target2, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed) { if (isEmpty(target) || isEmpty(target2) || isEmpty(viewName)) { return lookup_error("Lookup can't be created, one of these variables is missing: target=" + target + " target2=" + target2 + " viewName=" + viewName); } - var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, arguments); + var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed, arguments); fieldLookupPopup.showLookup(); this.target = target; this.target2 = target2; @@ -140,6 +142,39 @@ function lookup_error(str_message) { return null; } +function initiallyCollapse() { + if ((!LOOKUP_DIV) || (INITIALLY_COLLAPSED != "true")) return; + var slTitleBars = LOOKUP_DIV.getElementsByClassName('screenlet-title-bar'); + for (i in slTitleBars) { + var slTitleBar = slTitleBars[i]; + var ul = slTitleBar.firstChild; + if ((typeof ul) != 'object') continue; + + var childElements = ul.childNodes; + for (j in childElements) { + if (childElements[j].className == 'expanded' || childElements[j].className == 'collapsed') { + break; + } + } + var childEle = childElements[j].firstChild; + CollapsePanel(childEle, 'lec' + COLLAPSE); + break; + } +} + +function CollapsePanel(link, areaId){ + var container = $(areaId); + var liElement = $(link).up('li'); + liElement.removeClassName('expanded'); + liElement.addClassName('collapsed'); + Effect.toggle(container, 'appear'); +} + +function initiallyCollapseDelayed() { + setTimeout("initiallyCollapse()", 400); +} + + /************************************* * Fieldlookup Class & Methods *************************************/ @@ -200,19 +235,21 @@ var GLOBAL_LOOKUP_REF = new FieldLookupC * 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), etc. (see widget-form.xsd), default: top-left +* fadeBackGround - boolean, true by default +* initiallyCollapsed - boolean, false by default */ var FieldLookupPopup = Class.create({ - initialize: function (target, viewName, lookupWidth, lookupHeight, position, fadeBackground, args) { + initialize: function (target, viewName, lookupWidth, lookupHeight, position, fadeBackground, initiallyCollapsed, args) { if (args != null) { var argString = ""; - if (args.length > 7) { - for (var i = 7; i < args.length; i++) { - if ((viewName.indexOf("?") == -1) && (i - 6) == 1) { + if (args.length > 8) { + for (var i = 8; i < args.length; i++) { + if ((viewName.indexOf("?") == -1) && (i - 7) == 1) { sep = "?"; } else { sep = "&"; } - argString += sep + "parm" + (i - 6) + "=" + args[i]; + argString += sep + "parm" + (i - 7) + "=" + args[i]; } viewName += argString; } @@ -237,9 +274,10 @@ var FieldLookupPopup = Class.create({ this.parentTarget = target; this.viewName = viewName; this.position = position; - + INITIALLY_COLLAPSED = initiallyCollapsed; + this.createElement(); - + //set observe events for mouse and keypress Event.observe(document, "keypress", this.key_event = this.key_event.bindAsEventListener(this)); Event.observe(document, "mousedown", this.close_on_click = this.close_on_click.bindAsEventListener(this)); @@ -317,15 +355,20 @@ var FieldLookupPopup = Class.create({ //set the layer position this.setPosition(lookupDiv); - this.divRef = lookupDiv; + this.divRef = lookupDiv; //make layer draggable this.makeDraggable(lookupDiv); //make the window resiable this.makeResizeable(lookupDiv); - + identifyLookup(this.globalRef); + + //Collapse the search screenlet if the flag is set + LOOKUP_DIV = lookupDiv; + initiallyCollapseDelayed(); + }, close_on_click: function (evt) { @@ -366,7 +409,7 @@ var FieldLookupPopup = Class.create({ return lookupCont }, - + createFadedBackground: function (){ var pageSize = this.getPageSize(); var fadedBackground = new Element ('DIV', { @@ -575,7 +618,7 @@ function modifyCollapseable(lookupDiv){ var childElements = ul.childNodes; for (j in childElements) { - if (childElements[j].className == 'expanded' ||childElements[j].className == 'collapsed') { + if (childElements[j].className == 'expanded' || childElements[j].className == 'collapsed') { break; } } @@ -586,7 +629,6 @@ function modifyCollapseable(lookupDiv){ childEle.setAttribute('onclick', "javascript:toggleScreenlet(this, 'lec" + COLLAPSE +"', 'true', 'Expand', 'Collapse');"); childEle.href = "javascript:void(0);" slTitleBar.next('div').setAttribute('id', 'lec' + COLLAPSE); - } } Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Wed Jun 2 10:44:16 2010 @@ -968,6 +968,15 @@ under the License. </xs:restriction> </xs:simpleType> </xs:attribute> + <xs:attribute name="initially-collapsed" default="false"> + <xs:annotation><xs:documentation>If true the search screenlet is collapsed intially, default to false.</xs:documentation></xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> </xs:attributeGroup> <xs:element name="password" substitutionGroup="AllFields"> <xs:complexType> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Wed Jun 2 10:44:16 2010 @@ -2025,7 +2025,8 @@ public class MacroFormRenderer implement if (UtilValidate.isEmpty(fadeBackground)){ fadeBackground = "false"; } - + Boolean isInitiallyCollapsed = lookupField.getInitiallyCollapsed(); + String clearText = ""; Map<String, Object> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); if (uiLabelMap != null) { @@ -2093,6 +2094,8 @@ public class MacroFormRenderer implement sr.append(clearText); sr.append("\" showDescription=\""); sr.append(Boolean.toString(showDescription)); + sr.append("\" initiallyCollapsed=\""); + sr.append(Boolean.toString(isInitiallyCollapsed)); sr.append("\" />"); executeMacro(writer, sr.toString()); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Wed Jun 2 10:44:16 2010 @@ -3559,6 +3559,7 @@ public class ModelFormField { protected String lookupHeight; protected String lookupPosition; protected String fadeBackground; + protected String initiallyCollapsed; public LookupField(Element element, ModelFormField modelFormField) { super(element, modelFormField); @@ -3569,7 +3570,8 @@ public class ModelFormField { this.lookupHeight = element.getAttribute("height"); this.lookupWidth = element.getAttribute("width"); this.lookupPosition = element.getAttribute("position"); - this.fadeBackground = element.getAttribute("fade-background"); + this.fadeBackground = element.getAttribute("fade-background"); + this.initiallyCollapsed = element.getAttribute("initially-collapsed"); Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); if (subHyperlinkElement != null) { @@ -3657,6 +3659,10 @@ public class ModelFormField { public void setFadeBackground(String str) { this.fadeBackground = str; } + //initially-collapsed status + public boolean getInitiallyCollapsed() { + return "true".equals(this.initiallyCollapsed); + } } public static class FileField extends TextField { Modified: ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl Wed Jun 2 10:44:16 2010 @@ -103,7 +103,7 @@ under the License. <@renderField value /> </#macro> -<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription></#macro> +<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription initiallyCollapsed></#macro> <#macro renderNextPrev paginateStyle paginateFirstStyle viewIndex highIndex listSize viewSize ajaxEnabled javaScriptEnabled ajaxFirstUrl firstUrl paginateFirstLabel paginatePreviousStyle ajaxPreviousUrl previousUrl paginatePreviousLabel pageLabel ajaxSelectUrl selectUrl ajaxSelectSizeUrl selectSizeUrl commonDisplaying paginateNextStyle ajaxNextUrl nextUrl paginateNextLabel paginateLastStyle ajaxLastUrl lastUrl paginateLastLabel paginateViewSizeLabel></#macro> <#macro renderFileField className alert name value size maxlength autocomplete><@renderField value /></#macro> <#macro renderPasswordField className alert name value size maxlength id autocomplete></#macro> Modified: ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl Wed Jun 2 10:44:16 2010 @@ -122,7 +122,7 @@ under the License. <@makeBlock className value /> </#macro> -<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription></#macro> +<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription initiallyCollapsed></#macro> <#macro renderNextPrev paginateStyle paginateFirstStyle viewIndex highIndex listSize viewSize ajaxEnabled javaScriptEnabled ajaxFirstUrl firstUrl paginateFirstLabel paginatePreviousStyle ajaxPreviousUrl previousUrl paginatePreviousLabel pageLabel ajaxSelectUrl selectUrl ajaxSelectSizeUrl selectSizeUrl commonDisplaying paginateNextStyle ajaxNextUrl nextUrl paginateNextLabel paginateLastStyle ajaxLastUrl lastUrl paginateLastLabel paginateViewSizeLabel></#macro> <#macro renderFileField className alert name value size maxlength autocomplete><@makeBlock className value /></#macro> <#macro renderPasswordField className alert name value size maxlength id autocomplete><@makeBlock className "" /></#macro> Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Wed Jun 2 10:44:16 2010 @@ -421,7 +421,7 @@ ${item.description}</span> </#if> </#macro> -<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription> +<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription initiallyCollapsed> <span class="field-lookup"> <#if size?has_content && size=="0"><input type="hidden" <#if name?has_content> name="${name}"/></#if><#else><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/></#if> <#if presentation?has_content && descriptionFieldName?has_content && presentation == "window"> @@ -429,9 +429,9 @@ ${item.description}</span> <#elseif presentation?has_content && presentation == "window"> <a href="javascript:call_fieldlookup2(document.${formName}.${name},'${fieldFormName}'<#rt/> <#elseif descriptionFieldName?has_content> - <a href="javascript:call_fieldlookupLayer3(document.${formName?html}.${name?html},document.${formName?html}.${descriptionFieldName},'${fieldFormName}','${width}','${height}','${position}','${fadeBackground}'<#rt/> + <a href="javascript:call_fieldlookupLayer3(document.${formName?html}.${name?html},document.${formName?html}.${descriptionFieldName},'${fieldFormName}','${width}','${height}','${position}','${fadeBackground}','${initiallyCollapsed}'<#rt/> <#else> - <a href="javascript:call_fieldlookupLayer(document.${formName?html}.${name?html},'${fieldFormName}','${width}','${height}','${position}','${fadeBackground}'<#rt/> + <a href="javascript:call_fieldlookupLayer(document.${formName?html}.${name?html},'${fieldFormName}','${width}','${height}','${position}','${fadeBackground}','${initiallyCollapsed}'<#rt/> </#if> <#if targetParameterIter?has_content> <#list targetParameterIter as item> Modified: ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl Wed Jun 2 10:44:16 2010 @@ -103,7 +103,7 @@ under the License. <@renderField value /> </#macro> -<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription><@renderField value /></#macro> +<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription initiallyCollapsed><@renderField value /></#macro> <#macro renderNextPrev paginateStyle paginateFirstStyle viewIndex highIndex listSize viewSize ajaxEnabled javaScriptEnabled ajaxFirstUrl firstUrl paginateFirstLabel paginatePreviousStyle ajaxPreviousUrl previousUrl paginatePreviousLabel pageLabel ajaxSelectUrl selectUrl ajaxSelectSizeUrl selectSizeUrl commonDisplaying paginateNextStyle ajaxNextUrl nextUrl paginateNextLabel paginateLastStyle ajaxLastUrl lastUrl paginateLastLabel paginateViewSizeLabel></#macro> <#macro renderFileField className alert name value size maxlength autocomplete><@renderField value /></#macro> <#macro renderPasswordField className alert name value size maxlength id autocomplete></#macro> Modified: ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl?rev=950481&r1=950480&r2=950481&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl Wed Jun 2 10:44:16 2010 @@ -96,7 +96,7 @@ under the License. <#macro renderRangeFindField className alert name value size maxlength autocomplete titleStyle defaultOptionFrom opEquals opGreaterThan opGreaterThanEquals opLessThan opLessThanEquals value2 defaultOptionThru> </#macro> -<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription></#macro> +<#macro renderLookupField className alert name value size maxlength id event action disabled autocomplete descriptionFieldName formName fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled presentation width height position fadeBackground clearText showDescription initiallyCollapsed></#macro> <#macro renderNextPrev paginateStyle paginateFirstStyle viewIndex highIndex listSize viewSize ajaxEnabled javaScriptEnabled ajaxFirstUrl firstUrl paginateFirstLabel paginatePreviousStyle ajaxPreviousUrl previousUrl paginatePreviousLabel pageLabel ajaxSelectUrl selectUrl ajaxSelectSizeUrl selectSizeUrl commonDisplaying paginateNextStyle ajaxNextUrl nextUrl paginateNextLabel paginateLastStyle ajaxLastUrl lastUrl paginateLastLabel paginateViewSizeLabel></#macro> <#macro renderFileField className alert name value size maxlength autocomplete></#macro> <#macro renderPasswordField className alert name value size maxlength id autocomplete></#macro> |
Free forum by Nabble | Edit this page |