[Commits] r2008 - in core/trunk/geoext: examples examples/data lib lib/GeoExt/plugins tests tests/lib/GeoExt/plugins

commits at geoext.org commits at geoext.org
Thu Mar 18 17:14:16 CET 2010


Author: elemoine
Date: 2010-03-18 17:14:16 +0100 (Thu, 18 Mar 2010)
New Revision: 2008

Added:
   core/trunk/geoext/examples/attribute-form.html
   core/trunk/geoext/examples/attribute-form.js
   core/trunk/geoext/lib/GeoExt.js.orig
   core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js
   core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.html
   core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.js
Modified:
   core/trunk/geoext/examples/data/describe_feature_type.xml
   core/trunk/geoext/lib/GeoExt.js
   core/trunk/geoext/tests/list-tests.html
Log:
form panel auto-filled from attribute store, r=bartvde,bbinet (closes #155)

Added: core/trunk/geoext/examples/attribute-form.html
===================================================================
--- core/trunk/geoext/examples/attribute-form.html	                        (rev 0)
+++ core/trunk/geoext/examples/attribute-form.html	2010-03-18 16:14:16 UTC (rev 2008)
@@ -0,0 +1,25 @@
+<html>
+    <head>
+        <title>Attribute Form</title>
+
+        <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css" />
+        <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
+        <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+        <script type="text/javascript" src="attribute-form.js"></script>
+
+    </head>
+    <body>
+        <h1>Attribute Form</h1>
+
+        <p>This example shows how to create a form with fields creates from
+        attributes read from a WFS DescribeFeatureType response. This can be
+        useful when doing feature editing with WFS-T.</p>
+
+        <p>Note that the js is not minified so it is readable.
+        See <a href="attribute-form.js">attribute-form.js</a>.</p>
+
+    </body>
+</html>

Added: core/trunk/geoext/examples/attribute-form.js
===================================================================
--- core/trunk/geoext/examples/attribute-form.js	                        (rev 0)
+++ core/trunk/geoext/examples/attribute-form.js	2010-03-18 16:14:16 UTC (rev 2008)
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+var form;
+
+Ext.onReady(function() {
+    Ext.QuickTips.init();
+
+    // create attributes store
+    var attributeStore = new GeoExt.data.AttributeStore({
+        url: "data/describe_feature_type.xml"
+    });
+
+    form = new Ext.form.FormPanel({
+        renderTo: document.body,
+        autoScroll: true,
+        height: 300,
+        width: 350,
+        defaults: {
+            width: 120,
+            maxLengthText: "too long",
+            minLengthText: "too short"
+        },
+        plugins: [
+            new GeoExt.plugins.AttributeForm({
+                attributeStore: attributeStore
+            })
+        ]
+    });
+
+    attributeStore.load();
+});

Modified: core/trunk/geoext/examples/data/describe_feature_type.xml
===================================================================
--- core/trunk/geoext/examples/data/describe_feature_type.xml	2010-03-18 14:04:38 UTC (rev 2007)
+++ core/trunk/geoext/examples/data/describe_feature_type.xml	2010-03-18 16:14:16 UTC (rev 2008)
@@ -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="2147483647"/></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="2147483647"/></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="2147483647"/></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="2147483647"/></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>
\ No newline at end of file
+<?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="2147483647"/></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="2147483647"/></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="2147483647"/></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="2147483647"/></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>

Added: core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js	                        (rev 0)
+++ core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js	2010-03-18 16:14:16 UTC (rev 2008)
@@ -0,0 +1,204 @@
+/**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+Ext.namespace("GeoExt.plugins");
+
+/** api: (define)
+ *  module = GeoExt.plugins
+ *  class = AttributeForm
+ */
+
+/** api: example
+ *  Sample code showing how to use an Ext form panel as a feature
+ *  attribute form (for editing features for example).
+ *
+ *  .. code-block:: javascript
+ *
+ *      var formPanel = new Ext.form.FormPanel({
+ *          autoScroll: true,
+ *          height: 300,
+ *          width: 350,
+ *          defaults: {
+ *              maxLengthText: "too long",
+ *              minLengthText: "too short"
+ *          }
+ *          plugins: [
+ *              new GeoExt.plugins.AttributeForm({
+ *                  attributeStore: new GeoExt.data.AttributeStore({
+ *                      url: "http://some.wfs",
+ *                      baseParams: {
+ *                          "SERVICE": "WFS",
+ *                          "VERSION": "1.1.0",
+ *                          "REQUEST": "DescribeFeatureType",
+ *                          "TYPENAME": "the_typename"
+ *                      }
+ *                  })
+ *              })
+ *          ]
+ *      });
+ */
+
+/** api: constructor
+ *  .. class:: AttributeForm
+ *
+ *  This plugin allows creating form items from attribute records
+ *  and fill a form panel with these items.
+ */
+
+GeoExt.plugins.AttributeForm = function(config) {
+    Ext.apply(this, config);
+};
+
+GeoExt.plugins.AttributeForm.prototype = {
+
+    /** api: config[attributeStore]
+     *  ``Ext.data.Store`` The attribute store to bind to this plugin.
+     *  It can be any Ext store configured with a
+     *  :class:`GeoExt.data.AttributeReader`. If set form items
+     *  will be created from the attribute records in the form. In
+     *  most cases this store will be a :class:`GeoExt.data.AttributeStore`.
+     */
+    /** private: property[attributeStore]
+     *  ``Ext.data.Store`` The attribute store.
+     */
+    attributeStore: null,
+
+    /** private: property[formPanel]
+     *  ``Ext.form.FormPanel`` This form panel.
+     */
+    formPanel: null,
+
+    /** private: property[regExes]
+     *  ``Object`` Regular expressions for determining what type
+     *  of field to create from an attribute record.
+     */
+    regExes: {
+        "text": new RegExp(
+            "^(string)$", "i"
+        ),
+        "number": new RegExp(
+            "^(float|decimal|double|int|long|integer|short)$", "i"
+        ),
+        "boolean": new RegExp(
+            "^(boolean)$", "i"
+        ),
+        "date": new RegExp(
+            "^(dateTime)$", "i"
+        )
+    },
+
+    /** private: method[init]
+     *  :param formPanel: class:`Ext.form.FormPanel`
+     *
+     *  Initializes the plugin.
+     */
+    init: function(formPanel) {
+        this.formPanel = formPanel;
+        if(this.attributeStore instanceof Ext.data.Store) {
+            this.fillForm();
+            this.bind(this.attributeStore);
+        }
+        formPanel.on("destroy", this.onFormDestroy, this);
+    },
+
+    /** private: method[bind]
+     *  :param store: ``Ext.data.Store`` The attribute store this form panel
+     *  is to be bound to.
+     *
+     *  Bind the panel to the attribute store passed as a parameter.
+     */
+    bind: function(store) {
+        this.unbind();
+        store.on({
+            "load": this.onLoad,
+            scope: this
+        });
+        this.attributeStore = store;
+    },
+
+    /** private: method[unbind]
+     *
+     *  Unbind the panel from the attribute store it is currently bound
+     *  to, if any.
+     */
+    unbind: function() {
+        if(this.attributeStore) {
+            this.attributeStore.un("load", this.onLoad, this);
+        }
+    },
+
+    /** private: method[onLoad]
+     *
+     *  Callback called when the store is loaded.
+     */
+    onLoad: function() {
+        if(this.formPanel.items) {
+            this.formPanel.removeAll();
+        }
+        this.fillForm();
+    },
+
+    /** private: method[fillForm]
+     *
+     *  For each attribute record in the attribute store create
+     *  a form field and add it to the form.
+     */
+    fillForm: function() {
+        this.attributeStore.each(function(record) {
+            var name = record.get("name");
+            var type = record.get("type").split(":").pop(); // remove ns prefix
+            var restriction = record.get("restriction") || {};
+            if(type.match(this.regExes["text"])) {
+                var maxLength = restriction["maxLength"] !== undefined ?
+                    parseFloat(restriction["maxLength"]) : undefined;
+                var minLength = restriction["minLength"] !== undefined ?
+                    parseFloat(restriction["minLength"]) : undefined;
+                this.formPanel.add({
+                    xtype: "textfield",
+                    name: name,
+                    fieldLabel: name,
+                    maxLength: maxLength,
+                    minLength: minLength
+                });
+            } else if(type.match(this.regExes["number"])) {
+                var maxValue = restriction["maxInclusive"] !== undefined ?
+                    parseFloat(restriction["maxInclusive"]) : undefined;
+                var minValue = restriction["minInclusive"] !== undefined ?
+                    parseFloat(restriction["minInclusive"]) : undefined;
+                this.formPanel.add({
+                    xtype: "numberfield",
+                    name: name,
+                    fieldLabel: name,
+                    maxValue: maxValue,
+                    minValue: minValue
+                });
+            } else if(type.match(this.regExes["boolean"])) {
+                this.formPanel.add({
+                    xtype: "checkbox",
+                    name: name,
+                    boxLabel: name
+                });
+            } else if(type.match(this.regExes["date"])) {
+                this.formPanel.add({
+                    xtype: "datefield",
+                    fieldLabel: name,
+                    name: name
+                });
+            }
+        }, this);
+        this.formPanel.doLayout();
+    },
+
+    /** private: method[onFormDestroy]
+     */
+    onFormDestroy: function() {
+        this.unbind();
+    }
+};
+
+/** api: ptype = gx_attributeform */
+Ext.preg && Ext.preg("gx_attributeform", GeoExt.plugins.AttributeForm);

Modified: core/trunk/geoext/lib/GeoExt.js
===================================================================
--- core/trunk/geoext/lib/GeoExt.js	2010-03-18 14:04:38 UTC (rev 2007)
+++ core/trunk/geoext/lib/GeoExt.js	2010-03-18 16:14:16 UTC (rev 2008)
@@ -114,6 +114,7 @@
             "GeoExt/plugins/PrintPageField.js",
             "GeoExt/plugins/PrintProviderField.js",
             "GeoExt/plugins/PrintExtent.js",
+            "GeoExt/plugins/AttributeForm.js",
             "GeoExt/widgets/PrintMapPanel.js",
             "GeoExt/state/PermalinkProvider.js"
         );

