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

commits at geoext.org commits at geoext.org
Tue Jan 19 05:15:41 CET 2010


Author: cmoullet
Date: 2010-01-19 05:15:41 +0100 (Tue, 19 Jan 2010)
New Revision: 1772

Modified:
   sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js
Log:
Add delete confirmation dialog

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-01-19 04:05:21 UTC (rev 1771)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-01-19 04:15:41 UTC (rev 1772)
@@ -7,7 +7,7 @@
 
 /** api: constructor
  *  .. class:: FeatureEditingControler(config)
- *   
+ *
  *      Create a FeatureEditing main controler.
  */
 GeoExt.ux.FeatureEditingControler = Ext.extend(Ext.util.Observable, {
@@ -31,7 +31,7 @@
     lastDrawControl: null,
 
     /** api: config[deleteAllAction]
-     *  ``Ext.Action``  
+     *  ``Ext.Action``
      *  The action created to delete all features.
      */
     deleteAllAction: null,
@@ -58,19 +58,19 @@
 
     /** api: config[activeLayer]
      *  ``OpenLayers.Layer.Vector``  The current layer being edited.
-     */    
+     */
     activeLayer: null,
 
     /** api: config[featurePanel]
      *  ``GeoExt.ux.form.FeaturePanel``
      *  A reference to the FeaturePanel object created
-     */    
+     */
     featurePanel: null,
 
     /** api: config[popup]
      *  ``GeoExt.Popup``
      *  A reference to the Popup object created
-     */    
+     */
     popup: null,
 
     /** private: property[useIcons]
@@ -82,31 +82,31 @@
 
     /** private: method[constructor]
      *  Private constructor override.
-     */    
+     */
     constructor: function(config) {
         Ext.apply(this, config);
 
         this.addEvents([
-             /** api: events[activelayerchanged]
+            /** api: events[activelayerchanged]
              *  Triggered when the active layer is changed
-             *  
+             *
              *  Listener arguments:
              */
             "activelayerchanged"
         ]);
 
-        
+
         GeoExt.ux.FeatureEditingControler.superclass.constructor.apply(this, arguments);
 
         this.layers = [];
         this.drawControls = [];
         this.actions = [];
-        
-        if(this.map instanceof GeoExt.MapPanel) {
+
+        if (this.map instanceof GeoExt.MapPanel) {
             this.map = this.map.map;
         }
 
-        if(!this.map) {
+        if (!this.map) {
             this.map = GeoExt.MapPanel.guess().map;
         }
     },
@@ -116,7 +116,7 @@
      *  For each layers, add them with the addLayer method.
      */
     addLayers: function(layers) {
-        for(var i=0; i<layers.length; i++) {
+        for (var i = 0; i < layers.length; i++) {
             this.addLayer(layers[i]);
         }
     },
@@ -127,16 +127,16 @@
      *  events for feature modification.
      */
     addLayer: function(layer) {
-        if(!layer.map) {
+        if (!layer.map) {
             this.map.addLayer(layer);
         }
         this.layers.push(layer);
 
         layer.events.on({
-           "beforefeaturemodified": this.onModificationStart,
-           "featuremodified": this.onModification,
-           "afterfeaturemodified": this.onModificationEnd,
-//           "featureunselected": this.onFeatureUnselect,
+            "beforefeaturemodified": this.onModificationStart,
+            "featuremodified": this.onModification,
+            "afterfeaturemodified": this.onModificationEnd,
+            //           "featureunselected": this.onFeatureUnselect,
             scope: this
         });
     },
@@ -162,7 +162,7 @@
         options = {};
 
         control = new OpenLayers.Control.ModifyFeature(
-            layer, options);
+                layer, options);
 
         this.featureControl = control;
         this.map.addControl(control);
@@ -180,7 +180,7 @@
             checked: false
         };
 
-        if(this.useIcons === true) {
+        if (this.useIcons === true) {
             actionOptions.iconCls = "gx-featureediting-editfeature";
         } else {
             actionOptions.text = OpenLayers.i18n("EditFeature");
@@ -198,19 +198,19 @@
     },
 
     /** private: method[initDrawControls]
-     *  Create DrawFeature controls linked to the current activeLayer and 
+     *  Create DrawFeature controls linked to the current activeLayer and
      *  depending on its geometryType property and add them to the map.
      *  GeoExt.Action are also created and pushed to the actions array.
      */
     initDrawControls: function() {
         var layer, control, handler, geometryTypes, geometryType,
-            options, action, iconCls, actionOptions, tooltip;
+                options, action, iconCls, actionOptions, tooltip;
 
         geometryTypes = [];
         options = {};
         layer = this.activeLayer;
 
-        if(OpenLayers.i18n(layer.geometryType)) {
+        if (OpenLayers.i18n(layer.geometryType)) {
             geometryTypes.push(OpenLayers.i18n(layer.geometryType));
         } else {
             geometryTypes.push(OpenLayers.i18n("Point"));
@@ -219,50 +219,50 @@
             geometryTypes.push(OpenLayers.i18n("Label"));
         }
 
-        for(var i=0; i<geometryTypes.length; i++) {
+        for (var i = 0; i < geometryTypes.length; i++) {
             geometryType = geometryTypes[i];
 
-            switch(geometryType) {
-              case OpenLayers.i18n("LineString"):
-              case OpenLayers.i18n("MultiLineString"):
-                handler = OpenLayers.Handler.Path;
-                iconCls = "gx-featureediting-draw-line";
-                tooltip = OpenLayers.i18n("Create line");
-                break;
-              case OpenLayers.i18n("Point"):
-              case OpenLayers.i18n("MultiPoint"):
-                handler = OpenLayers.Handler.Point;
-                iconCls = "gx-featureediting-draw-point";
-                tooltip = OpenLayers.i18n("Create point");
-                break;
-              case OpenLayers.i18n("Polygon"):
-              case OpenLayers.i18n("MultiPolygon"):
-                handler = OpenLayers.Handler.Polygon;
-                iconCls = "gx-featureediting-draw-polygon";
-                tooltip = OpenLayers.i18n("Create polygon");
-                break;
-              case OpenLayers.i18n("Label"):
-                handler = OpenLayers.Handler.Point;
-                iconCls = "gx-featureediting-draw-label";
-                tooltip = OpenLayers.i18n("Create label");
-                break;
+            switch (geometryType) {
+                case OpenLayers.i18n("LineString"):
+                case OpenLayers.i18n("MultiLineString"):
+                    handler = OpenLayers.Handler.Path;
+                    iconCls = "gx-featureediting-draw-line";
+                    tooltip = OpenLayers.i18n("Create line");
+                    break;
+                case OpenLayers.i18n("Point"):
+                case OpenLayers.i18n("MultiPoint"):
+                    handler = OpenLayers.Handler.Point;
+                    iconCls = "gx-featureediting-draw-point";
+                    tooltip = OpenLayers.i18n("Create point");
+                    break;
+                case OpenLayers.i18n("Polygon"):
+                case OpenLayers.i18n("MultiPolygon"):
+                    handler = OpenLayers.Handler.Polygon;
+                    iconCls = "gx-featureediting-draw-polygon";
+                    tooltip = OpenLayers.i18n("Create polygon");
+                    break;
+                case OpenLayers.i18n("Label"):
+                    handler = OpenLayers.Handler.Point;
+                    iconCls = "gx-featureediting-draw-label";
+                    tooltip = OpenLayers.i18n("Create label");
+                    break;
             }
 
             control = new OpenLayers.Control.DrawFeature(
-                layer, handler, options);
+                    layer, handler, options);
 
             this.drawControls.push(control);
             this.map.addControl(control);
 
-            if(geometryType == OpenLayers.i18n("Label")) {
+            if (geometryType == OpenLayers.i18n("Label")) {
                 control.events.on({
-                   "featureadded": this.onLabelAdded,
+                    "featureadded": this.onLabelAdded,
                     scope: this
-                });                
+                });
             }
 
             control.events.on({
-               "featureadded": this.onFeatureAdded,
+                "featureadded": this.onFeatureAdded,
                 scope: this
             });
 
@@ -280,7 +280,7 @@
             };
 
             // use icons or text for the display
-            if(this.useIcons === true) {
+            if (this.useIcons === true) {
                 actionOptions.iconCls = iconCls;
             } else {
                 actionOptions.text = geometryType;
@@ -296,7 +296,7 @@
      *  Destroy all drawControls and all their related objects.
      */
     destroyDrawControls: function() {
-        for(var i=0; i<this.drawControls.length; i++) {
+        for (var i = 0; i < this.drawControls.length; i++) {
             this.drawControls[i].destroy();
         }
         this.drawControls = [];
@@ -310,10 +310,10 @@
         var actionOptions = {
             handler: this.deleteAllFeatures,
             scope: this,
-            tooltip: OpenLayers.i18n('Delete all features')  
+            tooltip: OpenLayers.i18n('Delete all features')
         };
 
-        if(this.useIcons === true) {
+        if (this.useIcons === true) {
             actionOptions.iconCls = "gx-featureediting-delete";
         } else {
             actionOptions.text = OpenLayers.i18n('DeleteAll');
@@ -325,19 +325,24 @@
         this.actions.push(action);
     },
 
-   /** private: method[deleteAllFeatures]
-     *  Called when the deleteAllAction is triggered (button pressed).  
+    /** private: method[deleteAllFeatures]
+     *  Called when the deleteAllAction is triggered (button pressed).
      *  Destroy all features from all layers.
      */
     deleteAllFeatures: function() {
-        if(this.popup) {
-            this.popup.close();
-            this.popup = null;
-        }
+        Ext.MessageBox.confirm(OpenLayers.i18n('Delete All Features'), OpenLayers.i18n('Do you really want to delete all features ?'), function(btn) {
+            if (btn == 'yes') {
+                if (this.popup) {
+                    this.popup.close();
+                    this.popup = null;
+                }
 
-        for(var i=0; i<this.layers.length; i++) {
-            this.layers[i].destroyFeatures();
-        }
+                for (var i = 0; i < this.layers.length; i++) {
+                    this.layers[i].destroyFeatures();
+                }
+            }
+        },
+                this);
     },
 
     /** private: method[getSelectControl]
@@ -348,14 +353,14 @@
     getSelectControl: function() {
         var control = false;
 
-        switch(this.featureControl.CLASS_NAME) {
-          case "OpenLayers.Control.SelectFeature":
-            control = this.featureControl;
-            break;
-          case "OpenLayers.Control.ModifyFeature":
-          case "OpenLayers.Control.DeleteFeature":
-            control = this.featureControl.selectControl;
-            break;
+        switch (this.featureControl.CLASS_NAME) {
+            case "OpenLayers.Control.SelectFeature":
+                control = this.featureControl;
+                break;
+            case "OpenLayers.Control.ModifyFeature":
+            case "OpenLayers.Control.DeleteFeature":
+                control = this.featureControl.selectControl;
+                break;
         }
 
         return control;
@@ -369,8 +374,8 @@
     getActiveDrawControl: function() {
         var control = false;
 
-        for(var i=0; i<this.drawControls.length; i++) {
-            if(this.drawControls[i].active) {
+        for (var i = 0; i < this.drawControls.length; i++) {
+            if (this.drawControls[i].active) {
                 control = this.drawControls[i];
                 break;
             }
@@ -401,13 +406,13 @@
         feature.state = OpenLayers.State.INSERT;
 
         drawControl = this.getActiveDrawControl();
-        if(drawControl) {
+        if (drawControl) {
             drawControl.deactivate();
             this.lastDrawControl = drawControl;
         }
 
         this.featureControl.activate();
-        
+
         this.getSelectControl().select(feature);
     },
 
@@ -422,26 +427,26 @@
         // to keep the state before any modification, useful when hitting the
         // 'cancel' button
         /*
-        if(feature.state != OpenLayers.State.INSERT){
-            feature.myClone = feature.clone();
-            feature.myClone.fid = feature.fid;
-        }
-        */
+         if(feature.state != OpenLayers.State.INSERT){
+         feature.myClone = feature.clone();
+         feature.myClone.fid = feature.fid;
+         }
+         */
 
         // if the user clicked on an other feature while adding a new one,
         // deactivate the draw control.
         drawControl = this.getActiveDrawControl();
-        if(drawControl) {
+        if (drawControl) {
             drawControl.deactivate();
             this.featureControl.activate();
         }
 
         var options = {
-          autoSave: this.autoSave,
-          features: [feature],
-          controler: this,
-          useIcons: this.useIcons,
-          plugins: [new GeoExt.ux.ExportFeature()]
+            autoSave: this.autoSave,
+            features: [feature],
+            controler: this,
+            useIcons: this.useIcons,
+            plugins: [new GeoExt.ux.ExportFeature()]
 
         };
         this.featurePanel = new GeoExt.ux.form.FeaturePanel(options);
@@ -459,7 +464,7 @@
         this.popup = popup;
         popup.on({
             close: function() {
-                if(OpenLayers.Util.indexOf(this.controler.activeLayer.selectedFeatures, this.feature) > -1) {
+                if (OpenLayers.Util.indexOf(this.controler.activeLayer.selectedFeatures, this.feature) > -1) {
                     this.controler.getSelectControl().unselect(this.feature);
                 }
             }
@@ -483,13 +488,13 @@
         var feature = (event.geometry) ? event : event.feature;
         // or we could execute commits here also
 
-        if(!feature) {
+        if (!feature) {
             return;
         }
 
         this.triggerAutoSave();
 
-        if(feature.popup){
+        if (feature.popup) {
             feature.popup.close();
             feature.popup = null;
         }
@@ -500,7 +505,7 @@
     /** private: methodreactivateDrawControl[]
      */
     reactivateDrawControl: function() {
-        if(this.lastDrawControl && this.activeLayer.selectedFeatures.length === 0) {
+        if (this.lastDrawControl && this.activeLayer.selectedFeatures.length === 0) {
             this.featureControl.deactivate();
             this.lastDrawControl.activate();
             this.lastDrawControl = null;
@@ -510,7 +515,7 @@
     /** private: method[triggerAutoSave]
      */
     triggerAutoSave: function() {
-        if(this.autoSave) {
+        if (this.autoSave) {
             this.featurePanel.triggerAutoSave();
         }
     },

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js	2010-01-19 04:05:21 UTC (rev 1771)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js	2010-01-19 04:15:41 UTC (rev 1772)
@@ -1,6 +1,6 @@
 /**
  * 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.
@@ -15,7 +15,7 @@
 
 /** api: constructor
  *  .. class:: FeaturePanel
- * 
+ *
  *  Todo
  */
 GeoExt.ux.form.FeaturePanel = Ext.extend(Ext.form.FormPanel, {
@@ -85,21 +85,21 @@
      *  ``Boolean`` Enable the auto-save of any changes made to the feature
      */
     autoSave: true,
-    
+
     /** api: config[deleteAction]
-     *  ``Ext.Action``  
+     *  ``Ext.Action``
      *  The action created to delete the selected feature(s).
      */
     deleteAction: null,
 
     /** api: config[attributeFieldSetId]
-     *  ``String``  
+     *  ``String``
      *  The id used when creating the FieldSet for the attribute fields.
      */
     attributeFieldSetId: "gx_featurepanel_attributefieldset_id",
 
     /** api: config[labelAttribute]
-     *  ``String``  
+     *  ``String``
      *  The attribute name to use as a label
      */
     labelAttribute: "name",
@@ -127,7 +127,7 @@
      *  :param features: ``Array(OpenLayers.Feature.Vector)``
      */
     initFeatures: function(features) {
-        if(features instanceof Array) {
+        if (features instanceof Array) {
             this.features = features;
         } else {
             this.features = [features];
@@ -152,7 +152,7 @@
         var oItems, oGroup, feature, field, oGroupItems;
 
         // todo : for multiple features selection support, remove this...
-        if(this.features.length != 1) {
+        if (this.features.length != 1) {
             return;
         } else {
             feature = this.features[0];
@@ -171,7 +171,7 @@
             defaultType: this.defaultType
         };
 
-        for(var attribute in feature.attributes) {
+        for (var attribute in feature.attributes) {
             field = {
                 'name': attribute,
                 'fieldLabel': attribute,
@@ -199,7 +199,7 @@
             tooltip: OpenLayers.i18n('Delete feature')
         };
 
-        if(this.useIcons === true) {
+        if (this.useIcons === true) {
             actionOptions.iconCls = "gx-featureediting-delete";
         } else {
             actionOptions.text = OpenLayers.i18n('Delete');
@@ -209,21 +209,27 @@
     },
 
     /** private: method[deleteFeatures]
-     *  Called when the deleteAction is triggered (button pressed).  
+     *  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++) {
-            var feature = this.features[i];
-            if(feature.popup){
-                feature.popup.close();
-                feature.popup = null;
-            }
 
-            feature.layer.destroyFeatures([feature]);
-        }
+        Ext.MessageBox.confirm(OpenLayers.i18n('Delete Feature'), OpenLayers.i18n('Do you really want to delete this feature ?'), function(btn) {
+            if (btn == 'yes') {
+                for (var i = 0; i < this.features.length; i++) {
+                    var feature = this.features[i];
+                    if (feature.popup) {
+                        feature.popup.close();
+                        feature.popup = null;
+                    }
 
-        this.controler.reactivateDrawControl();
+                    feature.layer.destroyFeatures([feature]);
+                }
+
+                this.controler.reactivateDrawControl();
+            }
+        },
+                this);
     },
 
     /** private: method[getActions]
@@ -239,7 +245,7 @@
     /** private: method[triggerAutoSave]
      */
     triggerAutoSave: function() {
-        if(this.autoSave) {
+        if (this.autoSave) {
             this.save();
         }
     },
@@ -249,20 +255,20 @@
     save: function() {
         var feature;
 
-        if(this.features && this.features.length === 0) {
+        if (this.features && this.features.length === 0) {
             return;
         }
 
-        if(this.features.length != 1) {
+        if (this.features.length != 1) {
             return;
         } else {
             feature = this.features[0];
         }
 
         this.parseFormFieldsToFeatureAttributes(feature);
-        if(feature.isLabel === true) {
-            if(feature.attributes[this.labelAttribute] != "") {
-                feature.layer.drawFeature(feature); 
+        if (feature.isLabel === true) {
+            if (feature.attributes[this.labelAttribute] != "") {
+                feature.layer.drawFeature(feature);
             } else {
                 feature.layer.destroyFeatures([feature]);
             }
@@ -280,16 +286,16 @@
         aoElements = fieldSet.items.items;
         nElements = aoElements.length;
 
-        for (var i=0; i<nElements; i++){
+        for (var i = 0; i < nElements; i++) {
             var oElement = aoElements[i];
             var szAttribute = oElement.getName();
             var szValue = null;
             if (oElement.initialConfig.isfid)
-            { 
-                szValue = feature.fid;              
+            {
+                szValue = feature.fid;
             }
-            else  
-            { 
+            else
+            {
                 szValue = feature.attributes[szAttribute];
             }
             oElement.setValue(szValue);
@@ -301,12 +307,12 @@
      *  Copy each form field value attribute values to its corresponding
      *  attribute of a feature.
      */
-    parseFormFieldsToFeatureAttributes: function(feature){
+    parseFormFieldsToFeatureAttributes: function(feature) {
         var field, id, value, fieldSet;
 
         fieldSet = this.findById(this.attributeFieldSetId);
 
-        for(var i=0; i<fieldSet.items.length; i++){
+        for (var i = 0; i < fieldSet.items.length; i++) {
             field = fieldSet.items.get(i);
             id = field.getName();
             value = field.getValue();
@@ -320,7 +326,7 @@
     onAfterRender : function() {
         var feature;
 
-        if(this.features.length != 1) {
+        if (this.features.length != 1) {
             return;
         } else {
             feature = this.features[0];
@@ -334,7 +340,7 @@
     beforeDestroy: function() {
         delete this.feature;
     }
-    
+
 });
 
 /** api: xtype = gx_featurepanel */



More information about the Commits mailing list