[fusion-commits] r1414 - sandbox/aboudreault/widgets
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Fri May 30 16:17:23 EDT 2008
Author: aboudreault
Date: 2008-05-30 16:17:23 -0400 (Fri, 30 May 2008)
New Revision: 1414
Modified:
sandbox/aboudreault/widgets/SelectionPanel.js
Log:
new abilities for the SelectionPanel widget
Modified: sandbox/aboudreault/widgets/SelectionPanel.js
===================================================================
--- sandbox/aboudreault/widgets/SelectionPanel.js 2008-05-29 14:21:40 UTC (rev 1413)
+++ sandbox/aboudreault/widgets/SelectionPanel.js 2008-05-30 20:17:23 UTC (rev 1414)
@@ -37,33 +37,232 @@
//console.log('SelectionPanel.initialize');
Fusion.Widget.prototype.initialize.apply(this, [widgetTag, false]);
-
+
this.defPrevTaskIcon = 'images/icon_back.gif';
this.defNextTaskIcon = 'images/icon_forward.gif';
var json = widgetTag.extension;
-
- this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_ON,
- OpenLayers.Function.bind(this.updateSelection, this));
- this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_OFF,
- OpenLayers.Function.bind(this.clearSelection, this));
-
+ this.iResultsPerPage = json.ResultsPerPage ? json.ResultsPerPage[0] : 0;
+ this.iResultsPerPage = parseInt(this.iResultsPerPage);
+ if (isNaN(this.iResultsPerPage))
+ this.iResultsPerPage = 0;
+
+ if (json.SelectionRenderer)
+ { // todo: use OpenLayers.Util.Try ?
+ try {
+ var renderer = eval(json.SelectionRenderer[0]);
+ if (renderer.prototype.CLASS_NAME && renderer.prototype.CLASS_NAME == "Fusion.Widget.SelectionPanel.SelectionRenderer") {
+ this.renderer = new renderer(this);
+ } else if (typeof renderer == "function") {
+ var renderFunction = renderer;
+ this.renderer = new Fusion.Widget.SelectionPanel.SelectionRenderer(this);
+ this.renderer.updateSelection = function() {
+ this.getMap().getSelection(
+ OpenLayers.Function.bind(renderFunction));
+ };
+ this.renderer.clearSelection = false;
+ }
+ }
+ catch (e) {}// this will occur if the renderer name provided is undefined.
+ } else {
+ this.renderer = new Fusion.Widget.SelectionPanel.SelectionRendererDefault(this);
+ }
+ this.iResultsPerPage = null; // handled by the renderer
+
+ if (this.renderer.updateSelection) {
+ this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_ON,
+ OpenLayers.Function.bind(this.renderer.updateSelection, this.renderer));
+ }
+
+ if (this.renderer.clearSelection) {
+ this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_OFF,
+ OpenLayers.Function.bind(this.renderer.clearSelection, this.renderer));
+ }
+ },
+});
+
+/* Class: Fusion.Widget.SelectionPanel.SelectionRenderer
+ * This is a class designed to help users to create their own renderer
+ * for customize display results.
+ */
+Fusion.Widget.SelectionPanel.SelectionRenderer = OpenLayers.Class(
+{
+ /**
+ * Property: oSelectionPanel
+ * {<Fusion.Widget.SelectionPanel>} The parent widget that uses
+ * the renderer.
+ */
+ oSelection: null,
+
+ /**
+ * Property: iCurrentIndex
+ * {int} The index of the current position for pagination
+ *
+ */
+ iCurrentIndex: 0,
+
+ /**
+ * Property: iResultsPerPage
+ * {int} The number of results per page for pagination.
+ */
+ iResultsPerPage: 0,
+
+ /* Constructor: Fusion.Widget.SelectionPanel.SelectionRenderer
+ * Constructor for a new <Fusion.Widget.SelectionPanel.SelectionRenderer> instance.
+ *
+ * Parameters:
+ * selectionPanel - {<Fusion.Widget.SelectionPanel>} The parent widget that uses
+ * the renderer.
+ */
+ initialize: function(selectionPanel) {
+ this.oSelectionPanel = selectionPanel;
+ this.iResultsPerPage = selectionPanel.iResultsPerPage;
+ },
+
+ /**
+ * Method: getNextPage
+ * Get the next batches of features. Wrapper of the getPage() method.
+ *
+ * Parameters:
+ * selectionLayer - {<Fusion.SelectionObject.Layer>} The layer that contains
+ * the set of features.
+ *
+ * Returns:
+ * {Array(Array)} An array of all features with their properties.
+ */
+ getNextPage: function(selectionLayer) {
+ if (selectionLayer && this.iCurrentIndex != selectionLayer.getNumElements()) {
+ var startIndex = 0;
+ var endIndex = selectionLayer.getNumElements();
+
+ if (this.iResultsPerPage != 0) {
+ var iTotalElement = endIndex;
+ startIndex = this.iCurrentIndex;
+ endIndex = startIndex + this.iResultsPerPage;
+ if (endIndex >= iTotalElement) {
+ endIndex = iTotalElement;
+ }
+ this.iCurrentIndex = endIndex;
+ }
+ return this.getPage(selectionLayer, startIndex, endIndex);
+ }
+ return false;
+ },
+
+ /**
+ * Method: getPreviousPage
+ * Get the previous batches of features. Wrapper of the getPage() method.
+ *
+ * Parameters:
+ * selectionLayer - {<Fusion.SelectionObject.Layer>} The layer that contains
+ * the set of features.
+ *
+ * Returns:
+ * {Array(Array)} An array of all features with their properties.
+ */
+ getPreviousPage: function(selectionLayer) {
+ var page = false;
+ if (selectionLayer && this.iCurrentIndex != 0) {
+ var page = new Array();
+ var startIndex = 0;
+ var endIndex = selectionLayer.getNumElements();
+
+ if (this.iResultsPerPage != 0) {
+ var iTotalElement = endIndex;
+ startIndex = this.iCurrentIndex - (this.iResultsPerPage * 2);
+ endIndex = this.iCurrentIndex - this.iResultsPerPage;
+ if (startIndex < 0) {
+ startIndex = 0;
+ }
+ this.iCurrentIndex = endIndex;
+ }
+ return this.getPage(selectionLayer, startIndex, endIndex);
+ }
+ return page;
+ },
+
+ /**
+ * Method: getMap
+ * Helper method to obtains the map.
+ *
+ * Returns:
+ * {<Fusion.Maps>} The map that uses the SelectionPanel Widget.
+ */
+ getMap: function() {
+ return this.oSelectionPanel.getMap();
+ },
+
+ /**
+ * Method: getPage
+ * Get a batches of features in a selection.
+ *
+ * Parameters:
+ * selectionLayer - {<Fusion.SelectionObject.Layer>} The layer that contains
+ * the set of features.
+ * startIndex - {int} The index of the first element.
+ * endIndex - {int} The index of the last element.
+ *
+ * Returns:
+ * {Array(Array)} An array of all features with their properties.
+ */
+ getPage: function(selectionLayer, startIndex, endIndex) {
+ var page = false;
+ if (selectionLayer) {
+ var page = new Array();
+ var propNames = selectionLayer.getPropertyNames();
+ var index = 0;
+ for (var i=startIndex; i<endIndex; i++, index++) {
+ for (var j=0; j<propNames.length; j++) {
+ page[index] = new Array();
+ page[index][j] = selectionLayer.getElementValue(i, j);
+ }
+ }
+ }
+ return page;
+ },
+
+ /**
+ * Method: updateSelection
+ * Abstract method that handle the event: Fusion.Event.MAP_SELECTION_ON. This method
+ * should be implemented by all concrete class.
+ */
+ updateSelection: function() {},
+
+ /**
+ * Method: clearSelection
+ * Abstract method that handle the event: Fusion.Event.MAP_SELECTION_OFF. This method
+ * should be implemented by all concrete class.
+ */
+ clearSelection: function() {},
+
+ CLASS_NAME: "Fusion.Widget.SelectionPanel.SelectionRenderer",
+});
+
+/* Class: Fusion.Widget.SelectionPanel.SelectionRendererDefault
+ * This class provide a default behavior for the selection panel.
+ *
+ */
+Fusion.Widget.SelectionPanel.SelectionRendererDefault = OpenLayers.Class(Fusion.Widget.SelectionPanel.SelectionRenderer,
+{
+ initialize : function(selectionPanel) {
+ Fusion.Widget.SelectionPanel.SelectionRenderer.prototype.initialize.apply(this, [selectionPanel]);
+
var d = document.createElement('div');
-
+
this.toolbar = document.createElement('div');
this.toolbar.className = 'selectionPanelToolbar';
-
+
this.layerList = document.createElement('select');
this.layerList.className = 'layerSelector';
this.toolbar.appendChild(this.layerList);
- Event.observe(this.layerList, 'change',
- OpenLayers.Function.bind(this.renderSelectionFeatures, this));
-
+ Event.observe(this.layerList, 'change',
+ OpenLayers.Function.bind(this.renderSelectionFeatures, this));
+
this.featureList = document.createElement('select');
this.featureList.className = 'featureSelector';
this.toolbar.appendChild(this.featureList);
- Event.observe(this.featureList, 'change',
- OpenLayers.Function.bind(this.renderFeature, this));
+ Event.observe(this.featureList, 'change',
+ OpenLayers.Function.bind(this.renderFeature, this));
this.featureDiv = document.createElement('div');
this.featureDiv.className = 'selectionPanelContent';
@@ -71,12 +270,16 @@
d.appendChild(this.toolbar);
d.appendChild(this.featureDiv);
-
- Fusion.addWidgetStyleSheet(widgetTag.location + 'SelectionPanel/SelectionPanel.css');
-
- this.domObj.appendChild(d);
+
+ Fusion.addWidgetStyleSheet(this.oSelectionPanel.getLocation() + 'SelectionPanel/SelectionPanel.css');
+ this.oSelectionPanel.domObj.appendChild(d);
+},
+
+ updateSelection: function() {
+ this.getMap().getSelection(
+ OpenLayers.Function.bind(this.renderSelectionLayers, this));
},
-
+
clearSelection: function() {
this.layerList.options.length = 0;
this.featureList.options.length = 0;
@@ -84,13 +287,7 @@
Element.addClassName(this.featureDiv, 'noSelection');
this.featureDiv.innerHTML = OpenLayers.i18n('noSelection');
},
-
- updateSelection: function() {
- //console.log('update selection');
- this.getMap().getSelection(
- OpenLayers.Function.bind(this.renderSelectionLayers, this));
- },
-
+
renderSelectionLayers: function(oSelection) {
//TODO: this just gets the first map, we need them all
this.oSelection = null;
@@ -101,6 +298,7 @@
if (!this.oSelection) {
return;
}
+
//clear the layer list select box of any previous selections
Element.removeClassName(this.featureDiv, 'noSelection');
while (this.layerList.length>0) {
@@ -124,7 +322,7 @@
this.layerList.selectedIndex = 0;
this.renderSelectionFeatures();
},
-
+
renderSelectionFeatures: function() {
var layerIdx = this.layerList.selectedIndex;
//clear the feature list select box of any previous selections
@@ -140,14 +338,14 @@
this.featureList.selectedIndex = 0;
this.renderFeature();
},
-
+
renderFeature: function() {
var layerIdx = this.layerList.selectedIndex;
var featureIdx = this.featureList.selectedIndex;
var layerObj = this.oSelection.getLayer(layerIdx);
var nProperties = layerObj.getNumProperties();
var aNames = layerObj.getPropertyNames();
-
+
var table = document.createElement('table');
var thead = document.createElement('thead');
@@ -160,7 +358,7 @@
tr.appendChild(th);
thead.appendChild(tr);
table.appendChild(thead);
-
+
var tbody = document.createElement('tbody');
table.appendChild(tbody);
for (var i=0; i<nProperties; i++) {
@@ -179,4 +377,4 @@
this.featureDiv.innerHTML = '';
this.featureDiv.appendChild(table);
}
-});
+});
\ No newline at end of file
More information about the fusion-commits
mailing list