← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2208: Improved find orgunit in tree function

 

------------------------------------------------------------
revno: 2208
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2010-11-29 14:06:19 +0100
message:
  Improved find orgunit in tree function
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittreesearch.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittree.vm
  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/ouwt/action/GetOrganisationUnitByCodeAction.java
  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/dhis-web-commons.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/menu.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menuWithTree.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-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2010-11-22 10:45:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2010-11-29 13:06:19 +0000
@@ -123,6 +123,14 @@
     OrganisationUnit getOrganisationUnitByName( String name );
 
     /**
+     * Returns an OrganisationUnit with a given name. Case is ignored.
+     * 
+     * @param name the name of the OrganisationUnit to return.
+     * @return the OrganisationUnit with the given name, or null if not match.
+     */
+    OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name );
+
+    /**
      * Returns an OrganisationUnit with a given code.
      * 
      * @param code the code of the OrganisationUnit to return.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java	2010-11-22 10:45:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java	2010-11-29 13:06:19 +0000
@@ -60,6 +60,14 @@
     OrganisationUnit getOrganisationUnitByName( String name );
 
     /**
+     * Returns an OrganisationUnit with a given name. Case is ignored.
+     * 
+     * @param name the name of the OrganisationUnit to return.
+     * @return the OrganisationUnit with the given name, or null if not match.
+     */
+    OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name );
+
+    /**
      * Returns an OrganisationUnit with a given code.
      * 
      * @param code the code of the OrganisationUnit to return.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2010-11-22 10:45:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2010-11-29 13:06:19 +0000
@@ -179,6 +179,11 @@
     {
         return organisationUnitStore.getOrganisationUnitByName( name );
     }
+    
+    public OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name )
+    {
+        return organisationUnitStore.getOrganisationUnitByNameIgnoreCase( name );
+    }
 
     public OrganisationUnit getOrganisationUnitByCode( String code )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2010-11-22 10:45:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2010-11-29 13:06:19 +0000
@@ -99,6 +99,13 @@
 
         return (OrganisationUnit) query.uniqueResult();
     }
+    
+    public OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( OrganisationUnit.class );        
+        criteria.add( Restrictions.eq( "name", name ).ignoreCase() );
+        return (OrganisationUnit) criteria.uniqueResult();
+    }
 
     public OrganisationUnit getOrganisationUnitByCode( String code )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittree.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittree.vm	2010-11-23 03:28:07 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittree.vm	2010-11-29 13:06:19 +0000
@@ -1,19 +1,3 @@
-<script>
-	
-$(document).ready(function(){
-	$("#searchIcon").click(function(){
-		$("#searchSpan").toggle();
-		$("#searchField").focus();
-		byId('visited').value = ( byId('visited').value==0 ) ? 1 : 0 ;
-	});
-	
-});
-
-</script>
-
-<input type='hidden' id='visited' name='visited' value='0'>
-<img id="searchIcon" src="../images/search.png" style="cursor: pointer" title="$i18n.getString( 'locate_organisation_unit_by_code' )">
-<span id="searchSpan" style="display:none"><input type="text" id="searchField" name="key" style="width:130px" onchange="getOrgunitByCode();"><input type="button" value="Find" onclick="getOrgunitByCode()"></span>
 
 #macro( parseNode $node )
 	#if( $node.hasChildren )
@@ -52,14 +36,3 @@
 		</ul>
 	</div>
 #end
-
-<script>
-	
-	var visited = byId('visited').value;
-	if(visited == 0 ){
-		byId('searchSpan').style.display = 'none';
-	}else{
-		$("#searchSpan").show();
-	}
-	
-</script>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittreesearch.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittreesearch.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/orgunittreesearch.vm	2010-11-29 13:06:19 +0000
@@ -0,0 +1,18 @@
+
+<img id="searchIcon" src="../images/search.png" style="cursor: pointer" title="$i18n.getString( 'locate_organisation_unit_by_code_or_name' )">
+<span id="searchSpan" style="display:none"><input type="text" id="searchField" name="key" style="width:130px" onchange="getOrgunitByCode()"><input type="button" value="Find" onclick="getOrgunitByCode()"></span>
+
+<script>
+	
+$(document).ready(function(){
+	$("#searchIcon").click(function(){
+		$("#searchSpan").toggle();
+		$("#searchField").focus();
+	});
+});
+
+</script>
+
+<div id="orgUnitTreeContainer">
+#parse( "/dhis-web-commons/ouwt/orgunittree.vm" )
+</div>
\ No newline at end of file

=== 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	2010-09-06 09:12:16 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2010-11-29 13:06:19 +0000
@@ -347,11 +347,11 @@
 
 function getOrgunitByCode(code)
 {
-	$.getJSON(organisationUnitTreePath + 'getOrganisationUnitByCode.action?code=' + $( '#searchField' ).val(), function (data){	
+	$.getJSON( organisationUnitTreePath + 'getOrganisationUnitByCode.action?code=' + $.URLEncode( $( '#searchField' ).val() ), function ( data ) {	
 		if ( data.response == "success" ) {
-			window.location.reload();
+			$( '#orgUnitTreeContainer' ).load( organisationUnitTreePath + 'loadOrganisationUnitTree.action' );
 		} else {
-			$( '#searchField' ).css( "background-color", "#ffc5c5" );
+			$( '#searchField' ).css( 'background-color', '#ffc5c5' );
 		}
 	} );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitByCodeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitByCodeAction.java	2010-09-06 09:12:16 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitByCodeAction.java	2010-11-29 13:06:19 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -35,16 +37,23 @@
 
 /**
  * @author Chau Thu Tran
- * @version $Id: GetOrganisationUnitByNameAction.java 5282 2010-08-31 18:41:06Z
- *          $
  */
 public class GetOrganisationUnitByCodeAction
     implements Action
 {
+    private static final Log log = LogFactory.getLog( GetOrganisationUnitByCodeAction.class );
+    
     // --------------------------------------------------------------------------
     // Dependencies
     // --------------------------------------------------------------------------
 
+    private OrganisationUnitSelectionManager selectionManager;
+    
+    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
+    {
+        this.selectionManager = selectionManager;
+    }
+
     private OrganisationUnitService organisationUnitService;
 
     public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
@@ -52,13 +61,6 @@
         this.organisationUnitService = organisationUnitService;
     }
 
