[Commits] r2847 - in core/trunk/geoext: lib/GeoExt/plugins lib/GeoExt/widgets tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Wed Oct 5 11:24:48 CEST 2011


Author: elemoine
Date: 2011-10-05 11:24:48 +0200 (Wed, 05 Oct 2011)
New Revision: 2847

Modified:
   core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js
   core/trunk/geoext/lib/GeoExt/widgets/form.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/form.html
   core/trunk/geoext/tests/lib/GeoExt/widgets/form.js
Log:
GeoExt.form.recordToField : highlight non nillable fields, p=fvanderbiest, r=me (closes #440)

Modified: core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js	2011-10-05 08:00:33 UTC (rev 2846)
+++ core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js	2011-10-05 09:24:48 UTC (rev 2847)
@@ -76,6 +76,10 @@
      *  ``Ext.form.FormPanel`` This form panel.
      */
     formPanel: null,
+    
+    /** api: config[recordToFieldOptions]
+     *  ``Object`` Options to pass on to :function:`GeoExt.form.recordToField`.
+     */
 
     /** private: method[init]
      *  :param formPanel: class:`Ext.form.FormPanel`
@@ -135,9 +139,9 @@
      */
     fillForm: function() {
         this.attributeStore.each(function(record) {
-            var field = GeoExt.form.recordToField(record, {
+            var field = GeoExt.form.recordToField(record, Ext.apply({
                 checkboxLabelProperty: 'fieldLabel'
-            });
+            }, this.recordToFieldOptions || {}));
             if(field) {
                 this.formPanel.add(field);
             }

Modified: core/trunk/geoext/lib/GeoExt/widgets/form.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/form.js	2011-10-05 08:00:33 UTC (rev 2846)
+++ core/trunk/geoext/lib/GeoExt/widgets/form.js	2011-10-05 09:24:48 UTC (rev 2847)
@@ -92,10 +92,15 @@
 
 /** private: function[recordToField]
  *  :param record: ``Ext.data.Record``, typically from an attributeStore
- *  :param options: ``Object``, optional object litteral. Valid options are:
- *  checkboxLabelProperty - ``String`` - The name of the property used to set
+ *  :param options: ``Object``, optional object litteral. Valid options:
+ *
+ *  * checkboxLabelProperty - ``String`` The name of the property used to set
  *  the label in the checkbox. Only applies if the record is of the "boolean"
  *  type. Possible values are "boxLabel" and "fieldLabel". Default is "boxLabel".
+ *  * mandatoryFieldLabelStyle - ``String`` A CSS style specification string
+ *  to apply to the field label if the field is not nillable (that is,
+ *  the corresponding record has the "nillable" attribute set to ``false``).
+ *  Default is ``"font-weigth: bold;"``.
  *
  *  :return: ``Object`` An object literal with a xtype property, use
  *  ``Ext.ComponentMgr.create`` (or ``Ext.create`` in Ext 3) to create
@@ -120,13 +125,22 @@
     var name = record.get("name");
     var label = record.get("label");
     var restriction = record.get("restriction") || {};
-
+    var nillable = record.get("nillable") || false;
+    
     // use name for label if label isn't defined in the record
     if(label == null) {
         label = name;
     }
 
     type = type.split(":").pop(); // remove ns prefix
+    
+    var baseOptions = {
+        name: name,
+        labelStyle: nillable ? '' : 
+                        options.mandatoryFieldLabelStyle != null ? 
+                            options.mandatoryFieldLabelStyle : 
+                            'font-weight:bold;'
+    };
 
     var r = GeoExt.form.recordToField.REGEXES;
 
@@ -135,39 +149,35 @@
             parseFloat(restriction["maxLength"]) : undefined;
         var minLength = restriction["minLength"] !== undefined ?
             parseFloat(restriction["minLength"]) : undefined;
-        field = {
+        field = Ext.apply({
             xtype: "textfield",
-            name: name,
             fieldLabel: label,
             maxLength: maxLength,
             minLength: minLength
-        };
+        }, baseOptions);
     } else if(type.match(r["number"])) {
         var maxValue = restriction["maxInclusive"] !== undefined ?
             parseFloat(restriction["maxInclusive"]) : undefined;
         var minValue = restriction["minInclusive"] !== undefined ?
             parseFloat(restriction["minInclusive"]) : undefined;
-        field = {
+        field = Ext.apply({
             xtype: "numberfield",
-            name: name,
             fieldLabel: label,
             maxValue: maxValue,
             minValue: minValue
-        };
+        }, baseOptions);
     } else if(type.match(r["boolean"])) {
-        field = {
-            xtype: "checkbox",
-            name: name
-        };
+        field = Ext.apply({
+            xtype: "checkbox"
+        }, baseOptions);
         var labelProperty = options.checkboxLabelProperty || "boxLabel";
         field[labelProperty] = label;
     } else if(type.match(r["date"])) {
-        field = {
+        field = Ext.apply({
             xtype: "datefield",
             fieldLabel: label,
-            name: name,
             format: 'c'
-        };
+        }, baseOptions);
     }
 
     return field;

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/form.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/form.html	2011-10-05 08:00:33 UTC (rev 2846)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/form.html	2011-10-05 09:24:48 UTC (rev 2847)
@@ -210,7 +210,7 @@
     }
 
     function test_recordToField(t) {
-        t.plan(19);
+        t.plan(26);
 
         // set up
 
@@ -220,7 +220,7 @@
            fields: [
                {name: "name"},
                {name: "type"},
-               {name: "nillable"},
+               {name: "nillable", type: "boolean"},
                {name: "restriction"}
            ],
            ignore: {
@@ -229,23 +229,65 @@
         });
         store.loadData(doc);
 
-        // test
+        // tests
+        
+        // labelStyle
+        field = GeoExt.form.recordToField(store.getAt(1));
+        field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, '', "[label] nillable field default labelStyle is correct");
 
+        field = GeoExt.form.recordToField(store.getAt(1), {
+            mandatoryFieldLabelStyle: 'font-style:italic;'
+        });
+        field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, '', "[label] nillable field labelStyle is not overriden by the mandatoryFieldLabelStyle option");
+
         field = GeoExt.form.recordToField(store.getAt(0));
         field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, 'font-weight:bold;', "[label] non nillable field default labelStyle is correct");
+
+        field = GeoExt.form.recordToField(store.getAt(0), {
+            mandatoryFieldLabelStyle: null
+        });
+        field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, 'font-weight:bold;', "[label] non nillable field, mandatoryFieldLabelStyle set to null");
+
+        field = GeoExt.form.recordToField(store.getAt(0), {
+            mandatoryFieldLabelStyle: undefined
+        });
+        field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, 'font-weight:bold;', "[label] non nillable field, mandatoryFieldLabelStyle set to undefined");
+
+        field = GeoExt.form.recordToField(store.getAt(0), {
+            mandatoryFieldLabelStyle: ''
+        });
+        field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, '', "[label] non nillable field labelStyle is correctly overridden");
+
+        field = GeoExt.form.recordToField(store.getAt(0), {
+            mandatoryFieldLabelStyle: 'font-style:italic;'
+        });
+        field = Ext.ComponentMgr.create(field);
+        t.eq(field.labelStyle, 'font-style:italic;', "[label] non nillable field custom labelStyle is correct");
+        
+        // txt
+        field = GeoExt.form.recordToField(store.getAt(0));
+        field = Ext.ComponentMgr.create(field);
         t.ok(field instanceof Ext.form.TextField, "[txt] field is a text field");
         t.eq(field.name, "STATE_NAME", "[txt] field name is correct");
         t.eq(field.allowBlank, true, "[txt] field allowBlank is correct");
         t.eq(field.maxLength, 10, "[txt] field maxLength is correct");
         t.eq(field.minLength, 5, "[txt] field minLength is correct");
-
+        
+        // num
         field = GeoExt.form.recordToField(store.getAt(1));
         field = Ext.ComponentMgr.create(field);
         t.ok(field instanceof Ext.form.NumberField, "[num] field is a number field");
         t.eq(field.name, "SAMP_POP", "[num] field name is correct");
         t.eq(field.maxValue, 10, "[num] field maxValue is correct");
         t.eq(field.minValue, 5, "[num] field minValue is correct");
-
+        
+        // boolean
         field = GeoExt.form.recordToField(store.getAt(2), {checkboxLabelProperty: 'fieldLabel'});
         field = Ext.ComponentMgr.create(field);
         t.ok(field instanceof Ext.form.Checkbox, "[bool] field is a checkbox");
@@ -257,6 +299,7 @@
         t.ok(field.boxLabel === "BOOLEAN" && field.fieldLabel === undefined,
             "[bool] field with no option has correct boxLabel and no fieldLabel");
 
+        // datetime
         field = GeoExt.form.recordToField(store.getAt(3));
         field = Ext.ComponentMgr.create(field);
         t.ok(field instanceof Ext.form.DateField, "[datetime] field is a checkbox");
@@ -264,6 +307,7 @@
         field.setValue("2001-10-26T21:32:52+02:00");
         t.ok(field.getValue() instanceof Date, "[datetime] getValue returns a Date");
 
+        // date
         field = GeoExt.form.recordToField(store.getAt(4));
         field = Ext.ComponentMgr.create(field);
         t.ok(field instanceof Ext.form.DateField, "[date] field is a checkbox");

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/form.js
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/form.js	2011-10-05 08:00:33 UTC (rev 2846)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/form.js	2011-10-05 09:24:48 UTC (rev 2847)
@@ -7,7 +7,7 @@
       '<xsd:extension base="gml:AbstractFeatureType">' +
         '<xsd:sequence>' +
           '<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiSurfacePropertyType"/>' +
-          '<xsd:element maxOccurs="1" minOccurs="0" name="STATE_NAME" nillable="true">' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="STATE_NAME" nillable="false">' +
             '<xsd:simpleType>' +
               '<xsd:restriction base="xsd:string">' +
                 '<xsd:maxLength value="10"/>' +



More information about the Commits mailing list