← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4273: re-implemented findByCode in ouwt. It will be a bit slow for now, will speed this up if there is ...

 

------------------------------------------------------------
revno: 4273
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-08-10 15:35:47 +0200
message:
  re-implemented findByCode in ouwt. It will be a bit slow for now, will speed this up if there is more space in sessionStorage when offline dataEntry is complete.
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	2011-08-10 10:56:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-08-10 13:35:47 +0000
@@ -329,29 +329,41 @@
     {
         var name = $( '#searchField' ).val()
 
-        $.getJSON( organisationUnitTreePath + 'getOrganisationUnitByCode.action?code=' + encodeURI( name ), function(
-                data )
-        {
-            if ( data.response == "success" )
-            {
-                var unitId = data.message;
-
-                $( '#orgUnitTreeContainer' ).load( organisationUnitTreePath + 'loadOrganisationUnitTree.action',
-                        function()
-                        {
-                            if ( !listenerFunction )
-                            {
-                                return false;
-                            }
-
-                            listenerFunction( [ unitId ] );
-                        } );
+        var match;
+
+        for ( var ou in localStorage )
+        {
+            if ( ou.indexOf( "orgUnit" ) != -1 )
+            {
+                var value = localStorage[ou];
+
+                if ( value.indexOf( "\"" + name + "\"" ) != -1 )
+                {
+                    match = JSON.parse( value );
+                }
+            }
+        }
+
+        if ( match !== undefined )
+        {
+            $( '#searchField' ).css( 'background-color', '#ffffff' );
+
+            if ( multipleSelectionAllowed )
+            {
+                sessionStorage[getTagId( "Selected" )] = [ match.id ];
             }
             else
             {
-                $( '#searchField' ).css( 'background-color', '#ffc5c5' );
+                sessionStorage[getTagId( "Selected" )] = match.id;
             }
-        } );
+
+            selection.sync();
+            subtree.reloadTree();
+        }
+        else
+        {
+            $( '#searchField' ).css( 'background-color', '#ffc5c5' );
+        }
     }
 }