← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17451: Improved add and edit for user groups in dashboard. Now uses partial load for user selector.

 

Merge authors:
  Halvdan Hoem Grelland (halvdanhg)
------------------------------------------------------------
revno: 17451 [merge]
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-11-12 16:12:24 +0100
message:
  Improved add and edit for user groups in dashboard. Now uses partial load for user selector.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/AddUserGroupAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/UpdateUserGroupAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/updateUserGroupForm.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/javascripts/validationRules.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js	2014-10-15 04:17:05 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js	2014-11-12 14:50:59 +0000
@@ -67,7 +67,7 @@
             "rangelength" : [ 2, 210 ],
             "alphanumericwithbasicpuncspaces" : true
         },
-        "groupMembersList" : {
+        "usersSelected" : {
             "required" : true
         }
     },

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/AddUserGroupAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/AddUserGroupAction.java	2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/AddUserGroupAction.java	2014-11-12 14:50:59 +0000
@@ -30,6 +30,7 @@
 
 import static org.hisp.dhis.setting.SystemSettingManager.KEY_ONLY_MANAGE_WITHIN_USER_GROUPS;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.hisp.dhis.attribute.AttributeService;
@@ -82,11 +83,11 @@
     // Parameters
     // -------------------------------------------------------------------------
 
-    private List<Integer> groupMembersList;
+    private List<String> usersSelected;
 
-    public void setGroupMembersList( List<Integer> groupMembersList )
+    public void setUsersSelected( List<String> usersSelected )
     {
-        this.groupMembersList = groupMembersList;
+        this.usersSelected = usersSelected;
     }
 
     private String name;
