dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14373
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4867: Add/update organisation unit: Removed the feature type selection - org units are saved as points ...
------------------------------------------------------------
revno: 4867
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-10-06 20:31:41 +0200
message:
Add/update organisation unit: Removed the feature type selection - org units are saved as points as default through the user interface. Allowed for optional input of latitude and longitude which are validated as numbers. This means that users cannot enter invalid points and cannot enter polygon coordinates at all. In update screen users can only modify latitude and longitude if the org unit has no coordinates or a valid point coordinate. We will rely on automated imports for polygon coordinates.
removed:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/featureType.js
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm
--
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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2011-10-06 17:27:11 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2011-10-06 18:31:41 +0000
@@ -146,4 +146,16 @@
return matcher.find() ? matcher.group( 2 ) : null;
}
+
+ /**
+ * Returns a coordinate string based on the given latitude and longitude.
+ *
+ * @param latitude the latitude string.
+ * @param longitude the longitude string.
+ * @return a coordinate string.
+ */
+ public static String getCoordinate( String latitude, String longitude )
+ {
+ return "[" + latitude + "," + longitude + "]";
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2011-10-06 08:32:14 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2011-10-06 18:31:41 +0000
@@ -77,6 +77,12 @@
"openingDate" : {
"required" : true
},
+ "latitude" : {
+ "number" : true
+ },
+ "longitude" : {
+ "number" : true
+ },
"url" : {
"url" : true,
"rangelength" : [ 0, 255 ]
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java 2011-09-22 10:32:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java 2011-10-06 18:31:41 +0000
@@ -43,6 +43,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
import org.hisp.dhis.system.util.AttributeUtils;
+import org.hisp.dhis.system.util.ValidationUtils;
import com.opensymphony.xwork2.Action;
@@ -137,18 +138,18 @@
this.comment = comment;
}
- private String coordinates;
+ private String latitude;
- public void setCoordinates( String coordinates )
+ public void setLatitude( String latitude )
{
- this.coordinates = coordinates;
+ this.latitude = latitude;
}
- private String featureType;
+ private String longitude;
- public void setFeatureType( String featureType )
+ public void setLongitude( String longitude )
{
- this.featureType = featureType;
+ this.longitude = longitude;
}
private String url;
@@ -223,8 +224,8 @@
{
code = nullIfEmpty( code );
comment = nullIfEmpty( comment );
- coordinates = nullIfEmpty( coordinates );
- featureType = nullIfEmpty( featureType );
+ latitude = nullIfEmpty( latitude );
+ longitude = nullIfEmpty( longitude );
url = nullIfEmpty( url );
contactPerson = nullIfEmpty( contactPerson );
@@ -234,6 +235,9 @@
Date date = format.parseDate( openingDate );
+ String coordinates = latitude != null && longitude != null ?
+ ValidationUtils.getCoordinate( latitude, longitude ) : null;
+
// ---------------------------------------------------------------------
// Get parent
// ---------------------------------------------------------------------
@@ -256,7 +260,7 @@
OrganisationUnit organisationUnit = new OrganisationUnit( name, shortName, code, date, null, true, comment );
organisationUnit.setCoordinates( coordinates );
- organisationUnit.setFeatureType( featureType );
+ organisationUnit.setFeatureType( OrganisationUnit.FEATURETYPE_POINT );
organisationUnit.setUrl( url );
organisationUnit.setParent( parent );
organisationUnit.setContactPerson( contactPerson );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java 2011-10-05 15:00:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitAction.java 2011-10-06 18:31:41 +0000
@@ -45,9 +45,12 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator;
import org.hisp.dhis.system.util.AttributeUtils;
+import org.hisp.dhis.system.util.ValidationUtils;
import com.opensymphony.xwork2.Action;
+import static org.hisp.dhis.system.util.ValidationUtils.*;
+
/**
* @author Torgeir Lorange Ostby
*/
@@ -145,6 +148,27 @@
{
return attributeValues;
}
+
+ private boolean point;
+
+ public boolean isPoint()
+ {
+ return point;
+ }
+
+ private String latitude;
+
+ public String getLatitude()
+ {
+ return latitude;
+ }
+
+ private String longitude;
+
+ public String getLongitude()
+ {
+ return longitude;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -174,6 +198,14 @@
Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() );
Collections.sort( attributes, new AttributeSortOrderComparator() );
+ // ---------------------------------------------------------------------
+ // Allow update only if org unit does not have polygon coordinates
+ // ---------------------------------------------------------------------
+
+ point = organisationUnit.getCoordinates() == null || coordinateIsValid( organisationUnit.getCoordinates() );
+ latitude = ValidationUtils.getLatitude( organisationUnit.getCoordinates() );
+ longitude = ValidationUtils.getLongitude( organisationUnit.getCoordinates() );
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java 2011-09-22 10:32:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java 2011-10-06 18:31:41 +0000
@@ -46,6 +46,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.system.util.AttributeUtils;
+import org.hisp.dhis.system.util.ValidationUtils;
import com.opensymphony.xwork2.Action;
@@ -159,18 +160,18 @@
this.comment = comment;
}
- private String coordinates;
+ private String latitude;
- public void setCoordinates( String coordinates )
+ public void setLatitude( String latitude )
{
- this.coordinates = coordinates;
+ this.latitude = latitude;
}
- private String featureType;
+ private String longitude;
- public void setFeatureType( String featureType )
+ public void setLongitude( String longitude )
{
- this.featureType = featureType;
+ this.longitude = longitude;
}
private String url;
@@ -245,8 +246,8 @@
{
code = nullIfEmpty( code );
comment = nullIfEmpty( comment );
- coordinates = nullIfEmpty( coordinates );
- featureType = nullIfEmpty( featureType );
+ latitude = nullIfEmpty( latitude );
+ longitude = nullIfEmpty( longitude );
url = nullIfEmpty( url );
contactPerson = nullIfEmpty( contactPerson );
@@ -263,6 +264,9 @@
cDate = format.parseDate( closedDate );
}
+ String coordinates = latitude != null && longitude != null ?
+ ValidationUtils.getCoordinate( latitude, longitude ) : null;
+
// ---------------------------------------------------------------------
// Update organisation unit
// ---------------------------------------------------------------------
@@ -277,13 +281,12 @@
organisationUnit.setName( name );
organisationUnit.setShortName( shortName );
organisationUnit.setCode( code );
- organisationUnit.setActive( active.booleanValue() );
+ organisationUnit.setActive( active );
organisationUnit.setOpeningDate( oDate );
organisationUnit.setClosedDate( cDate );
organisationUnit.setComment( comment );
organisationUnit.setCoordinates( coordinates );
organisationUnit.setUrl( url );
- organisationUnit.setFeatureType( featureType );
organisationUnit.setContactPerson( contactPerson );
organisationUnit.setAddress( address );
organisationUnit.setEmail( email );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2011-06-23 12:53:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2011-10-06 18:31:41 +0000
@@ -83,6 +83,8 @@
url = URL
latitude = Latitude
longitude = Longitude
+latitude_optional = Latitude (optional)
+longitude_optional = Longitude (optional)
polygon_coordinates = Polygon coordinates
assign_to_compulsory_group_set = Assign to compulsory organisation unit group set
organisation_unit_group_set = Organisation unit group set
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm 2011-10-06 10:47:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/addOrganisationUnitForm.vm 2011-10-06 18:31:41 +0000
@@ -50,20 +50,14 @@
<td><label for="comment">$i18n.getString( "comment" )</label></td>
<td><textarea id="comment" name="comment" style="width:20em; height:5em"></textarea></td>
</tr>
- <tr>
- <td><label for="coordinates">$i18n.getString( "coordinates_longitude_latitude" )</label></td>
- <!-- onkeyup="setFeatureType(document.addOrganisationUnitForm.featureType, this.value)" -->
- <td><textarea id="coordinates" name="coordinates" style="width:20em; height:5em"></textarea></td>
- </tr>
- <tr>
- <td><label for="featureType">$i18n.getString( "feature_type" )</label></td>
- <td>
- <select id="featureType" name="featureType" style="min-width:20em">
- <option value="Polygon">$i18n.getString( "polygon" )</option>
- <option value="Point">$i18n.getString( "point" )</option>
- </select>
- </td>
- </tr>
+ <tr>
+ <td><label for="latitude">$i18n.getString( "latitude_optional" )</label></td>
+ <td><input type="text" id="latitude" name="latitude" style="width:20em"/></td>
+ </tr>
+ <tr>
+ <td><label for="longitude">$i18n.getString( "longitude_optional" )</label></td>
+ <td><input type="text" id="longitude" name="longitude" style="width:20em"/></td>
+ </tr>
<tr>
<td><label for="url">$i18n.getString( "url" )</label></td>
<td><input type="text" id="url" name="url" style="width:20em"/></td>
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/featureType.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/featureType.js 2010-12-16 15:32:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/featureType.js 1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
-
-// -----------------------------------------------------------------------------
-// Set feature type "Point" or "MultiPolygon" from coordinate string (no GeoJSON validation)
-// -----------------------------------------------------------------------------
-
-function setFeatureType( field, c )
-{
- field.style.color = "#000000";
- field.style.fontStyle = "normal";
-
- if ( c.length >= 2 )
- {
- if ( c.substring( 0, 1 ) == "[" && c.substring( 1, 2 ) != "[" && c.substring( c.length - 1, c.length ) == "]" && c.substring( c.length - 2, c.length - 1 ) != "]" )
- {
- field.value = "Point";
- return;
- }
-
- if ( c.length >= 8 )
- {
- if ( c.substring( 0, 4 ) == "[[[[" && c.substring( c.length - 4, c.length ) == "]]]]")
- {
- field.value = "MultiPolygon";
- return;
- }
- }
- }
-
- if ( field.value )
- {
- field.value = "";
- }
-}
-
-// -----------------------------------------------------------------------------
-// Simple feature type / coordinates field validation
-// -----------------------------------------------------------------------------
-
-function validateFeatureType( cField, fField )
-{
- if ( cField.value && ( !fField.value || fField.value == validationMessage.unrecognizedcoordinatestring ) )
- {
- fField.style.color = "#ff0000";
- fField.style.fontStyle = "italic";
- fField.value = validationMessage.unrecognizedcoordinatestring;
- return false;
- }
-
- return true;
-}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm 2011-10-06 10:47:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/updateOrganisationUnitForm.vm 2011-10-06 18:31:41 +0000
@@ -75,20 +75,16 @@
<td><label for="comment">$i18n.getString( "comment" )</label></td>
<td><textarea id="comment" name="comment" style="width:20em; height:5em">$!encoder.htmlEncode( $organisationUnit.comment )</textarea></td>
</tr>
- <tr>
- <td><label for="coordinates">$i18n.getString( "coordinates_longitude_latitude" )</label></td>
- <!-- onkeyup="setFeatureType(document.updateOrganisationUnitForm.featureType, this.value)" -->
- <td><textarea id="coordinates" name="coordinates" style="width:20em; height:5em">$!encoder.htmlEncode( $organisationUnit.coordinates )</textarea></td>
- </tr>
- <tr>
- <td><label for="featureType">$i18n.getString( "feature_type" )</label></td>
- <td>
- <select id="featureType" name="featureType" style="min-width:20em">
- <option value="Polygon" #if( $organisationUnit.featureType == $i18n.getString( "polygon" ) || $organisationUnit.featureType == $i18n.getString( "multipolygon" ) ) selected="selected" #end>$i18n.getString( "polygon" )</option>
- <option value="Point" #if( $organisationUnit.featureType == $i18n.getString( "point" ) ) selected="selected" #end>$i18n.getString( "point" )</option>
- </select>
- </td>
- </tr>
+ #if( $point )
+ <tr>
+ <td><label for="latitude">$i18n.getString( "latitude_optional" )</label></td>
+ <td><input type="text" id="latitude" name="latitude" value="$!{latitude}" style="width:20em"/></td>
+ </tr>
+ <tr>
+ <td><label for="longitude">$i18n.getString( "longitude_optional" )</label></td>
+ <td><input type="text" id="longitude" name="longitude" value="$!{longitude}" style="width:20em"/></td>
+ </tr>
+ #end
<tr>
<td><label for="url">$i18n.getString( "url" )</label></td>
<td><input type="text" id="url" name="url" value="$!encoder.htmlEncode( $organisationUnit.url )" style="width:20em"></td>
Follow ups