← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16695: sync calls to addorgunit for ouwt, save old ouwt selected on update user load

 

------------------------------------------------------------
revno: 16695
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-09-11 19:33:22 +0700
message:
  sync calls to addorgunit for ouwt, save old ouwt selected on update user load
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.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-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	2014-07-01 08:23:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2014-09-11 12:33:22 +0000
@@ -415,11 +415,19 @@
                 var selected = selection.getSelected();
 
                 if( multipleSelectionAllowed ) {
+                    var def = $.Deferred();
+                    var p = def.promise();
+
                     $.each( selected, function( i, item ) {
-                        $.post( organisationUnitTreePath + "addorgunit.action", {
-                            id: item
-                        } ).complete( fn );
+                        p = p.then(function() {
+                            return $.post(organisationUnitTreePath + "addorgunit.action", {
+                                id: item
+                            });
+                        });
                     } );
+
+                    p.done(fn);
+                    def.resolve();
                 } else {
                     selected = $.isArray( selected ) ? selected[0] : selected;
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2014-09-11 12:33:22 +0000
@@ -28,14 +28,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.setting.SystemSettingManager.KEY_ONLY_MANAGE_WITHIN_USER_GROUPS;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.collect.Lists;
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -60,7 +56,12 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hisp.dhis.setting.SystemSettingManager.KEY_ONLY_MANAGE_WITHIN_USER_GROUPS;
 
 /**
  * @author Torgeir Lorange Ostby
@@ -121,6 +122,9 @@
         this.attributeService = attributeService;
     }
 
+    @Autowired
+    private IdentifiableObjectManager manager;
+
     private I18n i18n;
 
     public void setI18n( I18n i18n )
@@ -239,6 +243,13 @@
         return message;
     }
 
+    private String ouwtSelected;
+
+    public void setOuwtSelected( String ouwtSelected )
+    {
+        this.ouwtSelected = ouwtSelected;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -263,7 +274,7 @@
         // ---------------------------------------------------------------------
 
         Boolean canManageGroups = (Boolean) systemSettingManager.getSystemSetting( KEY_ONLY_MANAGE_WITHIN_USER_GROUPS, false );
-        
+
         if ( canManageGroups && !currentUser.getUserCredentials().getAllAuthorities().contains( "ALL" ) )
         {
             boolean groupFound = false;
@@ -382,7 +393,7 @@
         // ---------------------------------------------------------------------
         // Update User
         // ---------------------------------------------------------------------
-        
+
         userService.updateUserCredentials( userCredentials );
         userService.updateUser( user );
 
@@ -390,13 +401,26 @@
         // Update organisation unit trees if current user is being updated
         // ---------------------------------------------------------------------
 
-        if ( user.equals( currentUserService.getCurrentUser() ) && !dataCaptureOrgUnits.isEmpty() )
+        if ( user.equals( currentUser ) && !dataCaptureOrgUnits.isEmpty() )
         {
             selectionManager.setRootOrganisationUnits( dataCaptureOrgUnits );
             selectionManager.setSelectedOrganisationUnits( dataCaptureOrgUnits );
         }
-        
-        if ( user.equals( currentUserService.getCurrentUser() ) && !dataViewOrgUnits.isEmpty() )
+        else
+        {
+            selectionManager.setRootOrganisationUnits( currentUser.getOrganisationUnits() );
+
+            if ( ouwtSelected != null && manager.search( OrganisationUnit.class, ouwtSelected ) != null )
+            {
+                selectionManager.setSelectedOrganisationUnits( Lists.newArrayList( manager.search( OrganisationUnit.class, ouwtSelected ) ) );
+            }
+            else
+            {
+                selectionManager.setSelectedOrganisationUnits( currentUser.getOrganisationUnits() );
+            }
+        }
+
+        if ( user.equals( currentUser ) && !dataViewOrgUnits.isEmpty() )
         {
             selectionTreeManager.setRootOrganisationUnits( dataViewOrgUnits );
             selectionTreeManager.setSelectedOrganisationUnits( dataViewOrgUnits );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm	2014-07-03 05:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm	2014-09-11 12:33:22 +0000
@@ -1,4 +1,6 @@
 <script type="text/javascript">
+  var ouwtSelected = [];
+
   jQuery(function() {
     var rules = getValidationRules("user");
     rules["rawPassword"].required = false;
@@ -13,6 +15,8 @@
       if( $('#orgUnitTree').find('.selected').size() == 0 ) {
         setHeaderDelayMessage('$encoder.jsEncode( $i18n.getString( "data_capture_organisation_unit_required_for_user" ) )');
       } else {
+        $('#ouwtSelected').val( ouwtSelected[0] );
+        selection.setSelected( ouwtSelected !== undefined ? ouwtSelected : [] );
         form.submit();
       }
     }, {
@@ -25,6 +29,7 @@
 
     checkValueIsExist("openId", "validateUser.action", { id: $userCredentials.id });
 
+    ouwtSelected = selection.getSelected();
     selection.clearSelected(); // Sync ouwt from server
     selection.setMultipleSelectionAllowed( true );
     selection.setUnselectAllowed( true );
@@ -71,6 +76,7 @@
 <h3>$i18n.getString( "edit_user" )</h3>
 
 <form id="updateUserForm" action="updateUser.action" method="post" class="inputForm">
+<input type="hidden" id="ouwtSelected" name="ouwtSelected" value=""/>
 <div><input type="hidden" id="id" name="id" value="$userCredentials.id"/></div>
 
 <table>