Copied: core/trunk/geoext/lib/GeoExt.js.orig (from rev 2005, core/trunk/geoext/lib/GeoExt.js)
===================================================================
--- core/trunk/geoext/lib/GeoExt.js.orig	                        (rev 0)
+++ core/trunk/geoext/lib/GeoExt.js.orig	2010-03-18 16:14:16 UTC (rev 2008)
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ * 
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+/*
+ * The code in this file is based on code taken from OpenLayers.
+ *
+ * Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD
+ * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license.
+ */
+ 
+(function() {
+
+    /**
+     * Check to see if GeoExt.singleFile is true. It is true if the
+     * GeoExt/SingleFile.js is included before this one, as it is
+     * the case in single file builds.
+     */
+    var singleFile = (typeof GeoExt == "object" && GeoExt.singleFile);
+
+    /**
+     * The relative path of this script.
+     */
+    var scriptName = singleFile ? "GeoExt.js" : "lib/GeoExt.js";
+
+    /**
+     * Function returning the path of this script.
+     */
+    var getScriptLocation = function() {
+        var scriptLocation = "";
+        // If we load other scripts right before GeoExt using the same
+        // mechanism to add script resources dynamically (e.g. OpenLayers), 
+        // document.getElementsByTagName will not find the GeoExt script tag
+        // in FF2. Using document.documentElement.getElementsByTagName instead
+        // works around this issue.
+        var scripts = document.documentElement.getElementsByTagName('script');
+        for(var i=0, len=scripts.length; i<len; i++) {
+            var src = scripts[i].getAttribute('src');
+            if(src) {
+                var index = src.lastIndexOf(scriptName); 
+                // set path length for src up to a query string
+                var pathLength = src.lastIndexOf('?');
+                if(pathLength < 0) {
+                    pathLength = src.length;
+                }
+                // is it found, at the end of the URL?
+                if((index > -1) && (index + scriptName.length == pathLength)) {
+                    scriptLocation = src.slice(0, pathLength - scriptName.length);
+                    break;
+                }
+            }
+        }
+        return scriptLocation;
+    };
+
+    /**
+     * If GeoExt.singleFile is false then the JavaScript files in the jsfiles
+     * array are autoloaded.
+     */
+    if(!singleFile) {
+        var jsfiles = new Array(
+            "GeoExt/data/AttributeReader.js",
+            "GeoExt/data/AttributeStore.js",
+            "GeoExt/data/FeatureRecord.js",
+            "GeoExt/data/FeatureReader.js",
+            "GeoExt/data/FeatureStore.js",
+            "GeoExt/data/LayerRecord.js",
+            "GeoExt/data/LayerReader.js",
+            "GeoExt/data/LayerStore.js",
+            "GeoExt/data/ScaleStore.js",
+            "GeoExt/data/WMSCapabilitiesReader.js",
+            "GeoExt/data/WMSCapabilitiesStore.js",
+            "GeoExt/data/WFSCapabilitiesReader.js",
+            "GeoExt/data/WFSCapabilitiesStore.js",
+            "GeoExt/data/WMSDescribeLayerReader.js",
+            "GeoExt/data/WMSDescribeLayerStore.js",
+            "GeoExt/data/WMCReader.js",
+            "GeoExt/widgets/Action.js",
+            "GeoExt/data/ProtocolProxy.js",
+            "GeoExt/widgets/FeatureRenderer.js",
+            "GeoExt/widgets/MapPanel.js",
+            "GeoExt/widgets/Popup.js",
+            "GeoExt/widgets/form.js",
+            "GeoExt/widgets/form/SearchAction.js",
+            "GeoExt/widgets/form/BasicForm.js",
+            "GeoExt/widgets/form/FormPanel.js",
+            "GeoExt/widgets/tips/SliderTip.js",
+            "GeoExt/widgets/tips/LayerOpacitySliderTip.js",
+            "GeoExt/widgets/tips/ZoomSliderTip.js",
+            "GeoExt/widgets/tree/LayerNode.js",
+            "GeoExt/widgets/tree/RadioButtonMixin.js",
+            "GeoExt/widgets/tree/LayerLoader.js",
+            "GeoExt/widgets/tree/LayerContainer.js",
+            "GeoExt/widgets/tree/BaseLayerContainer.js",
+            "GeoExt/widgets/tree/OverlayLayerContainer.js",
+            "GeoExt/widgets/tree/LayerParamNode.js",
+            "GeoExt/widgets/tree/LayerParamLoader.js",
+            "GeoExt/widgets/LayerOpacitySlider.js",
+            "GeoExt/widgets/LayerLegend.js",
+            "GeoExt/widgets/LegendImage.js",
+            "GeoExt/widgets/UrlLegend.js",
+            "GeoExt/widgets/WMSLegend.js",
+            "GeoExt/widgets/VectorLegend.js",
+            "GeoExt/widgets/LegendPanel.js",
+            "GeoExt/widgets/ZoomSlider.js",
+            "GeoExt/widgets/grid/FeatureSelectionModel.js",
+            "GeoExt/data/PrintPage.js",
+            "GeoExt/data/PrintProvider.js",
+            "GeoExt/plugins/PrintPageField.js",
+            "GeoExt/plugins/PrintProviderField.js",
+            "GeoExt/plugins/PrintExtent.js",
+            "GeoExt/widgets/PrintMapPanel.js",
+            "GeoExt/state/PermalinkProvider.js"
+        );
+
+        var agent = navigator.userAgent;
+        var docWrite = (agent.match("MSIE") || agent.match("Safari"));
+        if(docWrite) {
+            var allScriptTags = new Array(jsfiles.length);
+        }
+        var host = getScriptLocation() + "lib/";    
+        for (var i=0, len=jsfiles.length; i<len; i++) {
+            if (docWrite) {
+                allScriptTags[i] = "<script src='" + host + jsfiles[i] +
+                                   "'></script>"; 
+            } else {
+                var s = document.createElement("script");
+                s.src = host + jsfiles[i];
+                var h = document.getElementsByTagName("head").length ? 
+                           document.getElementsByTagName("head")[0] : 
+                           document.body;
+                h.appendChild(s);
+            }
+        }
+        if (docWrite) {
+            document.write(allScriptTags.join(""));
+        }
+    }
+})();

