Author: erwan
Date: Thu Aug 19 11:12:55 2010 New Revision: 987127 URL: http://svn.apache.org/viewvc?rev=987127&view=rev Log: new option for fields : display-size. If a field size is longer than the specified value, then length will be cut and ... will be added. The full text will be displayed as a hint. This way, a form will not be deformed by too long fields. Modified: 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/htmlFormMacroLibrary.ftl Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=987127&r1=987126&r2=987127&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Thu Aug 19 11:12:55 2010 @@ -659,6 +659,9 @@ under the License. <xs:attribute type="xs:string" name="description"> <xs:annotation><xs:documentation>Specifies the string to display, can use the ${} syntax to insert context values; if empty the value of the field will be printed for a default.</xs:documentation></xs:annotation> </xs:attribute> + <xs:attribute type="xs:integer" name="size"> + <xs:annotation><xs:documentation>Specifies the size of the field (as a number of characters), when the text to display exceed the given size it is truncated and add the complete text as a hint</xs:documentation></xs:annotation> + </xs:attribute> <xs:attribute name="type" default="text"> <xs:simpleType> <xs:restriction base="xs:token"> @@ -699,6 +702,9 @@ under the License. <xs:attribute type="xs:string" name="entity-name" use="required"/> <xs:attribute type="xs:string" name="key-field-name"/> <xs:attribute type="xs:string" name="description" default="${description}"/> + <xs:attribute type="xs:integer" name="size"> + <xs:annotation><xs:documentation>Specifies the size of the field (as a number of characters), when the text to display exceed the given size it is truncated and add the complete text as a hint</xs:documentation></xs:annotation> + </xs:attribute> <xs:attribute name="cache" default="true"> <xs:simpleType> <xs:restriction base="xs:token"> @@ -771,6 +777,9 @@ under the License. images/webapp/images/combobox.js must be included in the page. </xs:documentation></xs:annotation> </xs:attribute> + <xs:attribute type="xs:integer" name="text-size" > + <xs:annotation><xs:documentation>Specifies the size of the field (as a number of characters), when the text to display exceed the given size it is truncated and add the complete text as a hint</xs:documentation></xs:annotation> + </xs:attribute> </xs:attributeGroup> <xs:element name="file" substitutionGroup="AllFields"> <xs:complexType> @@ -866,6 +875,9 @@ under the License. <xs:attribute name="parameters-map" type="xs:string"> <xs:annotation><xs:documentation>A Map in the context that will be used as additional name/value pairs.</xs:documentation></xs:annotation> </xs:attribute> + <xs:attribute type="xs:integer" name="size"> + <xs:annotation><xs:documentation>Specifies the size of the field (as a number of characters), when the text to display exceed the given size it is truncated and add the complete text as a hint</xs:documentation></xs:annotation> + </xs:attribute> </xs:attributeGroup> <xs:element name="parameter"> <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=987127&r1=987126&r2=987127&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 Thu Aug 19 11:12:55 2010 @@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletRes import javolution.util.FastList; +import org.apache.commons.lang.StringEscapeUtils; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilFormatOut; @@ -82,7 +83,6 @@ import freemarker.core.Environment; import freemarker.template.Template; import freemarker.template.TemplateException; - /** * Widget Library - Form Renderer implementation based on Freemarker macros * @@ -191,9 +191,25 @@ public class MacroFormRenderer implement String description = displayField.getDescription(context); String type = displayField.getType(); String imageLocation = displayField.getImageLocation(); + Integer size = Integer.valueOf("0"); + String title = ""; + + if (UtilValidate.isNotEmpty(displayField.getSize())) { + try { + size = Integer.parseInt(displayField.getSize()); + } + catch(NumberFormatException nfe) { + Debug.logError(nfe, "Error reading size of a field fieldName=" + displayField.getModelFormField().getFieldName() + + " FormName= " + displayField.getModelFormField().getModelForm().getName(), module); + } + } ModelFormField.InPlaceEditor inPlaceEditor = displayField.getInPlaceEditor(); boolean ajaxEnabled = inPlaceEditor != null && this.javaScriptEnabled; + if (UtilValidate.isNotEmpty(description) && size > 0 && description.length() > size ) { + title = description; + description = description.substring(0, size-3)+"..."; + } StringWriter sr = new StringWriter(); sr.append("<@renderDisplayField "); @@ -205,6 +221,8 @@ public class MacroFormRenderer implement sr.append(idName); sr.append("\" description=\""); sr.append(description); + sr.append("\" title=\""); + sr.append(title); sr.append("\" class=\""); sr.append(modelFormField.getWidgetStyle()); sr.append("\" alert=\""); @@ -345,12 +363,14 @@ public class MacroFormRenderer implement String encodedImageTitle = encode(hyperlinkField.getImageTitle(context), modelFormField, context); this.request.setAttribute("alternate", encodedAlternate); this.request.setAttribute("imageTitle", encodedImageTitle); + this.request.setAttribute("descriptionSize", hyperlinkField.getSize()); makeHyperlinkByType(writer, hyperlinkField.getLinkType(), modelFormField.getWidgetStyle(), hyperlinkField.getTargetType(), hyperlinkField.getTarget(context), hyperlinkField.getParameterMap(context), hyperlinkField.getDescription(context), hyperlinkField.getTargetWindow(context), hyperlinkField.getConfirmation(context), modelFormField, this.request, this.response, context); this.appendTooltip(writer, context, modelFormField); this.request.removeAttribute("image"); + this.request.removeAttribute("descriptionSize"); } public void renderTextField(Appendable writer, Map<String, Object> context, TextField textField) throws IOException { @@ -684,6 +704,16 @@ public class MacroFormRenderer implement ModelFormField.AutoComplete autoComplete = dropDownField.getAutoComplete(); String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); + Integer textSize = Integer.valueOf(0); + if (UtilValidate.isNotEmpty(dropDownField.getTextSize())) { + try { + textSize = Integer.parseInt(dropDownField.getTextSize()); + } + catch(NumberFormatException nfe) { + Debug.logError(nfe, "Error reading size of a field fieldName=" + dropDownField.getModelFormField().getFieldName() + + " FormName= " + dropDownField.getModelFormField().getModelForm().getName(), module); + } + } boolean ajaxEnabled = autoComplete != null && this.javaScriptEnabled; String className = ""; String alert = "false"; @@ -758,6 +788,11 @@ public class MacroFormRenderer implement options.append("'"); options.append(",'description':'"); String description = encode(optionValue.getDescription(), modelFormField, context); + String unescaped = StringEscapeUtils.unescapeHtml(description); + if (textSize > 0 && unescaped.length() > textSize ) { + String reduced = unescaped.substring(0, textSize - 3) + "..."; + description = StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(reduced)); + } options.append(description); if (UtilValidate.isNotEmpty(currentValueList)) { @@ -2944,6 +2979,15 @@ public class MacroFormRenderer implement if (UtilValidate.isNotEmpty(request.getAttribute("imageTitle"))) { imgTitle = request.getAttribute("imageTitle").toString(); } + Integer size = Integer.valueOf("0"); + + if (UtilValidate.isNotEmpty(request.getAttribute("descriptionSize"))) { + size = Integer.valueOf(request.getAttribute("descriptionSize").toString()); + } + if( UtilValidate.isNotEmpty(description) && size > 0 && description.length() > size) { + imgTitle = description; + description = description.substring(0, size - 3) + "..."; + } if(UtilValidate.isEmpty(imgTitle)){ imgTitle = modelFormField.getTitle(context); } 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=987127&r1=987126&r2=987127&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 Thu Aug 19 11:12:55 2010 @@ -2047,6 +2047,7 @@ public class ModelFormField { protected boolean alsoHidden = true; protected FlexibleStringExpander description; protected String type; // matches type of field, currently text or currency + protected String size; // maximum number of characters to display protected String imageLocation; protected FlexibleStringExpander currency; protected FlexibleStringExpander date; @@ -2067,6 +2068,7 @@ public class ModelFormField { public DisplayField(Element element, ModelFormField modelFormField) { super(element, modelFormField); this.type = element.getAttribute("type"); + this.size = element.getAttribute("size"); this.imageLocation = element.getAttribute("image-location"); this.setCurrency(element.getAttribute("currency")); this.setDescription(element.getAttribute("description")); @@ -2091,6 +2093,13 @@ public class ModelFormField { return this.type; } + public String getSize(){ + return this.size; + } + public String setSize(String size){ + return this.size = size; + } + public String getImageLocation(){ return this.imageLocation; } @@ -2211,6 +2220,7 @@ public class ModelFormField { this.entityName = element.getAttribute("entity-name"); this.keyFieldName = element.getAttribute("key-field-name"); this.cache = !"false".equals(element.getAttribute("cache")); + this.size = element.getAttribute("size"); if (this.description == null || this.description.isEmpty()) { this.setDescription("${description}"); @@ -2267,6 +2277,9 @@ public class ModelFormField { public void setSubHyperlink(SubHyperlink newSubHyperlink) { this.subHyperlink = newSubHyperlink; } + public String getSize(){ + return this.size; + } } public static class HyperlinkField extends FieldInfo { @@ -2276,6 +2289,7 @@ public class ModelFormField { protected String linkType; protected String targetType; protected String image; + protected String size; protected FlexibleStringExpander target; protected FlexibleStringExpander description; protected FlexibleStringExpander alternate; @@ -2311,6 +2325,7 @@ public class ModelFormField { this.targetWindowExdr = FlexibleStringExpander.getInstance(element.getAttribute("target-window")); this.parametersMapAcsr = FlexibleMapAccessor.getInstance(element.getAttribute("parameters-map")); this.image = element.getAttribute("image-location"); + this.size = element.getAttribute("size"); this.setRequestConfirmation("true".equals(element.getAttribute("request-confirmation"))); this.setConfirmationMsg(element.getAttribute("confirmation-message")); List<? extends Element> parameterElementList = UtilXml.childElementList(element, "parameter"); @@ -2401,6 +2416,14 @@ public class ModelFormField { return this.image; } + public String getSize() { + return this.size; + } + + public String setSize(String size) { + return this.size = size; + } + /** * @param b */ @@ -3071,6 +3094,7 @@ public class ModelFormField { protected boolean allowMulti = false; protected String current; protected String size; + protected String textSize; protected FlexibleStringExpander currentDescription; protected SubHyperlink subHyperlink; protected int otherFieldSize = 0; @@ -3093,6 +3117,7 @@ public class ModelFormField { this.current = element.getAttribute("current"); this.size = element.getAttribute("size"); + this.textSize = element.getAttribute("text-size"); this.allowEmpty = "true".equals(element.getAttribute("allow-empty")); this.allowMulti = "true".equals(element.getAttribute("allow-multiple")); this.currentDescription = FlexibleStringExpander.getInstance(element.getAttribute("current-description")); @@ -3101,6 +3126,9 @@ public class ModelFormField { if (size == null) { size = "1"; } + if (textSize == null) { + textSize = "0"; + } String sizeStr = element.getAttribute("other-field-size"); try { @@ -3185,6 +3213,10 @@ public class ModelFormField { return this.size; } + public String getTextSize() { + return this.textSize; + } + /** * Get the name to use for the parameter for this field in the form interpreter. * For HTML forms this is the request parameter name. Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=987127&r1=987126&r2=987127&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Thu Aug 19 11:12:55 2010 @@ -23,12 +23,12 @@ under the License. </#if> </#macro> -<#macro renderDisplayField type imageLocation idName description class alert inPlaceEditorUrl="" inPlaceEditorParams=""> +<#macro renderDisplayField type imageLocation idName description title class alert inPlaceEditorUrl="" inPlaceEditorParams=""> <#if type?has_content && type=="image"> <img src="${imageLocation}" alt=""><#lt/> <#else> - <#if inPlaceEditorUrl?has_content || class?has_content || alert=="true"> - <span <#if idName?has_content>id="cc_${idName}"</#if> <@renderClass class alert />><#t/> + <#if inPlaceEditorUrl?has_content || class?has_content || alert=="true" || title?has_content> + <span <#if idName?has_content>id="cc_${idName}"</#if> <#if title?has_content>title="${title}"</#if> <@renderClass class alert />><#t/> </#if> <#if description?has_content> @@ -517,4 +517,4 @@ ${item.description}</span> <#macro makeHiddenFormLinkForm actionUrl name parameters targetWindow><form method="post" action="${actionUrl}" <#if targetWindow?has_content>target="${targetWindow}"</#if> onsubmit="javascript:submitFormDisableSubmits(this)" name="${name}"><#list parameters as parameter><input name="${parameter.name}" value="${parameter.value}" type="hidden"/></#list></form></#macro> <#macro makeHiddenFormLinkAnchor linkStyle hiddenFormName event action imgSrc description confirmation><a <#if linkStyle?has_content>class="${linkStyle}"</#if> href="javascript:document.${hiddenFormName}.submit()"<#if action?has_content && event?has_content> ${event}="${action}"</#if><#if confirmation?has_content> onclick="return confirm('${confirmation?js_string}')"</#if>><#if imgSrc?has_content><img src="${imgSrc}" alt=""/></#if>${description}</a></#macro> -<#macro makeHyperlinkString linkStyle hiddenFormName event action imgSrc title alternate linkUrl targetWindow description confirmation><a <#if linkStyle?has_content>class="${linkStyle}"</#if> href="${linkUrl}"<#if targetWindow?has_content> target="${targetWindow}"</#if><#if action?has_content && event?has_content> ${event}="${action}"</#if><#if confirmation?has_content> onclick="return confirm('${confirmation?js_string}')"</#if>><#if imgSrc?has_content><img src="${imgSrc}" alt="${alternate}" title="${title}"/></#if>${description}</a></#macro> +<#macro makeHyperlinkString linkStyle hiddenFormName event action imgSrc title alternate linkUrl targetWindow description confirmation><a <#if linkStyle?has_content>class="${linkStyle}"</#if> href="${linkUrl}"<#if targetWindow?has_content> target="${targetWindow}"</#if><#if action?has_content && event?has_content> ${event}="${action}"</#if><#if confirmation?has_content> onclick="return confirm('${confirmation?js_string}')"</#if><#if imgSrc?length == 0 && title?has_content> title="${title}"</#if>><#if imgSrc?has_content><img src="${imgSrc}" alt="${alternate}" title="${title}"/></#if>${description}</a></#macro> |
Free forum by Nabble | Edit this page |