@@ -111,13 +112,24 @@
     public String execute()
         throws Exception
     {
+        if ( usersSelected == null )
+        {
+            usersSelected = new ArrayList<>();
+        }
+
         boolean writeGroupRequired = (Boolean) systemSettingManager.getSystemSetting( KEY_ONLY_MANAGE_WITHIN_USER_GROUPS, false );
 
         UserGroup userGroup = new UserGroup( name );
-        
-        for ( Integer groupMember : groupMembersList )
+
+        for ( String userUid : usersSelected )
         {
-            User user = userService.getUser( groupMember );
+            User user = userService.getUser( userUid );
+
+            if( user == null )
+            {
+                continue;
+            }
+
             userGroup.addUser( user );
 
             if ( writeGroupRequired && !userGroup.getMembers().contains( user) && !userService.canUpdate( user.getUserCredentials() ) )
@@ -128,8 +140,7 @@
 
         if ( jsonAttributeValues != null )
         {
-            AttributeUtils.updateAttributeValuesFromJson( userGroup.getAttributeValues(), jsonAttributeValues,
-                attributeService );
+            AttributeUtils.updateAttributeValuesFromJson( userGroup.getAttributeValues(), jsonAttributeValues, attributeService );
         }
 
         userGroupService.addUserGroup( userGroup );

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/UpdateUserGroupAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/UpdateUserGroupAction.java	2014-11-08 17:30:22 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/UpdateUserGroupAction.java	2014-11-12 14:50:59 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.user.UserGroupService;
 import org.hisp.dhis.user.UserService;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -87,11 +88,11 @@
     // Parameters
     // -------------------------------------------------------------------------
 
-    private List<Integer> groupMembersList;
+    private List<String> usersSelected;
 
-    public void setGroupMembersList( List<Integer> groupMembersList )
+    public void setUsersSelected( List<String> usersSelected )
     {
-        this.groupMembersList = groupMembersList;
+        this.usersSelected = usersSelected;
     }
 
     private String name;
@@ -123,16 +124,27 @@
     public String execute()
         throws Exception
     {
+        if ( usersSelected == null )
+        {
+            usersSelected = new ArrayList<>();
+        }
+
         boolean writeGroupRequired = (Boolean) systemSettingManager.getSystemSetting( KEY_ONLY_MANAGE_WITHIN_USER_GROUPS, false );
 
         UserGroup userGroup = userGroupService.getUserGroup( userGroupId );
 
-        Set<User> userList = new HashSet<>();
+        Set<User> users = new HashSet<>();
 
-        for ( Integer groupMember : groupMembersList )
+        for ( String userUid : usersSelected )
         {
-            User user = userService.getUser( groupMember );
-            userList.add( user );
+            User user = userService.getUser( userUid );
+
+            if( user == null)
+            {
+                continue;
+            }
+
+            users.add( user );
 
             if ( writeGroupRequired && !userGroup.getMembers().contains( user ) && !userService.canUpdate( user.getUserCredentials() ) )
             {
@@ -144,7 +156,7 @@
         {
             for ( User member : userGroup.getMembers() )
             {
-                if ( !userList.contains( member ) ) // Trying to remove member user from group.
+                if ( !users.contains( member ) ) // Trying to remove member user from group.
                 {
                     boolean otherGroupFound = false;
 
@@ -166,12 +178,11 @@
         }
 
         userGroup.setName( name );
-        userGroup.updateUsers( userList );
+        userGroup.updateUsers( users );
 
         if ( jsonAttributeValues != null )
         {
-            AttributeUtils.updateAttributeValuesFromJson( userGroup.getAttributeValues(), 
-                jsonAttributeValues, attributeService );
+            AttributeUtils.updateAttributeValuesFromJson( userGroup.getAttributeValues(), jsonAttributeValues, attributeService );
         }
 
         userGroupService.updateUserGroup( userGroup );

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm	2013-07-19 08:23:53 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/addUserGroupForm.vm	2014-11-12 14:51:29 +0000
@@ -1,31 +1,22 @@
 <script type="text/javascript">
-	jQuery(function() {
-        validation2( 'addUserGroupForm', function( form )
-        {
+    $( document ).ready( function() {
+        $( '#usersAvailable' ).selected( {
+            url: '../api/users.json',
+            target: $( '#usersSelected' ),
+            search: $( '#usersAvailableSearch' ),
+            iterator: 'users'
+        });
+
+        validation2( 'addUserGroupForm', function( form ) {
             form.submit();
         }, {
-            'beforeValidateHandler' : function()
-            {
-                jQuery( "#groupMembersList" ).find( "option" ).attr( "selected", "selected" );
-                
+            'beforeValidateHandler': function() {
+                $( '#usersSelected' ).find( 'option' ).attr( 'selected', 'selected' );
                 #tblDynamicAttributesJavascript()
             },
-            'rules' : getValidationRules( "userGroup" )
+            'rules': getValidationRules( 'userGroup' )
         } );
-
-		jQuery("#availableUsersList").dhisAjaxSelect({
-			source: "../dhis-web-commons-ajax-json/getUsers.action",
-			iterator: "users",
-			connectedTo: 'groupMembersList',
-			handler: function(item) {
-				var option = jQuery("<option />");
-				option.text( item.surname + ", " + item.firstName );
-				option.attr( "value", item.id );
-
-				return option;
-			}
-		});
-	});
+    });
 </script>
 
 <h3>$i18n.getString( "add_user_group" )</h3>
@@ -41,48 +32,23 @@
         <th colspan="2">$i18n.getString( "user_group_details" )</th>
     </tr>
 
-	<tr>
-		<td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-		<td><input type="text" id="name" name="name"></td>
-	</tr>
-</table>
-
-#tblDynamicAttributes( { "attributes": $attributes } )
-
-<table>
-    <colgroup>
-      <col style="width: 500px;"/>
-      <col/>
-      <col style="width: 500px;"/>
-    </colgroup>
-
-    <tr>
-        <th>$i18n.getString( "available_users" )</th>
-		<th></th>
-        <th>$i18n.getString( "group_members" )</th>
-    </tr>
-
-    <tr>
-        <td>
-            <select id="availableUsersList" name="availableUsersList" multiple="multiple" style="height: 200px; width: 100%;"></select>
-        </td>
-
-        <td style="text-align:center">
-        	<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableUsersList' );"/><br/>
-            <input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'groupMembersList' );"/><br/>
-			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableUsersList' );"/><br/>
-			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'groupMembersList' );"/>
-        </td>
-
-        <td>
-            <select id="groupMembersList" name="groupMembersList" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px;"></select>
-        </td>
-    </tr>
-</table>
+    <tr>
+        <td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+        <td><input type="text" id="name" name="name"></td>
+    </tr>
+</table>
+
+#tblDynamicAttributes( { "attributes": $attributes, "attributeValues": $attributeValues } )
+
+#jqSelected({
+    "prefix": "users",
+    "i18n_available": "available_users",
+    "i18n_selected": "group_members"
+})
 
 <p>
-	<input type="submit" value="$i18n.getString( 'add' )" style="width:10em"/>
-	<input type="button" value="$i18n.getString( 'cancel' )" onclick="dhis2.commons.redirectCurrentPage( 'getAllUserGroups.action' )" style="width:10em"/>
+    <input type="submit" value="$i18n.getString( 'add' )" style="width:10em"/>
+    <input type="button" value="$i18n.getString( 'cancel' )" onclick="dhis2.commons.redirectCurrentPage( 'getAllUserGroups.action' )" style="width:10em"/>
 </p>
 
 </form>

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/updateUserGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/updateUserGroupForm.vm	2013-07-19 08:23:53 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/updateUserGroupForm.vm	2014-11-12 14:50:59 +0000
@@ -1,93 +1,56 @@
 <script type="text/javascript">
-	jQuery(document).ready(function() {
-        validation2( 'editUserGroupForm', function( form )
-        {
+    $( document ).ready( function() {
+        $( '#usersAvailable' ).selected( {
+            url: '../api/users.json',
+            target: $( '#usersSelected' ),
+            search: $( '#usersAvailableSearch' ),
+            iterator: 'users'
+        });
+
+        validation2( 'editUserGroupForm', function( form ) {
             form.submit();
         }, {
-            'beforeValidateHandler' : function()
-            {
-                jQuery( "#groupMembersList" ).find( "option" ).attr( "selected", "selected" );
-                
-                #tblDynamicAttributesJavascript();
+            'beforeValidateHandler': function() {
+                $( '#usersSelected' ).find( 'option' ).attr( 'selected', 'selected' );
+                #tblDynamicAttributesJavascript()
             },
-            'rules' : getValidationRules( "userGroup" )
+            'rules': getValidationRules( 'userGroup' )
         } );
-
-		jQuery("#availableUsersList").dhisAjaxSelect({
-			source: "../dhis-web-commons-ajax-json/getUsers.action",
-			iterator: "users",
-			connectedTo: 'groupMembersList',
-			handler: function(item) {
-				var option = jQuery("<option />");
-				option.text( item.surname + ", " + item.firstName );
-				option.attr( "value", item.id );
-
-				return option;
-			}
-		});
-	});
+    });
 </script>
 
 <h3>$i18n.getString( "edit_user_group" )</h3>
 
 <form id="editUserGroupForm" name="editUserGroupForm" action="updateUserGroup.action" method="post" class="inputForm">
-	
+
 <input type="hidden" name="userGroupId" id="userGroupId" value="$group.id" />
 <table id="detailsList">
     <col style="width: 120px"/>
     <col style="width: 270px"/>
 
-	<tr>
-		<th colspan="2">$i18n.getString( "user_group_details" )</th>
-	</tr>
+    <tr>
+        <th colspan="2">$i18n.getString( "user_group_details" )</th>
+    </tr>
 
-	<tr>
-		<td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-		<td><input type="text" id="name" name="name" value ="$encoder.htmlEncode( $group.name )"></td>
-	</tr>
+    <tr>
+        <td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+        <td><input type="text" id="name" name="name" value ="$encoder.htmlEncode( $group.name )"></td>
+    </tr>
 
 </table>
 
 #tblDynamicAttributes( { "attributes": $attributes, "attributeValues": $attributeValues } )
 
-<table>
-    <colgroup>
-      <col style="width: 500px;"/>
-      <col/>
-      <col style="width: 500px;"/>
-    </colgroup>
-
-    <tr>
-        <th>$i18n.getString( "available_users" )</th>
-		<th></th>
-        <th>$i18n.getString( "group_members" )</th>
-    </tr>
-
-    <tr>
-        <td>
-            <select id="availableUsersList" name="availableUsersList" multiple="multiple" style="height: 200px; width: 100%;"></select>
-        </td>
-
-        <td style="text-align:center">          
-        	<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableUsersList' );"/><br/>
-            <input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'groupMembersList' );"/><br/>
-			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableUsersList' );"/><br/>
-			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'groupMembersList' );"/>
-        </td>
-
-        <td>
-        	<select id="groupMembersList" name="groupMembersList" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px;">
-				#foreach( $user in $groupMembers )
-					<option value="$user.id">$encoder.htmlEncode( $user.surname ), $!encoder.htmlEncode( $user.firstName )</option>
-				#end
-        	</select>
-        </td>
-    </tr>
-</table>
+#jqSelected({
+    "prefix": "users",
+    "i18n_available": "available_users",
+    "i18n_selected": "group_members",
+    "objects": $groupMembers
+})
 
 <p>
-	<input type="submit" value="$i18n.getString( 'save' )" style="width:10em" />
-	<input type="button" value="$i18n.getString( 'cancel' )" onclick="dhis2.commons.redirectCurrentPage( 'getAllUserGroups.action' )" style="width:10em" />
+    <input type="submit" value="$i18n.getString( 'save' )" style="width:10em" />
+    <input type="button" value="$i18n.getString( 'cancel' )" onclick="dhis2.commons.redirectCurrentPage( 'getAllUserGroups.action' )" style="width:10em" />
 </p>
 
 </form>