← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4164: even more jquerification in ouwt

 

------------------------------------------------------------
revno: 4164
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-07-19 10:56:39 +0200
message:
  even more jquerification in ouwt
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-07-19 07:38:53 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-07-19 08:56:39 +0000
@@ -93,11 +93,10 @@
 
         var unitIds = new Array();
 
-        var unitIdElements = rootElement.getElementsByTagName( 'unitId' );
-        for ( var i = 0, unitIdElement; ( unitIdElement = unitIdElements[i] ); ++i )
+        $( rootElement ).find( "unitId" ).each( function( i, item )
         {
-            unitIds[i] = unitIdElement.firstChild.nodeValue;
-        }
+            unitIds[i] = $( item ).text()
+        } );
 
         listenerFunction( unitIds );
     }
@@ -205,49 +204,38 @@
 
     function treeReceived( rootElement )
     {
-        var rootsElement = rootElement.getElementsByTagName( 'roots' )[0];
-        var unitElements = rootsElement.getElementsByTagName( 'unit' );
-
-        var treeTag = document.getElementById( 'orgUnitTree' );
-        var rootsTag = document.createElement( 'ul' );
-
-        for ( var i = 0; i < unitElements.length; ++i )
-        {
-            var unitTag = createTreeElementTag( unitElements[i] );
-
-            rootsTag.appendChild( unitTag );
-        }
-
-        treeTag.appendChild( rootsTag );
-
-        var childrenElement = rootElement.getElementsByTagName( 'children' )[0];
-        var parentElements = childrenElement.getElementsByTagName( 'parent' );
-
-        for ( var i = 0, parentElement; ( parentElement = parentElements[i] ); ++i )
-        {
-            var parentId = parentElement.getAttribute( 'parentId' );
-            var parentTag = document.getElementById( getTagId( parentId ) );
-
-            createChildren( parentTag, parentElement );
-        }
+        var $treeTag = $( "#orgUnitTree" );
+        var $rootsTag = $( "<ul/>" );
+
+        $( rootElement ).find( "roots > unit" ).each( function( i, item )
+        {
+            $rootsTag.append( createTreeElementTag( item ) );
+        } );
+
+        $treeTag.append( $rootsTag );
+
+        $( rootElement ).find( "children > parent" ).each( function( i, item )
+        {
+            var parentId = $( item ).attr( "parentId" );
+            var $parentTag = $( "#" + getTagId( parentId ) );
+
+            createChildren( $parentTag, item );
+        } );
     }
 
     function createChildren( parentTag, parentElement )
     {
-        var children = parentElement.getElementsByTagName( 'child' );
-        var childrenTag = document.createElement( 'ul' );
+        var $childrenTag = $( "<ul/>" );
 
-        for ( var i = 0, child; ( child = children[i] ); ++i )
+        $( parentElement ).find( "child" ).each( function( i, item )
         {
-            var childTag = createTreeElementTag( child );
-
-            childrenTag.appendChild( childTag );
-        }
-
-        setVisible( childrenTag, true );
+            $childrenTag.append( createTreeElementTag( item ) );
+        } )
+
+        setVisible( $childrenTag, true );
         setToggle( parentTag, true );
 
-        $( parentTag ).get( 0 ).appendChild( childrenTag );
+        $( parentTag ).append( $childrenTag );
     }
 
     function createTreeElementTag( child )
@@ -284,7 +272,7 @@
         $childTag.append( " " );
         $childTag.append( $linkTag )
 
-        return $childTag.get( 0 );
+        return $childTag;
     }
 
     function setToggle( unitTag, expanded )