svn commit: r711987 - in /ofbiz/trunk/framework: example/widget/example/ExampleForms.xml images/webapp/images/maincss.css widget/dtd/widget-form.xsd widget/src/org/ofbiz/widget/form/ModelForm.java widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

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

svn commit: r711987 - in /ofbiz/trunk/framework: example/widget/example/ExampleForms.xml images/webapp/images/maincss.css widget/dtd/widget-form.xsd widget/src/org/ofbiz/widget/form/ModelForm.java widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

jleroux@apache.org
Author: jleroux
Date: Thu Nov  6 14:04:10 2008
New Revision: 711987

URL: http://svn.apache.org/viewvc?rev=711987&view=rev
Log:
A patch from Nicolas Malin " Add filter on list to apply specific style" (https://issues.apache.org/jira/browse/OFBIZ-2032) - OFBIZ-2032
As suggested by Scott, Nicolas has replaced filter by altRowStyle, all is ok

Modified:
    ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
    ofbiz/trunk/framework/images/webapp/images/maincss.css
    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

Modified: ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleForms.xml?rev=711987&r1=711986&r2=711987&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/widget/example/ExampleForms.xml (original)
+++ ofbiz/trunk/framework/example/widget/example/ExampleForms.xml Thu Nov  6 14:04:10 2008
@@ -52,6 +52,8 @@
                 <field-map field-name="orderBy" env-name="parameters.sortField"/>
             </service>
         </actions>
+        <alt-row-style use-when="&quot;EXST_APPROVED&quot;.equals(statusId)" style="Validate"/>
+        <alt-row-style use-when="&quot;EXST_CANCELLED&quot;.equals(statusId)" style="Warn"/>
         <field name="exampleId" title="${uiLabelMap.ExampleExampleId}" widget-style="buttontext">
             <hyperlink also-hidden="false" description="${exampleId}" target="EditExample?exampleId=${exampleId}"/>
         </field>

Modified: ofbiz/trunk/framework/images/webapp/images/maincss.css
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/maincss.css?rev=711987&r1=711986&r2=711987&view=diff
==============================================================================
--- ofbiz/trunk/framework/images/webapp/images/maincss.css (original)
+++ ofbiz/trunk/framework/images/webapp/images/maincss.css Thu Nov  6 14:04:10 2008
@@ -1451,6 +1451,26 @@
 background: #FFF55F;
 }
 
