[Commits] r2862 - in core/trunk/geoext: examples examples/data lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Wed Oct 26 10:36:57 CEST 2011
Author: fvanderbiest
Date: 2011-10-26 10:36:57 +0200 (Wed, 26 Oct 2011)
New Revision: 2862
Modified:
core/trunk/geoext/examples/attribute-form.html
core/trunk/geoext/examples/attribute-form.js
core/trunk/geoext/examples/data/describe_feature_type.xml
core/trunk/geoext/lib/GeoExt/widgets/form.js
core/trunk/geoext/tests/lib/GeoExt/widgets/form.html
Log:
GeoExt.form.recordToField: label template, r=bbinet (closes #445)
Modified: core/trunk/geoext/examples/attribute-form.html
===================================================================
--- core/trunk/geoext/examples/attribute-form.html 2011-10-25 13:03:07 UTC (rev 2861)
+++ core/trunk/geoext/examples/attribute-form.html 2011-10-26 08:36:57 UTC (rev 2862)
@@ -23,6 +23,9 @@
information read from the DescribeFeatureType document. For example the
"STATE_NAME", "STATE_FIPS", "SUB_REGION", and "STATE_ABBR" text fields
indicate errors if more than 5 characters are entered.</p>
+
+ <p>Field labels have been formatted with templates, so that a star is
+ displayed when the field is required.</p>
<p>Note that the js is not minified so it is readable.
See <a href="attribute-form.js">attribute-form.js</a>.</p>
Modified: core/trunk/geoext/examples/attribute-form.js
===================================================================
--- core/trunk/geoext/examples/attribute-form.js 2011-10-25 13:03:07 UTC (rev 2861)
+++ core/trunk/geoext/examples/attribute-form.js 2011-10-26 08:36:57 UTC (rev 2862)
@@ -35,7 +35,18 @@
},
plugins: [
new GeoExt.plugins.AttributeForm({
- attributeStore: attributeStore
+ attributeStore: attributeStore,
+ recordToFieldOptions: {
+ labelTpl: new Ext.XTemplate(
+ '{name}{[this.getStar(values)]}', {
+ compiled: true,
+ disableFormats: true,
+ getStar: function(v) {
+ return v.nillable ? '' : ' *';
+ }
+ }
+ )
+ }
})
]
});
Modified: core/trunk/geoext/examples/data/describe_feature_type.xml
===================================================================
--- core/trunk/geoext/examples/data/describe_feature_type.xml 2011-10-25 13:03:07 UTC (rev 2861)
+++ core/trunk/geoext/examples/data/describe_feature_type.xml 2011-10-26 08:36:57 UTC (rev 2862)
@@ -1 +1 @@
-<?xml version="1.0" encoding="UTF-8"?><xs:schema targetNamespace="http://www.openplans.org/topp" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0"><xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2.1/feature.xsd"/><xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" name="states_Type"><xs:complexContent><xs:extension base="gml:AbstractFeatureType"><xs:sequence><xs:element name="the_geom" minOccurs="0" nillable="true" type="gml:MultiPolygonPropertyType"/><xs:element name="STATE_NAME" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_FIPS" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="SUB_REGION" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_ABBR" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="LAND_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WATER_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PERSONS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FAMILIES" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="HOUSHOLD" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WORKERS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="DRVALONE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="CARPOOL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PUBTRANS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="EMPLOYED" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="UNEMPLOY" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SERVICE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MANUAL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SAMP_POP" minOccurs="0" nillable="true" type="xs:double"/></xs:sequence></xs:extension></xs:complexContent></xs:complexType><xs:element name="states" type="topp:states_Type" substitutionGroup="gml:_Feature"/></xs:schema>
+<?xml version="1.0" encoding="UTF-8"?><xs:schema targetNamespace="http://www.openplans.org/topp" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0"><xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2.1/feature.xsd"/><xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" name="states_Type"><xs:complexContent><xs:extension base="gml:AbstractFeatureType"><xs:sequence><xs:element name="the_geom" minOccurs="0" nillable="true" type="gml:MultiPolygonPropertyType"/><xs:element name="STATE_NAME" minOccurs="0" nillable="false"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_FIPS" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="SUB_REGION" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_ABBR" minOccurs="0" nillable="false"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="5"/></xs:restriction></xs:simpleType></xs:element><xs:element name="LAND_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WATER_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PERSONS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FAMILIES" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="HOUSHOLD" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WORKERS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="DRVALONE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="CARPOOL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PUBTRANS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="EMPLOYED" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="UNEMPLOY" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SERVICE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MANUAL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SAMP_POP" minOccurs="0" nillable="true" type="xs:double"/></xs:sequence></xs:extension></xs:complexContent></xs:complexType><xs:element name="states" type="topp:states_Type" substitutionGroup="gml:_Feature"/></xs:schema>
Modified: core/trunk/geoext/lib/GeoExt/widgets/form.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/form.js 2011-10-25 13:03:07 UTC (rev 2861)
+++ core/trunk/geoext/lib/GeoExt/widgets/form.js 2011-10-26 08:36:57 UTC (rev 2862)
@@ -101,7 +101,39 @@
* 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;"``.
+ * * labelTpl - ``Ext.Template`` or ``String`` or ``Array`` If set,
+ * the field label is obtained by applying the record's data hash to this
+ * template. This allows for very customizable field labels.
+ * See for instance :
*
+ * .. code-block:: javascript
+ *
+ * var formPanel = new Ext.form.FormPanel({
+ * autoScroll: true,
+ * plugins: [
+ * new GeoExt.plugins.AttributeForm({
+ * attributeStore: store,
+ * recordToFieldOptions: {
+ * mandatoryFieldLabelStyle: 'font-style:italic;',
+ * labelTpl: new Ext.XTemplate(
+ * '<span ext:qtip="{[this.getTip(values)]}">{name}</span>', {
+ * compiled: true,
+ * disableFormats: true,
+ * getTip: function(v) {
+ * if (!v.type) {
+ * return '';
+ * }
+ * var type = v.type.split(":").pop();
+ * return OpenLayers.i18n(type) +
+ * (v.nillable ? '' : ' (required)');
+ * }
+ * }
+ * )
+ * }
+ * })
+ * ]
+ * });
+ *
* :return: ``Object`` An object literal with a xtype property, use
* ``Ext.ComponentMgr.create`` (or ``Ext.create`` in Ext 3) to create
* an ``Ext.form.Field`` from this object.
@@ -120,19 +152,24 @@
// field, just return it
return type;
}
-
+ type = type.split(":").pop(); // remove ns prefix
+
var field;
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) {
+ var label = record.get("label");
+ var labelTpl = options.labelTpl;
+ if (labelTpl) {
+ var tpl = (labelTpl instanceof Ext.Template) ?
+ labelTpl :
+ new Ext.XTemplate(labelTpl);
+ label = tpl.apply(record.data);
+ } else if (label == null) {
+ // use name for label if label isn't defined in the record
label = name;
}
-
- type = type.split(":").pop(); // remove ns prefix
var baseOptions = {
name: name,
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/form.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/form.html 2011-10-25 13:03:07 UTC (rev 2861)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/form.html 2011-10-26 08:36:57 UTC (rev 2862)
@@ -210,7 +210,7 @@
}
function test_recordToField(t) {
- t.plan(26);
+ t.plan(28);
// set up
@@ -270,6 +270,23 @@
field = Ext.ComponentMgr.create(field);
t.eq(field.labelStyle, 'font-style:italic;', "[label] non nillable field custom labelStyle is correct");
+ // label tip
+ field = GeoExt.form.recordToField(store.getAt(0), {
+ labelTpl: new Ext.XTemplate('{name}{[this.getStar(values)]}', {
+ getStar: function(v) {
+ return (v.nillable ? '':' *');
+ }
+ })
+ });
+ field = Ext.ComponentMgr.create(field);
+ t.eq(field.fieldLabel, 'STATE_NAME *', "[label template] template is applied successfully");
+
+ field = GeoExt.form.recordToField(store.getAt(0), {
+ labelTpl: '{name} foo'
+ });
+ field = Ext.ComponentMgr.create(field);
+ t.eq(field.fieldLabel, 'STATE_NAME foo', "[label template] labelTpl accepts strings too");
+
// txt
field = GeoExt.form.recordToField(store.getAt(0));
field = Ext.ComponentMgr.create(field);
More information about the Commits
mailing list