svn commit: r938844 - in /ofbiz/trunk/framework: example/config/ example/entitydef/ example/widget/example/ widget/config/ widget/src/org/ofbiz/widget/form/ widget/templates/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r938844 - in /ofbiz/trunk/framework: example/config/ example/entitydef/ example/widget/example/ widget/config/ widget/src/org/ofbiz/widget/form/ widget/templates/

jleroux@apache.org
Author: jleroux
Date: Wed Apr 28 10:02:57 2010
New Revision: 938844

URL: http://svn.apache.org/viewvc?rev=938844&view=rev
Log:
A slightly modified patch from Chris Snow "Provide better user help" (https://issues.apache.org/jira/browse/OFBIZ-3702) - OFBIZ-3702

Provides help by hovering over the field label. See Example for... an example :o) And also https://issues.apache.org/jira/secure/attachment/12442717/fieldLabelTooltip2.png

Added:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java   (with props)
Modified:
    ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml
    ofbiz/trunk/framework/example/entitydef/entitymodel.xml
    ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
    ofbiz/trunk/framework/widget/config/widget.properties
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
    ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl

Modified: ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml?rev=938844&r1=938843&r2=938844&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml (original)
+++ ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml Wed Apr 28 10:02:57 2010
@@ -90,6 +90,10 @@
         <value xml:lang="th">รหัสตัวอย่างประเภท ถ้าไม่มีการกำหนดรหัส จะต้องมีการสร้างขึ้นอัตโมัติ</value>
         <value xml:lang="zh">一个唯一的样例类型序号。如果你没有指定一个标识,那么会自动生成一个</value>
     </property>
+    <property key="FieldDescription.Example.exampleTypeId">
+        <value xml:lang="en">The type of Example.</value>
+        <value xml:lang="fr">Le type de l'exemple.</value>
+    </property>
     <property key="FieldDescription.amount">
         <value xml:lang="de">Betrag</value>
         <value xml:lang="en">Amount</value>

Modified: ofbiz/trunk/framework/example/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/entitydef/entitymodel.xml?rev=938844&r1=938843&r2=938844&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/example/entitydef/entitymodel.xml Wed Apr 28 10:02:57 2010
@@ -43,7 +43,9 @@ under the License.
 
     <entity entity-name="Example"
             package-name="org.ofbiz.example.example"
-            title="Example Entity">
+            title="Example Entity"
+            default-resource-name="ExampleEntityLabels"
+            >
         <field name="exampleId" type="id-ne"><description>primary sequenced ID</description></field>
         <field name="exampleTypeId" type="id-ne"></field>
         <field name="statusId" type="id-ne"></field>

Modified: ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleForms.xml?rev=938844&r1=938843&r2=938844&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/widget/example/ExampleForms.xml (original)
+++ ofbiz/trunk/framework/example/widget/example/ExampleForms.xml Wed Apr 28 10:02:57 2010
@@ -101,7 +101,7 @@ under the License.
         </actions>
         <alt-target use-when="example==null" target="createExample"/>
         <auto-fields-service service-name="updateExample"/>
-        <field use-when="example!=null" name="exampleId" title="${uiLabelMap.ExampleExampleId}" tooltip="${uiLabelMap.CommonNotModifRecreat}"><display/></field>
+        <field use-when="example!=null" name="exampleId" title="${uiLabelMap.ExampleExampleId}" tooltip="${uiLabelMap.CommonNotModifRecreat}" entity-name="Example"><display/></field>
         <field use-when="example==null @and exampleId==null" name="exampleId" title="${uiLabelMap.ExampleExampleId}"><ignored/></field>
         <field use-when="example==null @and exampleId!=null" name="exampleId" title="${uiLabelMap.ExampleExampleId}"><display description="${uiLabelMap.CommonCannotBeFound}: [${exampleId}]" also-hidden="false"/></field>
         <field name="exampleTypeId" title="${uiLabelMap.CommonType}" id-name="exampleTypeId">
@@ -112,12 +112,12 @@ under the License.
                 </entity-options>
             </drop-down>
         </field>
-        <field name="statusId" use-when="example==null" title="${uiLabelMap.CommonStatus}">
+        <field name="statusId" use-when="example==null" title="${uiLabelMap.CommonStatus}" entity-name="Example">
             <drop-down allow-empty="false">
                 <entity-options entity-name="ExampleStatusItem" description="${description}"/>
             </drop-down>
         </field>
-        <field name="statusId" use-when="example!=null" title="${uiLabelMap.CommonStatus}">
+        <field name="statusId" use-when="example!=null" title="${uiLabelMap.CommonStatus}" entity-name="Example">
             <drop-down allow-empty="false" current-description="${currentStatus.description}">
                 <entity-options entity-name="StatusValidChangeToDetail" key-field-name="statusIdTo" description="${transitionName} (${description})">
                     <entity-constraint name="statusId" env-name="example.statusId"/>

