← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13811: Ouwt, made tree potentially scroll down to selected org unit on page load and on search

 

------------------------------------------------------------
revno: 13811
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-01-22 15:53:27 +0200
message:
  Ouwt, made tree potentially scroll down to selected org unit on page load and on search
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js


--
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-12-20 12:00:03 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2014-01-22 13:53:27 +0000
@@ -116,7 +116,7 @@
         selected = selected ? JSON.parse( selected ) : [];
         selected = $.isArray( selected ) ? selected : [ selected ];
 
-        return  selected;
+        return selected;
     };
 
     this.clearSelected = function() {
@@ -278,6 +278,7 @@
                     subtree.reloadTree();
 
                     $( "#ouwt_loader" ).hide();
+                    selection.scrollToSelected();
                     $( "#orgUnitTree" ).trigger( "ouwtLoaded" );
                 } );
             } );
@@ -529,6 +530,19 @@
         return 'orgUnit' + unitId;
     }
 
+    this.scrollToSelected = function() {
+    	var ou = selection.getSelected();
+    	
+    	if ( ou && ou.length ) {
+    		$( "#orgUnitTree" ).scrollTop( 0 );
+    		var tagId = "#" + getTagId( ou[0] );
+    		var tagOffset = $( tagId ).offset().top;
+    		var treeOffset = $( "#orgUnitTree" ).offset().top;
+    		var offset = tagOffset - treeOffset;
+    		$( "#orgUnitTree" ).animate( { scrollTop: offset }, 300 );
+    	}
+    };
+    
     this.findByName = function() {
         var name = $( '#searchField' ).val();
         var match;
@@ -543,12 +557,13 @@
         }
 
         if( match !== undefined ) {
-            $( '#searchField' ).css( 'background-color', '#ffffff' );
+            $( '#searchField' ).css( 'background-color', '#fff' );
 
             multipleSelectionAllowed ? selection.setSelected( [ match.id ] ) : selection.setSelected( match.id );
 
             subtree.reloadTree();
             selection.sync( false, selection.responseReceived );
+            selection.scrollToSelected();
         }
         else {
             $.ajax( {
@@ -571,7 +586,7 @@
             } );
         }
     };
-
+    
     this.enable = function() {
         $( "#orgUnitTree" ).show();
     };