[fusion-commits] r3045 - trunk/widgets
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Wed Aug 29 06:45:21 PDT 2018
Author: jng
Date: 2018-08-29 06:45:21 -0700 (Wed, 29 Aug 2018)
New Revision: 3045
Modified:
trunk/widgets/SelectionPanel.js
Log:
Add support for specifying a custom date/time formatter function in the SelectionPanel widget. An example usage (format as d/m/y) would involve inserting something like this in the FUSION_INITIALIZED handler function.
Fusion.Widget.SelectionPanel.setDateTimeFormatter(function(dateStr) {
if (dateStr) {
var tokens = dateStr.split(" ");
if (tokens.length == 2) {
var dtParts = tokens[0].split("-");
var y = dtParts[0];
var m = dtParts[1];
var d = dtParts[2];
return d + "/" + m + "/" + y;
}
}
return "";
});
Fixes #663
Modified: trunk/widgets/SelectionPanel.js
===================================================================
--- trunk/widgets/SelectionPanel.js 2018-08-11 06:04:27 UTC (rev 3044)
+++ trunk/widgets/SelectionPanel.js 2018-08-29 13:45:21 UTC (rev 3045)
@@ -54,8 +54,7 @@
if (isNaN(this.iResultsPerPage) || (this.iResultsPerPage < 0))
this.iResultsPerPage = 0;
- if (json.SelectionRenderer)
- {
+ if (json.SelectionRenderer) {
var renderer = eval(json.SelectionRenderer[0]);
if (renderer && renderer.prototype.CLASS_NAME && renderer.prototype.CLASS_NAME == "Fusion.Widget.SelectionPanel.SelectionRenderer") {
this.renderer = new renderer(this);
@@ -87,6 +86,24 @@
}
});
+var PROP_TYPE_DATETIME = 3;
+
+//The date formatter function
+var _formatter = function(dateStr) { return dateStr; }
+
+/**
+ * Sets the date/time formatter function for the SelectionPanel widget.
+ *
+ * If not specified, date/time values will be presented as-is
+ *
+ * Parameters:
+ * formatter - {Function} The date/time formatter function
+ *
+ */
+Fusion.Widget.SelectionPanel.setDateTimeFormatter = function(formatter) {
+ _formatter = formatter;
+};
+
/* Class: Fusion.Widget.SelectionPanel.SelectionRenderer
* This is a class designed to help users to create their own renderer
* for customize display results.
@@ -240,11 +257,16 @@
startIndex = startIndex ? startIndex : 0;
endIndex = endIndex ? endIndex : selectionLayer.getNumElements();
var propNames = selectionLayer.getPropertyNames();
+ var propTypes = selectionLayer.getPropertyTypes();
var index =0;
for (var i=startIndex; i<endIndex; i++, index++) {
page[index] = new Array();
for (var j=0; j<propNames.length; j++) {
- page[index][j] = selectionLayer.getElementValue(i, j);
+ var fVal = selectionLayer.getElementValue(i, j);
+ if (propTypes[j] == PROP_TYPE_DATETIME) {
+ fVal = _formatter(fVal);
+ }
+ page[index][j] = fVal;
}
}
}
@@ -389,6 +411,7 @@
var layerObj = this.oSelection.getLayer(layerIdx);
var nProperties = layerObj.getNumProperties();
var aNames = layerObj.getPropertyNames();
+ var aTypes = layerObj.getPropertyTypes();
var table = document.createElement('table');
@@ -413,7 +436,11 @@
var th = document.createElement('th');
th.innerHTML = aNames[i];
var td = document.createElement('td');
- td.innerHTML = layerObj.getElementValue(featureIdx, i);
+ var fVal = layerObj.getElementValue(featureIdx, i);
+ if (aTypes[i] == PROP_TYPE_DATETIME) {
+ fVal = _formatter(fVal);
+ }
+ td.innerHTML = fVal;
tr.appendChild(th);
tr.appendChild(td);
tbody.appendChild(tr);
More information about the fusion-commits
mailing list