+.basic-table .Validate {
+/*Style use by alt-row-style on list*/
+background: #A0D5F7;
+}
+
+.basic-table .alternate-rowValidate {
+/*Style use by alt-row-style on list*/
+background: #72A8F2;
+}
+
+.basic-table .Warn {
+/*Style use by alt-row-style on list*/
+background: #f55C5C;
+}
+
+.basic-table .alternate-rowWarn {
+/*Style use by alt-row-style on list*/
+background: #FC7455;
+}
+
 .basic-table tr .button-col {
 /* button column style - for the small
 collection of buttons used in lists */

Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=711987&r1=711986&r2=711987&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Thu Nov  6 14:04:10 2008
@@ -32,6 +32,7 @@
             <xs:sequence>
                 <xs:element minOccurs="0" ref="actions"/>
                 <xs:element minOccurs="0" ref="row-actions"/>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="alt-row-style"/>
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="alt-target"/>
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="auto-fields-service"/>
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="auto-fields-entity"/>
@@ -234,6 +235,20 @@
         <xs:attribute type="xs:string" name="target"/>
         <xs:attribute type="xs:string" name="target-type"/>
     </xs:attributeGroup>
+    <xs:element name="alt-row-style">
+        <xs:annotation><xs:documentation>Active a style on a line if the use-when condition is validate</xs:documentation></xs:annotation>            
+        <xs:complexType>
+            <xs:attributeGroup ref="attlist.alt-row-style"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.alt-row-style">
+        <xs:attribute type="xs:string" name="use-when" use="required">
+            <xs:annotation><xs:documentation>Boolean expression tested for active the style on a line.</xs:documentation></xs:annotation>
+        </xs:attribute>
+        <xs:attribute type="xs:string" name="style" use="required">
+            <xs:annotation><xs:documentation>If use-when return true, concat this style to existing style of the line.</xs:documentation></xs:annotation>
+        </xs:attribute>
+    </xs:attributeGroup>
     <xs:element name="auto-fields-service">
         <xs:complexType>
             <xs:attributeGroup ref="attlist.auto-fields-service"/>

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=711987&r1=711986&r2=711987&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Thu Nov  6 14:04:10 2008
@@ -132,6 +132,7 @@
     protected List<AutoFieldsService> autoFieldsServices = FastList.newInstance();
     protected List<AutoFieldsEntity> autoFieldsEntities = FastList.newInstance();
     protected List<String> sortOrderFields = FastList.newInstance();
+    protected List<AltRowStyle> altRowStyles = FastList.newInstance();
 
     /** This List will contain one copy of each field for each field name in the order
      * they were encountered in the service, entity, or form definition; field definitions
@@ -291,6 +292,7 @@
                 this.defaultViewSize = parent.defaultViewSize;
                 this.onSubmitUpdateAreas = parent.onSubmitUpdateAreas;
                 this.onPaginateUpdateAreas = parent.onPaginateUpdateAreas;
+                this.altRowStyles = parent.altRowStyles;
                 
                 //these are done below in a special way...
                 //this.fieldList = parent.fieldList;
@@ -459,6 +461,12 @@
             this.rowCountExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("row-count"));
         }
 
+        //alt-row-styles
+        for (Element altRowStyleElement : UtilXml.childElementList(formElement, "alt-row-style")){
+            AltRowStyle altRowStyle = new AltRowStyle(altRowStyleElement);
+            this.altRowStyles.add(altRowStyle);
+        }
+        
         // alt-target
         List altTargetElements = UtilXml.childElementList(formElement, "alt-target");
         Iterator altTargetElementIter = altTargetElements.iterator();
@@ -2556,6 +2564,46 @@
     public List<UpdateArea> getOnSubmitUpdateAreas() {
         return this.onSubmitUpdateAreas;
     }
+        
+    public static class AltRowStyle {
+        public String useWhen;
+        public String style;
+        public AltRowStyle(Element altRowStyleElement) {
+            this.useWhen = altRowStyleElement.getAttribute("use-when");
+            this.style = altRowStyleElement.getAttribute("style");
+        }
+    }
+    
+    /**
+     * iterate through alt-row-styles list to see if should be used, then add style
+     * @return The style for item row
+     */
+    public String getStyleAltRowStyle(Map<String, Object> context) {
+        String styles = "";
+        try {
+            // use the same Interpreter (ie with the same context setup) for all evals
+            Interpreter bsh = this.getBshInterpreter(context);
+            for (AltRowStyle altRowStyle : this.altRowStyles) {
+                Object retVal = bsh.eval(altRowStyle.useWhen);
+                // retVal should be a Boolean, if not something weird is up...
+                if (retVal instanceof Boolean) {
+                    Boolean boolVal = (Boolean) retVal;
+                    if (boolVal.booleanValue()) {
+                        styles += altRowStyle.style;
+                    }
+                } else {
+                    throw new IllegalArgumentException(
+                        "Return value from style condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + this.name);
+                }
+            }
+        } catch (EvalError e) {
+            String errmsg = "Error evaluating BeanShell style conditions on form " + this.name;
+            Debug.logError(e, errmsg, module);
+            throw new IllegalArgumentException(errmsg);
+        }
+
+        return styles;
+    }
     
     public static class AltTarget {
         public String useWhen;

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=711987&r1=711986&r2=711987&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Thu Nov  6 14:04:10 2008
@@ -1532,20 +1532,39 @@
         writer.append("  <tr");
         if (itemIndex!=null) {
             
-            if (itemIndex.intValue()%2==0) {
-               String evenRowStyle = modelForm.getEvenRowStyle();
-               if (UtilValidate.isNotEmpty(evenRowStyle)) {
-                   writer.append(" class=\"");
-                   writer.append(evenRowStyle);
-                   writer.append("\"");
+            String altRowStyles = modelForm.getStyleAltRowStyle(context);
+            if (itemIndex.intValue() % 2 == 0) {
+                String evenRowStyle = modelForm.getEvenRowStyle();
+                if (UtilValidate.isNotEmpty(evenRowStyle)) {
+                    writer.append(" class=\"");
+                    writer.append(evenRowStyle);
+                    if (UtilValidate.isNotEmpty(altRowStyles)) {
+                        writer.append(altRowStyles);
+                    }
+                    writer.append("\"");
+                } else {
+                    if (UtilValidate.isNotEmpty(altRowStyles)) {
+                        writer.append(" class=\"");
+                        writer.append(altRowStyles);
+                        writer.append("\"");
+                    }
                 }
             } else {
-                  String oddRowStyle = modelForm.getOddRowStyle();
-                  if (UtilValidate.isNotEmpty(oddRowStyle)) {
-                      writer.append(" class=\"");
-                      writer.append(oddRowStyle);
-                      writer.append("\"");
-                  }
+                String oddRowStyle = modelForm.getOddRowStyle();
+                if (UtilValidate.isNotEmpty(oddRowStyle)) {
+                    writer.append(" class=\"");
+                    writer.append(oddRowStyle);
+                    if (UtilValidate.isNotEmpty(altRowStyles)) {
+                        writer.append(altRowStyles);
+                    }
+                    writer.append("\"");
+                } else {
+                    if (UtilValidate.isNotEmpty(altRowStyles)) {
+                        writer.append(" class=\"");
+                        writer.append(altRowStyles);
+                        writer.append("\"");
+                    }
+                }
             }
         }
         writer.append(">");