[Commits] r1722 - in sandbox/redlining/ux/FeatureEditing/ux/widgets: . form

commits at geoext.org commits at geoext.org
Tue Jan 12 17:44:18 CET 2010


Author: adube
Date: 2010-01-12 17:44:16 +0100 (Tue, 12 Jan 2010)
New Revision: 1722

Modified:
   sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js
Log:
FeaturePanel added, Delete button only

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-01-12 15:28:36 UTC (rev 1721)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-01-12 16:44:16 UTC (rev 1722)
@@ -367,19 +367,27 @@
         }
         */
 
+        var options = {
+          autoSave: this.autoSave,
+          features: [feature],
+          controler: this
+        };
+        var featurePanel = new GeoExt.ux.form.FeaturePanel(options);
+
         // display the popup
         var popup = new GeoExt.Popup({
             feature: feature,
             width: 200,
             title: 'EditFeature',
-            main: this
+            controler: this,
+            items: [featurePanel]
         });
         feature.popup = popup;
         popup.on({
             close: function() {
-                if(OpenLayers.Util.indexOf(this.main.activeLayer.selectedFeatures,
+                if(OpenLayers.Util.indexOf(this.controler.activeLayer.selectedFeatures,
                                            this.feature) > -1) {
-                    this.main.getSelectControl().unselect(this.feature);
+                    this.controler.getSelectControl().unselect(this.feature);
                 }
             }
         });

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js	2010-01-12 15:28:36 UTC (rev 1721)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js	2010-01-12 16:44:16 UTC (rev 1722)
@@ -64,7 +64,7 @@
      */
     map: null,
 
-    /** api: property[map]
+    /** api: property[controler]
      *  ``GeoExt.ux.FeatureEditingControler``
      */
     controler: null,
@@ -73,6 +73,11 @@
      *  ``Array(OpenLayers.Layer.Vector)``
      */
     layers: null,
+
+    /** private: property[autoSave]
+     *  ``Boolean`` Enable the auto-save of any changes made to any feature
+     */
+    autoSave: true,
     
     /** private: method[initComponent]
      */

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js	2010-01-12 15:28:36 UTC (rev 1721)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js	2010-01-12 16:44:16 UTC (rev 1722)
@@ -19,62 +19,120 @@
  *  Todo
  */
 GeoExt.ux.form.FeaturePanel = Ext.extend(Ext.form.FormPanel, {
-    
-    /** api: config[map]
-     *  ``GeoExt.MapPanel``|``OpenLayers.Map`` The map the drag control will
-     *  be added to. Optional if a layer is provided and the layer has already
-     *  been added to a map.
+
+    /** api: config[border]
+     *  ``Boolean``  Default value.
      */
-    
-    /** private: property[map]
-     *  ``OpenLayers.Map`` The map that layer and control will be added to.
+    border: false,
+
+    /** private: property[features]
+     *  ``OpenLayers.Feature.Vector`` The feature currently being edited
      */
-    map: null,
-    
+    features: null,
+
     /** api: config[layer]
-     *  ``OpenLayers.Layer.Vector`` The layer used to render extent and handle
-     *  features to. Optional, will be created if not provided.
+     *  ``OpenLayers.Layer.Vector``
+     *  The layer the features are binded to
      */
+    layer: null,
 
-    /** private: property[layer]
-     *  ``OpenLayers.Layer.Vector`` The layer used to render extent and handle
-     *  features to.
+    /** api: property[controler]
+     *  ``GeoExt.ux.FeatureEditingControler``
      */
-    layer: null,
+    controler: null,
+
+    /** private: property[autoSave]
+     *  ``Boolean`` Enable the auto-save of any changes made to the feature
+     */
+    autoSave: true,
     
+    /** api: config[deleteAction]
+     *  ``Ext.Action``  
+     *  The action created to delete the selected feature(s).
+     */
+    deleteAction: null,
+
     /** private: method[initComponent]
      */
     initComponent: function() {
+        this.initFeatures(this.features);
+        this.initToolbar();
+        this.initForm();
+
         GeoExt.ux.form.FeaturePanel.superclass.initComponent.call(this);
-        if(this.map instanceof GeoExt.MapPanel) {
-            this.map = this.map.map;
+    },
+
+    initFeatures: function(features) {
+        if(features instanceof Array) {
+            this.features = features;
+        } else {
+            this.features = [features];
         }
-        if(!this.map) {
-            this.map = this.layer.map;
-        }
+    },   
+
+    /** private: method[initToolbar]
+     *  Initialize the controls of the controler and create a toolbar from the
+     *  actions created.
+     */
+    initToolbar: function() {
+        this.initDeleteAction();
+
+        // Add buttons and toolbar
+        Ext.apply(this, {bbar: new Ext.Toolbar(this.getActions())});
     },
-    
-    /** private: method[initLayer]
+
+    /** private: method[initForm]
+     *  Create field options and link them to the controler controls and actions
      */
-    initLayer: function() {
-        if(!this.layer) {
-            this.layer = new OpenLayers.Layer.Vector(null, {
-                displayInLayerSwitcher: false
-            });
+    initForm: function() {
+        oItems = [];
+        oItems.push({
+              id: "featurepanel_id2",
+                    fieldLabel: "myOption",
+                    maxLength: 50,
+                    xtype: "checkbox"
+                });
+
+        Ext.apply(this, {items: oItems});
+    },
+
+    /** private: method[initDeleteAction]
+     *  Create a Ext.Action object that is set as the deleteAction property
+     *  and pushed to te actions array.
+     */
+    initDeleteAction: function() {
+        var action = new Ext.Action({
+            text:'Delete',
+            handler: this.deleteFeatures,
+            scope: this
+        });
+
+        this.deleteAction = action;
+    },
+
+   /** private: method[deleteFeatures]
+     *  Called when the deleteAction is triggered (button pressed).  
+     *  Destroy all features from all layers.
+     */
+    deleteFeatures: function() {
+        for(var i=0; i<this.features.length; i++) {
+            this.controler.onFeatureUnselect(this.features[i]);
+            this.features[i].layer.destroyFeatures([this.features[i]]);
         }
-        if(!this.layer.map) {
-            this.map.addLayer(this.layer);
-        }
     },
-    
+
+    getActions: function() {
+        var actions = [];
+
+        actions.push(this.deleteAction);
+
+        return actions;
+    },
+
     /** private: method[beforeDestroy]
      */
     beforeDestroy: function() {
-        if(!this.initialConfig.layer) {
-            this.layer.destroy();
-        }
-        delete this.layer;
-        delete this.map;
+        delete this.feature;
     }
     
 });

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js	2010-01-12 15:28:36 UTC (rev 1721)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js	2010-01-12 16:44:16 UTC (rev 1722)
@@ -28,12 +28,66 @@
  */
 GeoExt.ux.form.RedLiningPanel = Ext.extend(GeoExt.ux.form.FeatureEditingPanel, {
     
+    /** api: config[attributes]
+     *  ``Array(String)``
+     *  An array of attribute names to used when a blank feature is added
+     *  to the map.
+     */
+    attributes: ['title','description'],
+
+    /** api: config[layer]
+     *  ``OpenLayers.Layer.Vector``
+     *  The cosmetic OpenLayers.Layer.Vector object to work with.
+     */
+    layer: null,
+
     /** private: method[initComponent]
      */
     initComponent: function() {
-        this.layers = this.layers || new OpenLayers.Layer.Vector("Cosmetic");
+        this.initLayer(this.layer);
 
         GeoExt.ux.form.RedLiningPanel.superclass.initComponent.call(this);
+    },
+
+    /** private: method[initLayer]
+     *  :param layer: ``OpenLayers.Layer.Vector``
+     *  Create a new layer object if none was provided.  Register some events.
+     */
+    initLayer: function(layer) {
+        if(!layer){
+            layer = new OpenLayers.Layer.Vector("Cosmetic");
+        }
+
+        this.layers = [layer];
+        this.layer = layer;
+
+        layer.events.on({
+           "beforefeatureadded": this.onBeforeFeatureAdded,
+            scope: this
+        });
+    },
+
+    /** private: method[onBeforeFeatureAdded]
+     *  :param event: ``event``
+     *  Called when a new feature is added to the layer.  Check if the feature
+     *  as any attributes.  If not, add those defined in this.attributes.
+     */
+    onBeforeFeatureAdded: function(event) {
+        var feature, hasAttributes;
+
+        feature = event.feature;
+        hasAttributes = false;
+
+        for (var key in feature.attributes) {
+            hasAttributes = true;
+            break;
+        }
+
+        if(!hasAttributes) {
+            for(var i=0; i<this.attributes.length; i++) {
+                feature.attributes[this.attributes[i]] = '';
+            }
+        }
     }
     
 });



More information about the Commits mailing list