Modified: ofbiz/trunk/framework/widget/config/widget.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/config/widget.properties?rev=938844&r1=938843&r2=938844&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/config/widget.properties (original)
+++ ofbiz/trunk/framework/widget/config/widget.properties Wed Apr 28 10:02:57 2010
@@ -38,6 +38,9 @@ widget.lookup.showDescription=Y
 # Default text find field's option
 widget.form.defaultTextFindOption=contains
 
+# Controls whether to display help text tooltips for form field titles
+widget.form.displayhelpText=Y
+
 # Controls the initial results display in Find screens. If set to Y, the
 # search result list will be populated when the Find screen first appears.
 # If set to N, the search result list will be empty when the Find screen

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=938844&r1=938843&r2=938844&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 Apr 28 10:02:57 2010
@@ -48,6 +48,7 @@ import org.ofbiz.base.util.UtilPropertie
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.base.util.template.FreeMarkerWorker;
+import org.ofbiz.entity.Delegator;
 import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.webapp.taglib.ContentUrlTag;
 import org.ofbiz.widget.ModelWidget;
@@ -1202,11 +1203,23 @@ public class MacroFormRenderer implement
                     style = requiredStyle;
                 }
             }
+            Delegator delegator = (Delegator)request.getAttribute("delegator");
+            Locale locale = (Locale)context.get("locale");
+            String entityName = modelFormField.getEntityName();
+            String fieldName = modelFormField.getFieldName();
+            String helpText = UtilHelpText.getHelp(entityName, fieldName, delegator, locale);
+            
+            String displayHelpText = UtilProperties.getPropertyValue("widget.properties", "widget.form.displayhelpText");
+            
             StringWriter sr = new StringWriter();
             sr.append("<@renderFieldTitle ");
             sr.append(" style=\"");
             sr.append(style);
-            sr.append("\" title=\"");
+            if ("Y".equals(displayHelpText)) {
+                sr.append("\" fieldHelpText=\"");
+                sr.append(FreeMarkerWorker.encodeDoubleQuotes(helpText));
+            }
+            sr.append("\" fieldTitle=\"");
             sr.append(sb.toString());
             sr.append("\" />");
             executeMacro(writer, sr.toString());

Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java?rev=938844&view=auto
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java (added)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java Wed Apr 28 10:02:57 2010
@@ -0,0 +1,56 @@
+package org.ofbiz.widget.form;
+
+import java.util.Locale;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelReader;
+
+/**
+ * Util for working with Help Text
+ */
+public class UtilHelpText {
+
+    public static final String module = UtilHelpText.class.getName();
+
+    /**
+     * Find the help text associated with an entity field.
+     *
+     * @param entityName the entity name
+     * @param fieldName the field name
+     * @param delegator the delegator
+     * @param locale the locale
+     * @return the help text, or the resource propertyName if no help text exists
+     */
+    public static String getHelp(final String entityName, final String fieldName, final Delegator delegator, final Locale locale) {
+
+        if (UtilValidate.isEmpty(entityName)) {
+            Debug.logWarning("entityName [" + entityName + "] is empty", module);
+            return "";
+        }
+        if (UtilValidate.isEmpty(fieldName)) {
+            Debug.logWarning("fieldName [" + fieldName + "] is empty", module);
+            return "";
+        }
+        ModelReader reader = delegator.getModelReader();
+        ModelEntity entity = null;
+        try {
+            if (!reader.getEntityNames().contains(entityName)) {
+                Debug.logWarning("couldn't find entityName [" + entityName + "]", module);
+                return "";
+            }
+            entity = reader.getModelEntity(entityName);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Error getting help text for entity=" + entityName + " field " + fieldName, module);
+            return "";
+        }
+        String entityResourceName = entity.getDefaultResourceName();
+        String messageId = "FieldDescription." + entityName + "." + fieldName;
+        String fieldDescription = UtilProperties.getMessage(entityResourceName, messageId, locale);
+        return fieldDescription;
+    }
+}
\ No newline at end of file

Propchange: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=938844&r1=938843&r2=938844&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Wed Apr 28 10:02:57 2010
@@ -205,14 +205,20 @@ ${item.description}</span>
 
 <#macro renderIgnoredField></#macro>
 
-<#macro renderFieldTitle style title>
+<#macro renderFieldTitle style fieldTitle fieldHelpText="">
+    <#if fieldHelpText?has_content>
+        <span title="${fieldHelpText}"><#t/>
+    </#if>
     <#if style?has_content>
         <span class="${style}"><#t/>
     </#if>
-    ${title}<#t/>
+    ${fieldTitle}<#t/>
     <#if style?has_content>
-        </span><#lt/>
+        </span><#t/>
     </#if>
+    <#if fieldHelpText?has_content>
+        </span><#t/>
+    </#if>    
 </#macro>
 
 <#macro renderSingleFormFieldTitle></#macro>