------------------------------------------------------------ revno: 8324 committer: Morten Olav Hansen <[email protected]> branch nick: dhis2 timestamp: Mon 2012-10-01 21:21:41 +0700 message: add support for organisationUnits in /api/currentUser/recipients modified: dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-01 13:21:22 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-01 14:21:41 +0000 @@ -40,6 +40,7 @@ import org.hisp.dhis.message.MessageConversation; import org.hisp.dhis.message.MessageService; import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.user.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -52,10 +53,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; +import java.util.*; /** * @author Morten Olav Hansen <[email protected]> @@ -81,6 +79,9 @@ @Autowired private InterpretationService interpretationService; + @Autowired + private OrganisationUnitService organisationUnitService; + @RequestMapping public String getCurrentUser( @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception @@ -245,6 +246,7 @@ } Recipients recipients = new Recipients(); + recipients.setOrganisationUnits( getOrganisationUnitsForUser( currentUser, filter ) ); if ( filter == null || filter.isEmpty() ) { @@ -259,4 +261,33 @@ JacksonUtils.toJson( response.getOutputStream(), recipients ); } + + private Set<OrganisationUnit> getOrganisationUnitsForUser( User user, String filter ) + { + Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>(); + + for ( OrganisationUnit organisationUnit : user.getOrganisationUnits() ) + { + organisationUnits.add( organisationUnit ); + organisationUnits.addAll( organisationUnitService.getLeafOrganisationUnits( organisationUnit.getId() ) ); + } + + if ( filter != null ) + { + Iterator<OrganisationUnit> iterator = organisationUnits.iterator(); + filter = filter.toUpperCase(); + + while ( iterator.hasNext() ) + { + OrganisationUnit organisationUnit = iterator.next(); + + if ( !organisationUnit.getName().toUpperCase().contains( filter ) ) + { + iterator.remove(); + } + } + } + + return organisationUnits; + } } === modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm' --- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm 2012-10-01 13:21:22 +0000 +++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm 2012-10-01 14:21:41 +0000 @@ -3,14 +3,17 @@ function displaySelected() { + $('#selection-list').children().remove(); + $('form[role="search"] input:text').val(''); + $('#selection-list').append('<li id="organisation-unit-list" data-role="list-divider">Organisation Units</li>') - $('#selection-list').append('<li>None selected.</li>'); - $('#selection-list').append('<li id="user-list" data-role="list-divider">Users</li>') - $('#selection-list').append('<li>None selected.</li>'); - $('#selection-list').append('<li id="user-group-list" data-role="list-divider">Users Groups</li>') - $('#selection-list').append('<li>None selected.</li>'); + + // TODO use selected object to populate selected-list + $('<li>None selected.</li>').insertAfter('#organisation-unit-list'); + $('<li>None selected.</li>').insertAfter('#user-list'); + $('<li>None selected.</li>').insertAfter('#user-group-list'); $('#selection-list').listview('refresh'); } @@ -28,14 +31,15 @@ $('form[role="search"] input:text').bind('keyup', function () { var search = $('form[role="search"] input:text').val(); - $('#selection-list').children().remove(); - if( search.length == 0) { displaySelected(); return; } - else if ( search.length < 3 ) + + $('#selection-list').children().remove(); + + if ( search.length < 3 ) { return; } @@ -49,6 +53,15 @@ 'filter' : search } }).success(function ( data ) { + if( data.organisationUnits && data.organisationUnits.length > 0) + { + $('#selection-list').append('<li id="organisation-unit-list" data-role="list-divider">Organisation Units</li>') + + _(data.organisationUnits).each(function(organisationUnit) { + $('#selection-list').append('<li data-id="' + organisationUnit.id + '">' + organisationUnit.name + '</li>'); + }); + } + if( data.users && data.users.length > 0 ) { $('#selection-list').append('<li id="user-list" data-role="list-divider">Users</li>')
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

