Changeset 327


Ignore:
Timestamp:
04/02/09 19:17:31 (8 years ago)
Author:
tschaub
Message:

Cloning feature and layer in record.copy. Patch from #34.

Location:
sandbox/opengeo/geoexplorer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sandbox/opengeo/geoexplorer/lib/GeoExt/data/FeatureRecord.js

    r320 r327  
    2323
    2424/**
     25 * APIMethod: copy
     26 * Creates a copy of this Record.
     27 *
     28 * Paremters:
     29 * id - {String} (optional) A new Record id.
     30 *
     31 * Returns:
     32 * {GeoExt.data.LayerRecord} A new layer record.
     33 */
     34GeoExt.data.FeatureRecord.prototype.copy = function(id) {
     35    var feature = this.get("feature") && this.get("feature").clone();
     36    return new this.constructor(
     37        Ext.applyIf({feature: feature}, this.data),
     38        id || this.id
     39    );
     40};
     41
     42/**
    2543 * APIFunction: GeoExt.data.FeatureRecord.create
    2644 * Creates a constructor for a FeatureRecord, optionally with additional
  • sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerRecord.js

    r320 r327  
    3131
    3232/**
     33 * APIMethod: copy
     34 * Creates a copy of this Record.
     35 *
     36 * Paremters:
     37 * id - {String} (optional) A new Record id.
     38 *
     39 * Returns:
     40 * {GeoExt.data.LayerRecord} A new layer record.
     41 */
     42GeoExt.data.LayerRecord.prototype.copy = function(id) {
     43    var layer = this.get("layer") && this.get("layer").clone();
     44    return new this.constructor(
     45        Ext.applyIf({layer: layer}, this.data),
     46        id || this.id
     47    );
     48};
     49
     50/**
    3351 * APIFunction: GeoExt.data.LayerRecord.create
    3452 * Creates a constructor for a LayerRecord, optionally with additional
  • sandbox/opengeo/geoexplorer/modifications.txt

    r326 r327  
    66 * Add WMSCapabilitiesStore (see #9)
    77 * Added examples of grid using WMSCapabilitiesStore (see #9)
     8 * Clone feature and layer in record.clone (see #34)
    89 * Merge changes from trunk up to r319
    910
  • sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/FeatureRecord.html

    r320 r327  
    4747            t.eq(record.get("foo"), "bar", "foo data row set correctly");
    4848        }
     49
     50        function test_copy(t) {
     51           
     52            t.plan(2);
     53           
     54            var feature = new OpenLayers.Feature.Vector();
     55            feature.fid = "foo";
     56            var recordType = GeoExt.data.FeatureRecord.create();
     57           
     58            var record = new recordType({feature: feature, fid: feature.fid});
     59            var copy = record.copy();
     60           
     61            record.set("fid", "bar");
     62            t.ok(copy.get("fid") === "foo", "setting a property on original doesn't modify copy");
     63           
     64            t.ok(copy.get("feature") !== feature, "copy does not have original feature");
     65           
     66        }
     67
    4968    </script>
    5069  <body>
  • sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerRecord.html

    r269 r327  
    4242            t.eq(record.get("foo"), "bar", "foo data row set correctly");
    4343        }
     44       
     45        function test_copy(t) {
     46           
     47            t.plan(2);
     48           
     49            var layer = new OpenLayers.Layer();
     50            var recordType = GeoExt.data.LayerRecord.create();
     51           
     52            var record = new recordType({layer: layer, title: layer.name});
     53            var copy = record.copy();
     54           
     55            record.set("title", "foo");
     56            t.ok(copy.get("title") !== "foo", "setting a property on original doesn't modify copy");
     57           
     58            t.ok(copy.get("layer") !== layer, "copy does not have original layer");
     59           
     60        }
     61       
    4462    </script>
    4563  <body>
Note: See TracChangeset for help on using the changeset viewer.