← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11318: support ouwt-search when using partial ou loading

 

------------------------------------------------------------
revno: 11318
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-07-03 12:50:10 +0700
message:
  support ouwt-search when using partial ou loading
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/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java


--
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	2013-02-05 08:35:12 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2013-07-03 05:50:10 +0000
@@ -485,11 +485,33 @@
 
             subtree.reloadTree();
             selection.sync( false, selection.responseReceived );
-            // selection.responseReceived();
         }
         else
         {
-            $( '#searchField' ).css( 'background-color', '#ffc5c5' );
+            $.ajax( {
+                url: '../dhis-web-commons-ajax-json/getOrganisationUnitTree.action',
+                data: { byName: name }
+            } ).done(function(data) {
+                if ( data.realRoot === undefined ) {
+                    if ( sessionStorage["organisationUnits"] === undefined )
+                    {
+                        sessionStorage["organisationUnits"] = JSON.stringify( data.organisationUnits );
+                    }
+                    else
+                    {
+                        var units = JSON.parse( sessionStorage["organisationUnits"] );
+                        $.extend(units, data.organisationUnits);
+                        sessionStorage["organisationUnits"] = JSON.stringify( units );
+                    }
+
+                    $.extend(organisationUnits, data.organisationUnits);
+                    selection.findByName();
+                }
+
+                $( '#searchField' ).css( 'background-color', '#ffc5c5' );
+            } ).fail(function() {
+                $( '#searchField' ).css( 'background-color', '#ffc5c5' );
+            });
         }
     };
 
@@ -692,7 +714,7 @@
                         } 
                         else 
                         {
-                            units = JSON.parse( sessionStorage["organisationUnits"] );
+                            var units = JSON.parse( sessionStorage["organisationUnits"] );
                             $.extend(units, data.organisationUnits);
                             sessionStorage["organisationUnits"] = JSON.stringify( units );
                         }

=== 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	2013-07-03 04:04:40 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2013-07-03 05:50:10 +0000
@@ -128,6 +128,13 @@
         this.parentId = parentId;
     }
 
+    private String byName;
+
+    public void setByName( String byName )
+    {
+        this.byName = byName;
+    }
+
     private boolean realRoot;
 
     public boolean isRealRoot()
@@ -142,6 +149,27 @@
     public String execute()
         throws Exception
     {
+        if ( byName != null )
+        {
+            List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName( byName );
+
+            if ( !organisationUnitByName.isEmpty() )
+            {
+                OrganisationUnit child = organisationUnitByName.get( 0 );
+                organisationUnits.add( child );
+                OrganisationUnit parent = child.getParent();
+
+                do
+                {
+                    organisationUnits.add( parent );
+                    organisationUnits.addAll( parent.getChildren() );
+                }
+                while ( (parent = parent.getParent()) != null );
+
+                return "partial";
+            }
+        }
+
         if ( parentId != null )
         {
             OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java	2012-09-19 11:41:19 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java	2013-07-03 05:50:10 +0000
@@ -27,14 +27,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Chau Thu Tran
  */
@@ -42,7 +41,7 @@
     implements Action
 {
     private static final int MAX = 14;
-    
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -85,7 +84,7 @@
         throws Exception
     {
         organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByName( term, 0, MAX ) );
-        
+
         return SUCCESS;
     }
 }