[Commits] r2635 - in sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux: . widgets widgets/grid
commits at geoext.org
commits at geoext.org
Thu Mar 24 17:06:52 CET 2011
Author: adube
Date: 2011-03-24 17:06:52 +0100 (Thu, 24 Mar 2011)
New Revision: 2635
Added:
sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/grid/
sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/grid/FeatureGrid.js
Modified:
sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/WFSTFeatureEditing.js
sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js
Log:
WFSTFeatureEditing - FeatureGrid added (from OpenGeo gxp), added in TapPanel with FeatureStore and FeatureSelectionModel
Modified: sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/WFSTFeatureEditing.js
===================================================================
--- sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/WFSTFeatureEditing.js 2011-03-24 08:03:55 UTC (rev 2634)
+++ sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/WFSTFeatureEditing.js 2011-03-24 16:06:52 UTC (rev 2635)
@@ -54,7 +54,8 @@
var jsfiles = new Array(
"widgets/WFSTFeatureEditingManager.js",
"widgets/WFSTFeatureEditingPanel.js",
- "widgets/WFSTFeatureEditingStatusBar.js"
+ "widgets/WFSTFeatureEditingStatusBar.js",
+ "widgets/grid/FeatureGrid.js"
);
var agent = navigator.userAgent;
Modified: sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js
===================================================================
--- sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js 2011-03-24 08:03:55 UTC (rev 2634)
+++ sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js 2011-03-24 16:06:52 UTC (rev 2635)
@@ -135,14 +135,12 @@
// === featureGrid and featureEditorGrid containers, mainPanel ===
- this.featureGridContainer = new Ext.Panel({
- "title": this.featureGridContainerTitleText,
+ this.featureGridContainer = new Ext.TabPanel({
"border": true,
"width": 300,
"region": "west",
"resizable": true,
- "collapsible": true,
- "layout": "fit"
+ "collapsible": true
});
this.featureEditorGridContainer = new Ext.Panel({
@@ -239,9 +237,11 @@
format.setNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
var describe = format.read(response.responseXML);
+ var fields = [];
if (describe && describe.featureTypes && describe.featureTypes[0]) {
Ext.each(describe.featureTypes[0].properties, function(property, index) {
+ fields.push({"name": property.name});
if (property.name == this.manager.geomProperty) {
var geomType;
switch (property.localType) {
@@ -276,10 +276,10 @@
OpenLayers.Geometry.MultiPolygon;
break;
}
- return false;
}
}, this);
- }
+ this.layer.wfstFeatureEditing.fields = fields;
+ }
this.manager.queries++;
@@ -375,6 +375,25 @@
var selectControl = new OpenLayers.Control.SelectFeature(layer, {
clickout: false
});
+ selectControl.events.on({
+ "activate": function() {
+ this.layer.setVisibility(true);
+ this.manager.mainPanelContainer &&
+ this.manager.mainPanelContainer.expand() &&
+ this.manager.mainPanelContainer.show();
+
+ this.layer.wfstFeatureEditing.featureGrid.enable();
+ this.manager.featureGridContainer.setActiveTab(
+ this.manager.featureGridContainer.items.items.indexOf(
+ this.layer.wfstFeatureEditing.featureGrid)
+ );
+ },
+ "deactivate": function() {
+ this.layer.setVisibility(false);
+ this.layer.wfstFeatureEditing.featureGrid.disable();
+ },
+ scope: {layer: layer, manager: this}
+ });
layer.wfstFeatureEditing.selectControl = selectControl;
// =========================
@@ -387,17 +406,10 @@
});
highlightControl.events.on({
"activate": function() {
- this.setVisibility(true);
this.wfstFeatureEditing.selectControl.activate();
},
"deactivate": function() {
- this.setVisibility(false);
this.wfstFeatureEditing.selectControl.deactivate();
-
- // todo
- // if control is deactivated while editing, no choice but to
- // cancel the current modifications...
- ///this.cancelEditing();
},
"beforefeaturehighlighted": function(e) {
// if hovered feature is already selected, do nothing
@@ -459,16 +471,22 @@
"featureselected" :function(e) {
var feature = e.feature;
var editorGrid = this.manager.getNewFeatureEditorGrid(feature);
-
+
// todo: is this useful ?
this.layer.wfstFeatureEditing.editorGrid = editorGrid;
-
+
this.manager.featureEditorGridContainer.add(editorGrid);
- this.manager.mainPanelContainer.doLayout();
- this.manager.mainPanelContainer.show();
+ this.manager.featureEditorGridContainer.doLayout();
},
scope: {layer: layer, manager: manager}
});
+
+ // ===========
+ // FeatureGrid
+ // ===========
+ var featureGrid = this.getNewFeatureGrid(layer);
+ this.featureGridContainer.add(featureGrid);
+ layer.wfstFeatureEditing.featureGrid = featureGrid
},
resetAll: function() {
@@ -487,23 +505,8 @@
return wmsLayerSibling;
},
- getNewFeatureGrid: function() {
- },
-
getNewFeatureEditorGrid: function(feature) {
- var layer = feature.layer;
- var params = Ext.applyIf(Ext.applyIf(
- this.describeFeatureTypeParams || {},
- this.DEFAULT_DESCRIBE_FEATURETYPE_PARAMS),
- {'TYPENAME': layer.protocol.featureType});
- var store = new GeoExt.data.AttributeStore({
- feature: feature,
- url: Ext.urlAppend(feature.layer.protocol.url,
- OpenLayers.Util.getParameterString(params)),
- ignore: this.ignoredAttributes
- });
- store.load();
-
+ var store = this.getNewAttributeStore(feature);
return new GeoExt.ux.FeatureEditorGrid({
nameField: "name",
store: store,
@@ -528,6 +531,52 @@
}); // end of return
},
+ getNewAttributeStore: function(feature) {
+ var params = Ext.applyIf(Ext.applyIf(
+ this.describeFeatureTypeParams || {},
+ this.DEFAULT_DESCRIBE_FEATURETYPE_PARAMS),
+ {'TYPENAME': feature.layer.protocol.featureType});
+ return new GeoExt.data.AttributeStore({
+ feature: feature,
+ url: Ext.urlAppend(feature.layer.protocol.url,
+ OpenLayers.Util.getParameterString(params)),
+ ignore: this.ignoredAttributes,
+ autoLoad: true
+ });
+ },
+
+ getNewFeatureGrid: function(layer) {
+ var store = this.getNewFeatureStore(layer);
+ return new gxp.grid.FeatureGrid({
+ title: layer.name,
+ disabled: true,
+ border: false,
+ layer: layer,
+ store: store,
+ ignoreFields: ["the_geom"],
+ sm: new GeoExt.grid.FeatureSelectionModel({
+ layerFromStore: true,
+ selectControl: layer.wfstFeatureEditing.selectControl,
+ listeners: {
+ beforerowselect: function(sm, row, keep, rec) {
+ // todo : validate that the currently selected record
+ // doesn't have any unsaved changes...
+ }
+ },
+ scope: this
+ })
+ });
+ },
+
+ getNewFeatureStore: function(layer) {
+ return new GeoExt.data.FeatureStore({
+ fields: layer.wfstFeatureEditing.fields,
+ layer: layer,
+ features: layer.features,
+ autoLoad: true
+ });
+ },
+
cancelEditing: function(layer) {
if (layer.wfstFeatureEditing.editorGrid) {
var feature = layer.wfstFeatureEditing.editorGrid.store.feature;
@@ -548,9 +597,7 @@
// avoid reentrance
if(!arguments.callee._in) {
arguments.callee._in = true;
- this.featureGridContainer.removeAll(true);
this.featureEditorGridContainer.removeAll(true);
- layer.wfstFeatureEditing.featureGrid = null;
layer.wfstFeatureEditing.editorGrid = null;
layer.wfstFeatureEditing.selectControl.unselectAll();
delete arguments.callee._in;
Added: sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/grid/FeatureGrid.js
===================================================================
--- sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/grid/FeatureGrid.js (rev 0)
+++ sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/grid/FeatureGrid.js 2011-03-24 16:06:52 UTC (rev 2635)
@@ -0,0 +1,202 @@
+/**
+ * Copyright (c) 2008-2011 The Open Planning Project
+ *
+ * Published under the BSD license.
+ * See https://github.com/opengeo/gxp/raw/master/license.txt for the full text
+ * of the license.
+ */
+
+/** api: (define)
+ * module = gxp.grid
+ * class = FeatureGrid
+ * base_link = `Ext.grid.GridPanel <http://extjs.com/deploy/dev/docs/?class=Ext.grid.GridPanel>`_
+ */
+Ext.namespace("gxp.grid");
+
+/** api: constructor
+ * .. class:: FeatureGrid(config)
+ *
+ * Create a new grid displaying the contents of a
+ * ``GeoExt.data.FeatureStore`` .
+ */
+gxp.grid.FeatureGrid = Ext.extend(Ext.grid.GridPanel, {
+
+ /** api: config[map]
+ * ``OpenLayers.Map`` If provided, a layer with the features from this
+ * grid will be added to the map.
+ */
+ map: null,
+
+ /** api: config[ignoreFields]
+ * ``Array`` of field names from the store's records that should not be
+ * displayed in the grid.
+ */
+ ignoreFields: null,
+
+ /** api: config[layer]
+ * ``OpenLayers.Layer.Vector``
+ * The vector layer that will be synchronized with the layer store.
+ * If the ``map`` config property is provided, this value will be ignored.
+ */
+
+ /** api: config[schema]
+ * ``GeoExt.data.AttributeStore``
+ * Optional schema for the grid. If provided, appropriate field
+ * renderers (e.g. for date or boolean fields) will be used.
+ */
+
+ /** api: config[dateFormat]
+ * ``String`` Date format. Default is the value of
+ * ``Ext.form.DateField.prototype.format``.
+ */
+
+ /** api: config[timeFormat]
+ * ``String`` Time format. Default is the value of
+ * ``Ext.form.TimeField.prototype.format``.
+ */
+
+ /** private: property[layer]
+ * ``OpenLayers.Layer.Vector`` layer displaying features from this grid's
+ * store
+ */
+ layer: null,
+
+ /** api: method[initComponent]
+ * Initializes the FeatureGrid.
+ */
+ initComponent: function(){
+ this.ignoreFields = ["feature", "state", "fid"].concat(this.ignoreFields);
+ if(this.store) {
+ this.cm = this.createColumnModel(this.store);
+ // layer automatically added if map provided, otherwise check for
+ // layer in config
+ if(this.map) {
+ this.layer = new OpenLayers.Layer.Vector(this.id + "_layer");
+ this.map.addLayer(this.layer);
+ }
+ } else {
+ this.store = new Ext.data.Store();
+ this.cm = new Ext.grid.ColumnModel({
+ columns: []
+ });
+ }
+ if(this.layer) {
+ this.sm = this.sm || new GeoExt.grid.FeatureSelectionModel({
+ layerFromStore: false,
+ layer: this.layer
+ });
+ if(this.store instanceof GeoExt.data.FeatureStore) {
+ this.store.bind(this.layer);
+ }
+ }
+ if (!this.dateFormat) {
+ this.dateFormat = Ext.form.DateField.prototype.format;
+ }
+ if (!this.timeFormat) {
+ this.timeFormat = Ext.form.TimeField.prototype.format;
+ }
+
+ gxp.grid.FeatureGrid.superclass.initComponent.call(this);
+ },
+
+ /** private: method[onDestroy]
+ * Clean up anything created here before calling super onDestroy.
+ */
+ onDestroy: function() {
+ if(this.initialConfig && this.initialConfig.map
+ && !this.initialConfig.layer) {
+ // we created the layer, let's destroy it
+ this.layer.destroy();
+ delete this.layer;
+ }
+ gxp.grid.FeatureGrid.superclass.onDestroy.apply(this, arguments);
+ },
+
+ /** api: method[setStore]
+ * :arg store: ``GeoExt.data.FeatureStore``
+ * :arg schema: ``GeoExt.data.AttributeStore`` Optional schema to
+ * determine appropriate field renderers for the grid.
+ *
+ * Sets the store for this grid, reconfiguring the column model
+ */
+ setStore: function(store, schema) {
+ if (schema) {
+ this.schema = schema;
+ }
+ if (store) {
+ if(this.store instanceof GeoExt.data.FeatureStore) {
+ this.store.unbind();
+ }
+ if(this.layer) {
+ this.layer.destroyFeatures();
+ store.bind(this.layer);
+ }
+ this.reconfigure(store, this.createColumnModel(store));
+ } else {
+ this.reconfigure(
+ new Ext.data.Store(),
+ new Ext.grid.ColumnModel({columns: []})
+ );
+ }
+ },
+
+ /** private: method[createColumnModel]
+ * :arg store: ``GeoExt.data.FeatureStore``
+ * :return: ``Ext.grid.ColumnModel``
+ */
+ createColumnModel: function(store) {
+ function getRenderer(format) {
+ return function(value) {
+ //TODO When http://trac.osgeo.org/openlayers/ticket/3131
+ // is resolved, change the 5 lines below to
+ // return value.format(format);
+ var date = value;
+ if (typeof value == "string") {
+ date = Date.parseDate(value.replace(/Z$/, ""), "c");
+ }
+ return date ? date.format(format) : value;
+ };
+ }
+ var columns = [], name, type, xtype, format, renderer;
+ (this.schema || store.fields).each(function(f) {
+ if (this.schema) {
+ name = f.get("name");
+ type = f.get("type").split(":").pop();
+ format = null;
+ switch (type) {
+ case "date":
+ format = this.dateFormat;
+ case "datetime":
+ format = format ? format : this.dateFormat + " " + this.timeFormat;
+ xtype = undefined;
+ renderer = getRenderer(format);
+ break;
+ case "boolean":
+ xtype = "booleancolumn";
+ break;
+ case "string":
+ xtype = "gridcolumn";
+ break;
+ default:
+ xtype = "numbercolumn";
+ }
+ } else {
+ name = f.name;
+ }
+ if (this.ignoreFields.indexOf(name) === -1) {
+ columns.push({
+ dataIndex: name,
+ header: name,
+ sortable: true,
+ xtype: xtype,
+ format: format,
+ renderer: xtype ? undefined : renderer
+ });
+ }
+ }, this);
+ return new Ext.grid.ColumnModel(columns);
+ }
+});
+
+/** api: xtype = gxp_featuregrid */
+Ext.reg('gxp_featuregrid', gxp.grid.FeatureGrid);
\ No newline at end of file
More information about the Commits
mailing list