=== 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 @@ - - - - - - - - - - - + + + + + + + + === 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 @@ - - - - - - - - - - - + #if( $point ) + + + + + + + + + #end