[Commits] r327 - in sandbox/opengeo/geoexplorer: . lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Thu Apr 2 19:17:31 CEST 2009
Author: tschaub
Date: 2009-04-02 19:17:31 +0200 (Thu, 02 Apr 2009)
New Revision: 327
Modified:
sandbox/opengeo/geoexplorer/lib/GeoExt/data/FeatureRecord.js
sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerRecord.js
sandbox/opengeo/geoexplorer/modifications.txt
sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/FeatureRecord.html
sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerRecord.html
Log:
Cloning feature and layer in record.copy. Patch from #34.
Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/data/FeatureRecord.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/data/FeatureRecord.js 2009-04-02 17:15:23 UTC (rev 326)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/data/FeatureRecord.js 2009-04-02 17:17:31 UTC (rev 327)
@@ -22,6 +22,24 @@
]);
/**
+ * APIMethod: copy
+ * Creates a copy of this Record.
+ *
+ * Paremters:
+ * id - {String} (optional) A new Record id.
+ *
+ * Returns:
+ * {GeoExt.data.LayerRecord} A new layer record.
+ */
+GeoExt.data.FeatureRecord.prototype.copy = function(id) {
+ var feature = this.get("feature") && this.get("feature").clone();
+ return new this.constructor(
+ Ext.applyIf({feature: feature}, this.data),
+ id || this.id
+ );
+};
+
+/**
* APIFunction: GeoExt.data.FeatureRecord.create
* Creates a constructor for a FeatureRecord, optionally with additional
* fields.
Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerRecord.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerRecord.js 2009-04-02 17:15:23 UTC (rev 326)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerRecord.js 2009-04-02 17:17:31 UTC (rev 327)
@@ -30,6 +30,24 @@
]);
/**
+ * APIMethod: copy
+ * Creates a copy of this Record.
+ *
+ * Paremters:
+ * id - {String} (optional) A new Record id.
+ *
+ * Returns:
+ * {GeoExt.data.LayerRecord} A new layer record.
+ */
+GeoExt.data.LayerRecord.prototype.copy = function(id) {
+ var layer = this.get("layer") && this.get("layer").clone();
+ return new this.constructor(
+ Ext.applyIf({layer: layer}, this.data),
+ id || this.id
+ );
+};
+
+/**
* APIFunction: GeoExt.data.LayerRecord.create
* Creates a constructor for a LayerRecord, optionally with additional
* fields.
Modified: sandbox/opengeo/geoexplorer/modifications.txt
===================================================================
--- sandbox/opengeo/geoexplorer/modifications.txt 2009-04-02 17:15:23 UTC (rev 326)
+++ sandbox/opengeo/geoexplorer/modifications.txt 2009-04-02 17:17:31 UTC (rev 327)
@@ -5,5 +5,6 @@
* Add WMSCapabilitiesReader (see #26)
* Add WMSCapabilitiesStore (see #9)
* Added examples of grid using WMSCapabilitiesStore (see #9)
+ * Clone feature and layer in record.clone (see #34)
* Merge changes from trunk up to r319
Modified: sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/FeatureRecord.html
===================================================================
--- sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/FeatureRecord.html 2009-04-02 17:15:23 UTC (rev 326)
+++ sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/FeatureRecord.html 2009-04-02 17:17:31 UTC (rev 327)
@@ -46,6 +46,25 @@
record = new c({feature: feature, state: feature.name, fid: feature.fid, foo: "bar"}, feature.id);
t.eq(record.get("foo"), "bar", "foo data row set correctly");
}
+
+ function test_copy(t) {
+
+ t.plan(2);
+
+ var feature = new OpenLayers.Feature.Vector();
+ feature.fid = "foo";
+ var recordType = GeoExt.data.FeatureRecord.create();
+
+ var record = new recordType({feature: feature, fid: feature.fid});
+ var copy = record.copy();
+
+ record.set("fid", "bar");
+ t.ok(copy.get("fid") === "foo", "setting a property on original doesn't modify copy");
+
+ t.ok(copy.get("feature") !== feature, "copy does not have original feature");
+
+ }
+
</script>
<body>
<div id="mappanel"></div>
Modified: sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerRecord.html
===================================================================
--- sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerRecord.html 2009-04-02 17:15:23 UTC (rev 326)
+++ sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerRecord.html 2009-04-02 17:17:31 UTC (rev 327)
@@ -41,6 +41,24 @@
record = new c({layer: layer, title: layer.name, foo: "bar"}, layer.id);
t.eq(record.get("foo"), "bar", "foo data row set correctly");
}
+
+ function test_copy(t) {
+
+ t.plan(2);
+
+ var layer = new OpenLayers.Layer();
+ var recordType = GeoExt.data.LayerRecord.create();
+
+ var record = new recordType({layer: layer, title: layer.name});
+ var copy = record.copy();
+
+ record.set("title", "foo");
+ t.ok(copy.get("title") !== "foo", "setting a property on original doesn't modify copy");
+
+ t.ok(copy.get("layer") !== layer, "copy does not have original layer");
+
+ }
+
</script>
<body>
<div id="mappanel"></div>
More information about the Commits
mailing list