Added: core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.html	                        (rev 0)
+++ core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.html	2010-03-18 16:14:16 UTC (rev 2008)
@@ -0,0 +1,183 @@
+<!DOCTYPE html>
+<html debug="true">
+  <head>
+    <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+    <script type="text/javascript" src="AttributeForm.js"></script>
+
+    <script type="text/javascript">
+    function test_constructor(t) {
+        t.plan(2);
+
+        var plugin = new GeoExt.plugins.AttributeForm({
+            attributeStore: new GeoExt.data.AttributeStore({
+               fields: [
+                   {name: "name"},
+                   {name: "type"},
+                   {name: "nillable"},
+                   {name: "restriction"}
+               ]
+            })
+        });
+
+        t.ok(plugin instanceof GeoExt.plugins.AttributeForm,
+             "constructor creates an attribute form plugin");
+        t.ok(plugin.attributeStore instanceof GeoExt.data.AttributeStore,
+             "constructor sets attribute store in instance");
+    }
+
+    function test_init(t) {
+        t.plan(6);
+
+        // Set up
+
+        var store, plugin, form;
+        var NUM_ATTR = 24;
+
+        // Test
+
+        // provide the plugin with a loaded store
+        store = new GeoExt.data.AttributeStore({
+           fields: [
+               {name: "name"},
+               {name: "type"},
+               {name: "nillable"},
+               {name: "restriction"}
+           ]
+        });
+        store.loadData(doc);
+        plugin = new GeoExt.plugins.AttributeForm({
+            attributeStore: store
+        });
+        form = new Ext.form.FormPanel({
+            renderTo: "form",
+            width: 200,
+            plugins: [plugin]
+        });
+        t.ok(plugin.formPanel == form,
+             "plugin correctly sets formPanel property when initialized");
+        t.eq(form.items.getCount(), NUM_ATTR,
+             "plugin auto-fills form when given a loaded store");
+        t.eq(store.hasListener("load"), true,
+             "plugin binds itself to store when given a loaded store");
+        form.destroy();
+
+        // provide the plugin with a non-loaded form
+        store = new GeoExt.data.AttributeStore({
+           fields: [
+               {name: "name"},
+               {name: "type"},
+               {name: "nillable"},
+               {name: "restriction"}
+           ]
+        });
+        plugin = new GeoExt.plugins.AttributeForm({
+            attributeStore: store
+        });
+        form = new Ext.form.FormPanel({
+            renderTo: "form",
+            width: 200,
+            plugins: [plugin]
+        });
+        t.eq(form.items.getCount(), 0,
+             "plugin adds no item when given a non-loaded store");
+        t.eq(store.hasListener("load"), true,
+             "plugin binds itself to store when given a non-loaded store");
+
+        // load the store
+        store.loadData(doc);
+        t.eq(form.items.getCount(), NUM_ATTR,
+             "fields are added when store is loaded");
+        form.destroy();
+    }
+
+    function test_destroy(t) {
+        t.plan(1);
+
+        // Set up
+
+        var store, plugin, form;
+
+        store = new GeoExt.data.AttributeStore({
+           fields: [
+               {name: "name"},
+               {name: "type"},
+               {name: "nillable"},
+               {name: "restriction"}
+           ]
+        });
+        plugin = new GeoExt.plugins.AttributeForm({
+            attributeStore: store
+        });
+        form = new Ext.form.FormPanel({
+            renderTo: "form",
+            width: 200,
+            plugins: [plugin]
+        });
+
+        // Test
+
+        form.destroy();
+        t.eq(store.hasListener("load"), false,
+             "destroy unbinds plugin from store");
+     }
+
+     function test_autofill(t) {
+        t.plan(13);
+
+        // Set up
+
+        var store, plugin, form, field;
+
+        store = new GeoExt.data.AttributeStore({
+           fields: [
+               {name: "name"},
+               {name: "type"},
+               {name: "nillable"},
+               {name: "restriction"}
+           ]
+        });
+        store.loadData(doc);
+        plugin = new GeoExt.plugins.AttributeForm({
+            attributeStore: store
+        });
+        form = new Ext.form.FormPanel({
+           renderTo: "form",
+           width: 200,
+            plugins: [plugin]
+        });
+
+        // Test
+
+        field = form.getComponent(0);
+        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");
+
+        field = form.getComponent(1);
+        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, "[txt] field maxValue is correct");
+        t.eq(field.minValue, 5, "[txt] field minValue is correct");
+
+        field = form.getComponent(2);
+        t.ok(field instanceof Ext.form.Checkbox, "[bool] field is a checkbox");
+        t.eq(field.name, "BOOLEAN", "[bool] field name is correct");
+
+        field = form.getComponent(3);
+        t.ok(field instanceof Ext.form.DateField, "[date] field is a checkbox");
+        t.eq(field.name, "DATE", "[date] field name is correct");
+
+        // Tear down
+
+        form.destroy();
+     }
+    </script>
+  <body>
+    <div id="form"></div>
+  </body>
+</html>

