=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm 2011-07-21 15:16:53 +0000 @@ -0,0 +1,23 @@ + +#macro( expandOrganisationUnit $organisationUnit ) + { + "id": $!{organisationUnit.id}, + "name": "$!encoder.jsonEncode( ${organisationUnit.name} )", + "hasChildren": #if( $organisationUnit.children.size() > 0 )true,#{else}false#end + #if( $organisationUnit.children.size() > 0 ) + "children": [ + #foreach ( $child in $organisationUnit.children ) + #expandOrganisationUnit( $child )#if( $velocityCount < $organisationUnit.children.size() ),#end + #end + ] + #end + } +#end + +{ "organisationUnits": [ + #foreach ( $organisationUnit in $organisationUnits ) + #expandOrganisationUnit( $organisationUnit ) + #if( $velocityCount < $organisationUnits.size() ),#end + #end + ] +} === added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 2011-07-21 15:16:53 +0000 @@ -0,0 +1,110 @@ +package org.hisp.dhis.commons.action; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; + +import com.opensymphony.xwork2.Action; + +/** + * @author mortenoh + */ +public class GetOrganisationUnitTreeAction + implements Action +{ + private final static int ALL = 0; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + // ------------------------------------------------------------------------- + // Comparator + // ------------------------------------------------------------------------- + + private Comparator organisationUnitComparator; + + public void setOrganisationUnitComparator( Comparator organisationUnitComparator ) + { + this.organisationUnitComparator = organisationUnitComparator; + } + + // ------------------------------------------------------------------------- + // Input & Output + // ------------------------------------------------------------------------- + + private Integer level; + + public void setLevel( Integer level ) + { + this.level = level; + } + + private List organisationUnits; + + public List getOrganisationUnits() + { + return organisationUnits; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + if ( level == null || level == ALL ) + { + organisationUnits = new ArrayList( + organisationUnitService.getOrganisationUnitsAtLevel( 1 ) ); + } + else + { + organisationUnits = new ArrayList( + organisationUnitService.getOrganisationUnitsAtLevel( level ) ); + } + + Collections.sort( organisationUnits, organisationUnitComparator ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2011-07-06 07:04:25 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2011-07-21 15:16:53 +0000 @@ -5,7 +5,7 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> - + @@ -88,7 +88,7 @@ - + @@ -184,7 +184,7 @@ - + @@ -511,6 +511,11 @@ + + + + @@ -531,7 +536,7 @@ - + @@ -539,7 +544,7 @@ - + === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml' --- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2011-07-06 07:04:25 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2011-07-21 15:16:53 +0000 @@ -6,15 +6,16 @@ - + + - + @@ -56,10 +57,10 @@ - + @@ -105,7 +106,7 @@ - + @@ -155,7 +156,7 @@ - + @@ -209,7 +210,7 @@ - + @@ -229,7 +230,7 @@ - + @@ -273,7 +274,7 @@ - + @@ -393,7 +394,7 @@ - + @@ -589,6 +590,12 @@ plainTextError + + + /dhis-web-commons/ajax/jsonOrganisationUnitTree.vm + plainTextError + + /dhis-web-commons/ajax/jsonPeriod.vm @@ -612,7 +619,7 @@ /dhis-web-commons/ajax/jsonConstants.vm plainTextError - + /dhis-web-commons/ajax/jsonResponseSuccess.vm @@ -628,7 +635,7 @@ - + @@ -637,8 +644,8 @@ - - + +