← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4328: bugfixes in ouwt

 

------------------------------------------------------------
revno: 4328
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-08-17 13:17:40 +0200
message:
  bugfixes in ouwt
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js
  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/resources/META-INF/dhis/beans.xml


--
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-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-08-15 10:35:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-08-17 11:17:40 +0000
@@ -61,7 +61,7 @@
         {
             var roots = JSON.parse( localStorage[getTagId( "Roots" )] );
 
-            if ( sessionStorage[getTagId( "Selected" )] == null )
+            if ( sessionStorage[getTagId( "Selected" )] == null && roots.length > 0 )
             {
                 if ( multipleSelectionAllowed )
                 {
@@ -110,10 +110,11 @@
                                     localStorage[getTagId( "Roots" )] = JSON.stringify( roots );
                                     localStorage[getTagId( "Version" )] = data.version;
 
-                                } ).complete( function() {
-                                    sync_and_reload();
-                                    $( "#orgUnitTree" ).trigger( "ouwtLoaded" );
-                                } );
+                                } ).complete( function()
+                        {
+                            sync_and_reload();
+                            $( "#orgUnitTree" ).trigger( "ouwtLoaded" );
+                        } );
                     }
                     else
                     {
@@ -166,32 +167,37 @@
                     return;
                 }
 
-                var selected = JSON.parse( sessionStorage[getTagId( "Selected" )] );
-
-                if ( multipleSelectionAllowed )
-                {
-                    if ( !$.isArray( selected ) )
-                    {
-                        selected = [ selected ];
-                    }
-
-                    $.each( selected, function( i, item )
-                    {
-                        $.post( organisationUnitTreePath + "addorgunit.action", {
-                            id : item
-                        } );
-                    } ).complete( this.responseReceived );
-                }
-                else
-                {
-                    if ( $.isArray( selected ) )
-                    {
-                        selected = selected[0];
-                    }
-
-                    $.post( organisationUnitTreePath + "setorgunit.action", {
-                        id : selected
-                    } ).complete( this.responseReceived );
+                var selected = sessionStorage[getTagId( "Selected" )];
+
+                if ( selected != null )
+                {
+                    selected = JSON.parse( selected );
+
+                    if ( multipleSelectionAllowed )
+                    {
+                        if ( !$.isArray( selected ) )
+                        {
+                            selected = [ selected ];
+                        }
+
+                        $.each( selected, function( i, item )
+                        {
+                            $.post( organisationUnitTreePath + "addorgunit.action", {
+                                id : item
+                            } );
+                        } ).complete( this.responseReceived );
+                    }
+                    else
+                    {
+                        if ( $.isArray( selected ) )
+                        {
+                            selected = selected[0];
+                        }
+
+                        $.post( organisationUnitTreePath + "setorgunit.action", {
+                            id : selected
+                        } ).complete( this.responseReceived );
+                    }
                 }
             } );
         }
@@ -516,19 +522,24 @@
         }
         else
         {
-            var selected = JSON.parse( sessionStorage[getTagId( "Selected" )] );
-
-            if ( $.isArray( selected ) )
-            {
-                expandTreeAtOrgUnits( selected );
-            }
-            else
-            {
-                expandTreeAtOrgUnit( selected );
-                selected = [ selected ];
-            }
-
-            selectOrgUnits( selected );
+            var selected = sessionStorage[getTagId( "Selected" )];
+
+            if ( selected != null )
+            {
+                selected = JSON.parse( selected );
+
+                if ( $.isArray( selected ) )
+                {
+                    expandTreeAtOrgUnits( selected );
+                }
+                else
+                {
+                    expandTreeAtOrgUnit( selected );
+                    selected = [ selected ];
+                }
+
+                selectOrgUnits( selected );
+            }
         }
     };
 

=== modified 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	2011-08-12 13:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-08-17 11:17:40 +0000
@@ -34,6 +34,7 @@
 import java.util.UUID;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.version.Version;
@@ -58,6 +59,13 @@
         this.currentUserService = currentUserService;
     }
 
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
     private VersionService versionService;
 
     public void setVersionService( VersionService versionService )
@@ -117,13 +125,21 @@
         {
             User user = currentUserService.getCurrentUser();
 
-            if ( user.getOrganisationUnits() != null )
+            if ( user.getOrganisationUnits() != null && user.getOrganisationUnits().size() > 0 )
             {
                 organisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
             }
             else
             {
-                organisationUnits = new ArrayList<OrganisationUnit>();
+                if ( user.getOrganisationUnits() != null && currentUserService.currentUserIsSuper() )
+                {
+                    organisationUnits = new ArrayList<OrganisationUnit>(
+                        organisationUnitService.getAllOrganisationUnits() );
+                }
+                else
+                {
+                    organisationUnits = new ArrayList<OrganisationUnit>();
+                }
             }
 
             Collections.sort( organisationUnits, organisationUnitComparator );

=== 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-08-16 12:16:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-08-17 11:17:40 +0000
@@ -525,6 +525,7 @@
   <bean id="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction" class="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction"
     scope="prototype">
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+    <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
     <property name="versionService" ref="org.hisp.dhis.version.VersionService" />
   </bean>