[Commits] r1748 - core/trunk/geoext/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Thu Jan 14 22:12:15 CET 2010
Author: tschaub
Date: 2010-01-14 22:12:15 +0100 (Thu, 14 Jan 2010)
New Revision: 1748
Modified:
core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js
Log:
The text for a layer legend comes from the first truthy value in record title, record name, or layer name. r=ahocevar (closes #197)
Modified: core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js 2010-01-14 19:35:23 UTC (rev 1747)
+++ core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js 2010-01-14 21:12:15 UTC (rev 1748)
@@ -44,11 +44,9 @@
initComponent: function() {
GeoExt.LayerLegend.superclass.initComponent.call(this);
this.autoEl = {};
- var rec = this.layerRecord;
this.add({
xtype: "label",
- text: (this.showTitle && !rec.get('hideTitle')) ?
- rec.get("layer").name : '',
+ text: this.getLayerTitle(this.layerRecord),
cls: 'x-form-item x-form-item-label' +
(this.labelCls ? ' ' + this.labelCls : '')
});
@@ -58,12 +56,26 @@
* Updates the legend.
*/
update: function() {
- var rec = this.layerRecord;
- if ((this.showTitle && !rec.get('hideTitle')) &&
- (this.items.get(0).text !== rec.get('title'))) {
- // we need to update the title
- this.items.get(0).setText(rec.get('title'));
+ var title = this.getLayerTitle(this.layerRecord);
+ if (this.items.get(0).text !== title) {
+ // we need to update the title
+ this.items.get(0).setText(title);
}
+ },
+
+ /** private: method[getLayerTitle]
+ * :arg record: :class:GeoExt.data.LayerRecord
+ * :returns: ``String``
+ *
+ * Get a title for the layer. If the record doesn't have a title, use the
+ * name.
+ */
+ getLayerTitle: function(record) {
+ var title = "";
+ if (this.showTitle && !record.get("hideTitle")) {
+ title = record.get("title") || record.get("name") || record.get("layer").name || "";
+ }
+ return title;
}
});
More information about the Commits
mailing list