Skip to content

Commit

Permalink
Merge pull request #246 from bartvde/keepraw2
Browse files Browse the repository at this point in the history
Add an optional keepRaw property (r=@marcjansen)
  • Loading branch information
Bart van den Eijnden committed Mar 24, 2014
2 parents 8b5b862 + 401b9cd commit 6d6a8a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/GeoExt/data/reader/WmsCapabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Ext.define('GeoExt.data.reader.WmsCapabilities', {
}
},

/**
* Should we keep the raw parsed result? Default is false.
* @cfg {Boolean}
*/
keepRaw: false,

/**
* CSS class name for the attribution DOM elements.
* Element class names append "-link", "-image", and "-title" as
Expand Down Expand Up @@ -118,6 +124,15 @@ Ext.define('GeoExt.data.reader.WmsCapabilities', {
return layer.opaque == undefined || !layer.opaque;
},

/**
* @private
*/
destroyReader: function() {
var me = this;
delete me.raw;
this.callParent();
},

/**
* Create a data block containing Ext.data.Records from an XML document.
*
Expand All @@ -140,6 +155,9 @@ Ext.define('GeoExt.data.reader.WmsCapabilities', {
if (!!data.error) {
Ext.Error.raise({msg: "Error parsing WMS GetCapabilities", arg: data.error});
}
if (this.keepRaw) {
this.raw = data;
}
var version = data.version;
var capability = data.capability || {};
var url = capability.request && capability.request.getmap &&
Expand Down
18 changes: 18 additions & 0 deletions src/GeoExt/data/reader/WmsDescribeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Ext.define('GeoExt.data.reader.WmsDescribeLayer', {
requires: [
'GeoExt.Version'
],
/**
* Should we keep the raw parsed result? Default is false.
* @cfg {Boolean}
*/
keepRaw: false,
/**
* Creates new Reader.
*
Expand Down Expand Up @@ -72,6 +77,19 @@ Ext.define('GeoExt.data.reader.WmsDescribeLayer', {
if (!!data.error) {
Ext.Error.raise({msg: "Error parsing WMS DescribeLayer", arg: data.error});
}
if (this.keepRaw) {
this.raw = data;
}
return this.callParent([data]);
},

/**
* @private
*/
destroyReader: function() {
var me = this;
delete me.raw;
this.callParent();
}

});
6 changes: 4 additions & 2 deletions tests/data/reader/WmsCapabilities.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
}

function test_read(t) {
t.plan(39);
t.plan(41);

var reader = Ext.create("GeoExt.data.reader.WmsCapabilities");
var reader = Ext.create("GeoExt.data.reader.WmsCapabilities", {keepRaw: true});
var records = reader.read({responseXML: doc, responseText: true});
t.ok(reader.raw, "raw property set when keepRaw is true");
var record = records.records[2];
t.eq(record.get("name"), "tiger:tiger_roads", "correct layer name");
reader.destroy();
Expand All @@ -58,6 +59,7 @@
}
});
records = reader.read({responseXML: doc, responseText: true});
t.ok(!reader.raw, "raw property not populated by default");
t.eq(records.totalRecords, 22, 'readRecords returns correct number of records');

var layer;
Expand Down
5 changes: 3 additions & 2 deletions tests/data/reader/WmsDescribeLayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
}

function test_read(t) {
t.plan(4);
t.plan(5);

var reader = Ext.create("GeoExt.data.reader.WmsDescribeLayer");
var reader = Ext.create("GeoExt.data.reader.WmsDescribeLayer", {keepRaw: true});

var records = reader.read({responseXML : doc, responseText: true});
t.ok(reader.raw, "When keepRaw is true, the raw property is populated");

//1 test
t.eq(records.totalRecords, 2, 'readRecords returns correct number of records');
Expand Down

0 comments on commit 6d6a8a6

Please sign in to comment.