← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 642: (GIS) Legend class breaks with decimal values now accepted. Numeric validation added, eg input: 2...

 

------------------------------------------------------------
revno: 642
committer: Jan Henrik Overland janhenrik.overland@xxxxxxxxx
branch nick: trunk
timestamp: Wed 2009-09-09 04:08:50 +0700
message:
  (GIS) Legend class breaks with decimal values now accepted. Numeric validation added, eg input: 20,",30,abc,%!'&",40 will not break the process and be submitted as 20,30,40.
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/resources/mapfish/core/GeoStat.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/resources/mapfish/core/GeoStat.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/resources/mapfish/core/GeoStat.js	2009-07-13 11:45:16 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/resources/mapfish/core/GeoStat.js	2009-09-08 21:08:50 +0000
@@ -436,6 +436,10 @@
     sturgesRule: function() {
         return Math.floor(1 + 3.3 * Math.log(this.nbVal, 10));
     },
+	
+	isNumber: function(k) {
+		return ( (typeof k === typeof 1) && (null !== k) && isFinite(k) );
+	},
 
     /**
      * Method: classify
@@ -452,35 +456,40 @@
      */
     classify: function(method, nbBins, bounds) {
     
-        if (method == 0)
-        {
+        if (method == 0) {
             var str = Ext.getCmp('bounds').getValue();
             
-            for (var i = 0; i < str.length; i++){
+            for (var i = 0; i < str.length; i++) {
                 str = str.replace(' ','');
             }
             
-            if (str.charAt(str.length-1) == ','){
+            if (str.charAt(str.length-1) == ',') {
                 str = str.substring(0, str.length-1);
             }
             
-            bounds = new Array();
+            var bounds = new Array();
             bounds = str.split(',');
-            
+			
+			for (var i = 0; i < bounds.length; i++) {
+				if (!this.isNumber(parseFloat(bounds[i]))) {
+					for (var j = i+1; j < (bounds.length); j++) {
+						bounds[j-1] = bounds[j];
+					}
+					bounds.pop();
+				}
+			}
+			
             for (var i = 0; i < bounds.length; i++)
             {
-                bounds[i] = parseInt(bounds[i]);
+				bounds[i] = parseFloat(bounds[i]);
+				if (!this.isNumber(parseFloat(bounds[i]))) {
+					alert("ikke numeric");
+				}
+					
                 
                 if (bounds[i] < this.minVal || bounds[i] > this.maxVal)
                 {
-                    Ext.Msg.show({
-                        title:'Bounds',
-                        msg: '<p style="padding-top:8px">Bounds should be within ' + this.minVal + ' -  ' + this.maxVal + '</p>',
-                        buttons: Ext.Msg.OK,
-                        animEl: 'elId',
-                        width: 250,
-                        icon: Ext.MessageBox.WARNING
-                    });
+                    Ext.messageRed.msg('Fixed bounds', 'Class breaks must be higher than ' + msg_highlight_start + this.minVal + msg_highlight_end + ' and lower than ' + msg_highlight_start + this.maxVal + msg_highlight_end + '.');
                 }
             }