[Commits] r2613 - in sandbox/camptocamp/geobretagne/lib/GeoExt: plugins widgets
commits at geoext.org
commits at geoext.org
Wed Mar 2 10:55:30 CET 2011
Author: fvanderbiest
Date: 2011-03-02 10:55:30 +0100 (Wed, 02 Mar 2011)
New Revision: 2613
Modified:
sandbox/camptocamp/geobretagne/lib/GeoExt/plugins/AttributeForm.js
sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/form.js
Log:
camptocamp/geobretagne sandbox: GeoExt.form.recordToField improvements (see #380)
Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/plugins/AttributeForm.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/plugins/AttributeForm.js 2011-03-01 14:30:18 UTC (rev 2612)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/plugins/AttributeForm.js 2011-03-02 09:55:30 UTC (rev 2613)
@@ -76,6 +76,23 @@
* ``Ext.form.FormPanel`` This form panel.
*/
formPanel: null,
+
+ /** api: config[displayFieldType]
+ * ``Boolean`` Display the field type as a quick tip (defaults to false).
+ * Quick tips need to be initialized with Ext.QuickTips.init().
+ */
+ /** private: property[displayFieldType]
+ * ``Boolean`` Display the field type as a quick tip.
+ */
+ displayFieldType: null,
+
+ /** api: config[markRequiredFields]
+ * ``Boolean`` Display required fields with bold labels.
+ */
+ /** private: property[markRequiredFields]
+ * ``Boolean`` Display required fields with bold labels.
+ */
+ markRequiredFields: null,
/** private: method[init]
* :param formPanel: class:`Ext.form.FormPanel`
@@ -135,7 +152,10 @@
*/
fillForm: function() {
this.attributeStore.each(function(record) {
- var field = GeoExt.form.recordToField(record);
+ var field = GeoExt.form.recordToField(record, {
+ displayType: this.displayFieldType,
+ markRequired: this.markRequiredFields
+ });
if(field) {
this.formPanel.add(field);
}
Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/form.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/form.js 2011-03-01 14:30:18 UTC (rev 2612)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/form.js 2011-03-02 09:55:30 UTC (rev 2613)
@@ -89,7 +89,11 @@
GeoExt.form.CONTAINS = 3;
/** private: function[recordToField]
- * :param record: ``Ext.data.Record``, typically from an attributeStore
+ * :param record: ``Ext.data.Record``, typically from an attributeStore.
+ * :param options: ``Object``, optional object litteral with keys
+ * "displayType" and "markRequired". Both are booleans. When true, the
+ * latter displays bold field labels, while the former enables display
+ * of field type as a quick tip when hovering labels.
*
* :return: ``Object`` An object literal with a xtype property, use
* ``Ext.ComponentMgr.create`` (or ``Ext.create`` in Ext 3) to create
@@ -99,71 +103,75 @@
* an ``Ext.data.Record`` containing name, type, restriction and
* label fields.
*/
-GeoExt.form.recordToField = function(record) {
+GeoExt.form.recordToField = function(record, options) {
var type = record.get("type");
-
if(typeof type === "object" && type.xtype) {
// we have an xtype'd object literal in the type
// 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") || {};
-
// 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 nillable = record.get("nillable") || false;
+ var restriction = record.get("restriction") || {};
+
+ var typeI18n = GeoExt.form.recordToField.TIPTRANSLATIONS[type] || type;
+ var qtip = typeI18n + ((!nillable && options.markRequired) ?
+ ' ('+GeoExt.form.recordToField.TIPTRANSLATIONS["required"]+')': '');
+ var baseOptions = {
+ name: name,
+ labelStyle: (!nillable && options.markRequired) ?
+ 'font-weight:bold;' : '',
+ fieldLabel: (options.displayType) ?
+ '<span ext:qtip="'+qtip+'">'+label+'</span>' : label
+ };
+
var r = GeoExt.form.recordToField.REGEXES;
-
if(type.match(r["text"])) {
var maxLength = restriction["maxLength"] !== undefined ?
parseFloat(restriction["maxLength"]) : undefined;
var minLength = restriction["minLength"] !== undefined ?
parseFloat(restriction["minLength"]) : undefined;
- field = {
+ field = Ext.apply({
xtype: "textfield",
- name: name,
- fieldLabel: label,
+ allowBlank: nillable,
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,
+ allowBlank: nillable,
+ allowNegative: !type.match(r["positiveNumbers"]),
+ allowDecimals: type.match(r["decimals"]),
maxValue: maxValue,
minValue: minValue
- };
+ }, baseOptions);
} else if(type.match(r["boolean"])) {
- field = {
- xtype: "checkbox",
- name: name,
- fieldLabel: label
- };
+ field = Ext.apply({
+ xtype: "checkbox"
+ }, baseOptions);
} else if(type.match(r["date"])) {
- field = {
+ field = Ext.apply({
xtype: "datefield",
- fieldLabel: label,
- name: name,
+ allowBlank: nillable,
format: 'c'
- };
+ }, baseOptions);
}
return field;
-}
+};
/** private: constant[REGEXES]
* ``Object`` Regular expressions for determining what type
@@ -174,8 +182,14 @@
"^(text|string)$", "i"
),
"number": new RegExp(
- "^(number|float|decimal|double|int|long|integer|short)$", "i"
+ "^(number|float|decimal|double|int|long|integer|short|byte|unsignedLong|unsignedInt|unsignedShort|unsignedByte|nonNegativeInteger|positiveInteger)$", "i"
),
+ "decimals": new RegExp(
+ "^(number|float|decimal|double)$", "i"
+ ),
+ "positiveNumbers": new RegExp(
+ "^(unsignedLong|unsignedInt|unsignedShort|unsignedByte|nonNegativeInteger|positiveInteger)$", "i"
+ ),
"boolean": new RegExp(
"^(boolean)$", "i"
),
@@ -183,3 +197,30 @@
"^(date|dateTime)$", "i"
)
};
+
+/** private: constant[TIPTRANSLATIONS]
+ * ``Object`` translation of field types.
+ */
+GeoExt.form.recordToField.TIPTRANSLATIONS = {
+ "required": "required",
+ "text": "Text",
+ "string": "String",
+ "number": "Number",
+ "float": "Float",
+ "decimal": "Decimal",
+ "double": "Double",
+ "int": "Integer",
+ "long": "Long integer",
+ "integer": "Integer",
+ "short": "Short integer",
+ "byte": "Byte",
+ "unsignedLong": "Unsigned long integer",
+ "unsignedInt": "Unsigned integer",
+ "unsignedShort": "Unsigned short integer",
+ "unsignedByte": "Unsigned byte",
+ "nonNegativeInteger": "Non negative integer",
+ "positiveInteger": "Positive integer",
+ "boolean": "Boolean",
+ "date": "Date",
+ "dateTime": "Date w/ time"
+};
More information about the Commits
mailing list