Added: core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.js
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.js	                        (rev 0)
+++ core/trunk/geoext/tests/lib/GeoExt/plugins/AttributeForm.js	2010-03-18 16:14:16 UTC (rev 2008)
@@ -0,0 +1,55 @@
+var doc = (new OpenLayers.Format.XML).read(
+'<?xml version="1.0" encoding="UTF-8"?>' +
+'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:topp="http://www.openplans.org/topp" elementFormDefault="qualified" targetNamespace="http://www.openplans.org/topp">' +
+  '<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://sigma.openplans.org:80/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>' +
+  '<xsd:complexType name="statesType">' +
+    '<xsd:complexContent>' +
+      '<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:simpleType>' +
+              '<xsd:restriction base="xsd:string">' +
+                '<xsd:maxLength value="10"/>' +
+                '<xsd:minLength value="5"/>' +
+              '</xsd:restriction>' +
+            '</xsd:simpleType>' +
+          '</xsd:element>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="SAMP_POP" nillable="true">' +
+            '<xsd:simpleType>' +
+              '<xsd:restriction base="xsd:double">' +
+                '<xsd:maxInclusive value="10"/>' +
+                '<xsd:minInclusive value="5"/>' +
+              '</xsd:restriction>' +
+            '</xsd:simpleType>' +
+          '</xsd:element>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="BOOLEAN" nillable="true" type="xsd:boolean"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="DATE" nillable="true" type="xsd:dateTime"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="STATE_FIPS" nillable="true" type="xsd:string"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="SUB_REGION" nillable="true" type="xsd:string"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="STATE_ABBR" nillable="true" type="xsd:string"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="LAND_KM" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="WATER_KM" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="PERSONS" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="FAMILIES" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="HOUSHOLD" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="MALE" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="FEMALE" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="WORKERS" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="DRVALONE" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="CARPOOL" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="PUBTRANS" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="EMPLOYED" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="UNEMPLOY" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="SERVICE" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="MANUAL" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="P_MALE" nillable="true" type="xsd:double"/>' +
+          '<xsd:element maxOccurs="1" minOccurs="0" name="P_FEMALE" nillable="true" type="xsd:double"/>' +
+        '</xsd:sequence>' +
+      '</xsd:extension>' +
+    '</xsd:complexContent>' +
+  '</xsd:complexType>' +
+  '<xsd:element name="states" substitutionGroup="gml:_Feature" type="topp:statesType"/>' +
+'</xsd:schema>'
+);
+

Modified: core/trunk/geoext/tests/list-tests.html
===================================================================
--- core/trunk/geoext/tests/list-tests.html	2010-03-18 14:04:38 UTC (rev 2007)
+++ core/trunk/geoext/tests/list-tests.html	2010-03-18 16:14:16 UTC (rev 2008)
@@ -18,6 +18,7 @@
   <li>lib/GeoExt/plugins/PrintPageField.html</li>
   <li>lib/GeoExt/plugins/PrintProviderField.html</li>
   <li>lib/GeoExt/plugins/PrintExtent.html</li>
+  <li>lib/GeoExt/plugins/AttributeForm.html</li>
   <li>lib/GeoExt/widgets/Action.html</li>
   <li>lib/GeoExt/widgets/FeatureRenderer.html</li>
   <li>lib/GeoExt/widgets/LayerOpacitySlider.html</li>



More information about the Commits mailing list