← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4267: ouwt: finished implementing client-server state sync

 

------------------------------------------------------------
revno: 4267
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-08-09 10:50:30 +0200
message:
  ouwt: finished implementing client-server state sync
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-08 17:38:41 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-08-09 08:50:30 +0000
@@ -73,8 +73,6 @@
                 {
                     sessionStorage[getTagId( "Selected" )] = roots[0];
                 }
-
-                selection.sync();
             }
 
             if ( data["organisationUnits"].length > 0 )
@@ -82,6 +80,8 @@
                 subtree.reloadTree();
             }
 
+            selection.sync();
+
             $( "#ouwt_loader" ).hide();
         } );
     }
@@ -96,58 +96,68 @@
 
             $.post( organisationUnitTreePath + "getselected.action", function( data )
             {
+                if ( data["selectedUnits"].length < 1 )
+                {
+                    return;
+                }
+
                 if ( multipleSelectionAllowed )
                 {
-                    $.each( data, function( i, item )
+                    var selected = [];
+                    $.each( data["selectedUnits"], function( i, item )
                     {
-                        console.log( "multiSelecting " + item.id );
-                    } )
+                        selected.push( item.id );
+                    } );
+
+                    sessionStorage[getTagId( "Selected" )] = JSON.stringify( selected );
                 }
                 else
                 {
-                    console.log( "singleSelecting " + data[0].id );
+                    var ou = data["selectedUnits"][0];
+                    sessionStorage[getTagId( "Selected" )] = ou.id;
                 }
+
+                subtree.reloadTree();
             } );
         }
         else
         {
-            $.post( organisationUnitTreePath + "clearselected.action", this.responseReceived );
-
-            if ( sessionStorage[getTagId( "Selected" )] === undefined )
-            {
-                return;
-            }
-
-            var selected = JSON.parse( sessionStorage[getTagId( "Selected" )] );
-
-            if ( multipleSelectionAllowed )
-            {
-                if ( !$.isArray( selected ) )
-                {
-                    selected = [ selected ];
-                }
-
-                $.each( selected, function( i, item )
-                {
-                    $.post( organisationUnitTreePath + "addorgunit.action", {
-                        id : item
-                    } )
-                } );
-            }
-            else
-            {
-                if ( $.isArray( selected ) )
-                {
-                    selected = selected[0];
-                }
-
-                $.post( organisationUnitTreePath + "setorgunit.action", {
-                    id : selected
-                } );
-            }
+            $.post( organisationUnitTreePath + "clearselected.action", function()
+            {
+                if ( sessionStorage[getTagId( "Selected" )] === undefined )
+                {
+                    return;
+                }
+
+                var selected = JSON.parse( sessionStorage[getTagId( "Selected" )] );
+
+                if ( multipleSelectionAllowed )
+                {
+                    if ( !$.isArray( selected ) )
+                    {
+                        selected = [ selected ];
+                    }
+
+                    $.each( selected, function( i, item )
+                    {
+                        $.post( organisationUnitTreePath + "addorgunit.action", {
+                            id : item
+                        } )
+                    } );
+                }
+                else
+                {
+                    if ( $.isArray( selected ) )
+                    {
+                        selected = selected[0];
+                    }
+
+                    $.post( organisationUnitTreePath + "setorgunit.action", {
+                        id : selected
+                    } );
+                }
+            } );
         }
-
-        subtree.reloadTree();
     }
 
     this.clear = function()