-    private OrganisationUnitSelectionManager selectionManager;
-
-    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
-    {
-        this.selectionManager = selectionManager;
-    }
-
     // --------------------------------------------------------------------------
     // Input
     // --------------------------------------------------------------------------
@@ -70,9 +72,9 @@
         this.code = code;
     }
 
-    private String message;
+    private Integer message;
 
-    public String getMessage()
+    public Integer getMessage()
     {
         return message;
     }
@@ -85,19 +87,24 @@
     public String execute()
         throws Exception
     {
-        message = "";
+        log.debug( "Searching organisation unit for code: " + code );
         
         OrganisationUnit unit = organisationUnitService.getOrganisationUnitByCode( code );
         
+        if ( unit == null )
+        {
+            unit = organisationUnitService.getOrganisationUnitByNameIgnoreCase( code );
+        }
+        
         if ( unit != null )
         {
-            message = unit.getId() + "";
-            
             selectionManager.setSelectedOrganisationUnit( unit );
             
+            message = unit.getId();
+            
             return SUCCESS;
         }
-
+        
         return INPUT;
     }
 }

=== 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	2010-11-26 10:54:28 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2010-11-29 13:06:19 +0000
@@ -189,13 +189,13 @@
 	</bean>
 	
 	<bean id="org.hisp.dhis.ouwt.action.GetOrganisationUnitByCodeAction"
-		class="org.hisp.dhis.ouwt.action.GetOrganisationUnitByCodeAction" scope="prototype">
+		class="org.hisp.dhis.ouwt.action.GetOrganisationUnitByCodeAction" scope="prototype">		
+		<property name="selectionManager">
+			<ref local="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
+		</property>
 		<property name="organisationUnitService">
 			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
 		</property>
-		<property name="selectionManager">
-			<ref local="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
-		</property>
 	</bean>
 	
 	

=== 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	2010-11-20 08:23:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2010-11-29 13:06:19 +0000
@@ -226,6 +226,12 @@
 				/dhis-web-commons/ajax/jsonResponseInput.vm</result>
 		</action>
 		
+		<action name="loadOrganisationUnitTree" 
+			class="org.hisp.dhis.commons.action.NoAction">
+			<result name="success" type="velocity">/dhis-web-commons/ouwt/orgunittree.vm</result>
+			<interceptor-ref name="organisationUnitTreeStack" />
+		</action>
+		
 	</package>
 
 	<!-- Menu -->

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2010-11-25 21:34:02 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2010-11-29 13:06:19 +0000
@@ -37,7 +37,7 @@
 org_unit_tree = Organisation Unit Tree
 specify_organisationunit = Please specify an organisation unit
 cannot_clear_selected_orgunits = Cannot clear the selected organisation units
-locate_organisation_unit_by_code = Locate organisation unit by code
+locate_organisation_unit_by_code_or_name = Locate organisation unit by code or name
 error_occurred = An error has occurred.
 select_organisationunit = You must select an OrganisationUnit from the tree.
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/menu.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/menu.vm	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/menu.vm	2010-11-29 13:06:19 +0000
@@ -1,2 +1,2 @@
 <br>
-#parse( "/dhis-web-commons/ouwt/orgunittree.vm" )
+#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" )
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2010-11-20 08:35:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2010-11-29 13:06:19 +0000
@@ -22,7 +22,7 @@
 			<result name="success" type="velocity">/main.vm</result>
 			<param name="page">/dhis-web-maintenance-organisationunit/organisationUnit.vm</param>
 			<param name="menu">/dhis-web-maintenance-organisationunit/menuWithTree.vm</param>
-			<param name="menuTreeHeight">384</param>
+			<param name="menuTreeHeight">358</param>
 			<param name="javascripts">
 					../dhis-web-commons/ouwt/ouwt.js,
 					javascript/organisationUnit.js

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menuWithTree.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menuWithTree.vm	2010-09-21 06:16:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menuWithTree.vm	2010-11-29 13:06:19 +0000
@@ -1,7 +1,7 @@
 
 #parse( "/dhis-web-maintenance-organisationunit/menu.vm" )
 
-#parse( "/dhis-web-commons/ouwt/orgunittree.vm" )
+#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" )
 
 <script>