← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19148: support d2Selected plugin in program userRole mgmt

 

------------------------------------------------------------
revno: 19148
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-05-13 10:05:12 +0700
message:
  support d2Selected plugin in program userRole mgmt
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/DefineProgramUserroleAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programUserrole.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-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/DefineProgramUserroleAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/DefineProgramUserroleAction.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/DefineProgramUserroleAction.java	2015-05-13 03:05:12 +0000
@@ -28,27 +28,25 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.user.UserService;
 
-import com.opensymphony.xwork2.Action;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * @author Chau Thu Tran
- * 
  * @version DefineProgramUserroleAction.java 12:43:40 PM Feb 19, 2013 $
  */
 public class DefineProgramUserroleAction
     implements Action
 {// -------------------------------------------------------------------------
- // Dependency
- // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
 
     private ProgramService programService;
 
@@ -75,11 +73,11 @@
         this.id = id;
     }
 
-    private Collection<Integer> userRoleIds = new HashSet<>();
+    private Collection<String> urSelected = new HashSet<>();
 
-    public void setUserRoleIds( Collection<Integer> userRoleIds )
+    public void setUrSelected( Collection<String> urSelected )
     {
-        this.userRoleIds = userRoleIds;
+        this.urSelected = urSelected;
     }
 
     // -------------------------------------------------------------------------
@@ -92,14 +90,14 @@
     {
         Program program = programService.getProgram( id );
 
-        Set<UserAuthorityGroup> userAutorities = new HashSet<>();
+        Set<UserAuthorityGroup> userAuthorities = new HashSet<>();
 
-        for ( Integer userRoleId : this.userRoleIds )
+        for ( String id : urSelected )
         {
-            userAutorities.add( userService.getUserAuthorityGroup( userRoleId ) );
+            userAuthorities.add( userService.getUserAuthorityGroup( id ) );
         }
 
-        program.setUserRoles( userAutorities );
+        program.setUserRoles( userAuthorities );
 
         programService.updateProgram( program );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programUserrole.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programUserrole.vm	2014-11-03 13:35:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programUserrole.vm	2015-05-13 03:05:12 +0000
@@ -1,61 +1,29 @@
+<script>
+  $(document).ready(function() {
+    $('#urAvailable').selected({
+      url: '../api/userRoles.json?canIssue=true',
+      target: $('#urSelected'),
+      search: $('#urAvailableSearch'),
+      iterator: 'userRoles'
+    });
+  });
+</script>
+
 <h3>$i18n.getString( "assign_program_to_userroles" )</h3>
 
 <h4>$encoder.htmlEncode($program.displayName)</h4>
 
-<form name="userRole" action="defineProgramUserrole.action" method="POST" onsubmit="selectAllById( 'userRoleIds' );">
-<input type="hidden" name="id" value="$program.id"/>
-<table>
-	<colgroup>
-		<col style='width:500px'/>
-		<col/>
-		<col style='width:500px'/>
-	</colgroup>
-	<tr>
-		<th>$i18n.getString( "available" )</th>
-		<th></th>
-		<th>$i18n.getString( "selected" )</th>
-	</tr>
-	<tr>
-		<td>
-			<select style="height:200px;width:100%;" size="15" id="availableList" name="availableList" multiple="multiple" style="min-width:20em;height:20em" ondblclick="moveSelectedById( 'availableList', 'userRoleIds' )">
-            </select>
-		</td>
-		<td>
-			<input type="button" value="&gt;" onclick="moveSelectedById( 'availableList', 'userRoleIds' )" class="filterButton" /><br/>
-			<input type="button" value="&lt;" onclick="moveSelectedById( 'userRoleIds', 'availableList' )" class="filterButton" /><br/>
-			<input type="button" value="&gt;&gt;" onclick="moveAllById( 'availableList', 'userRoleIds' )" class='filterButton' /><br/>
-			<input type="button" value="&lt;&lt;" onclick="moveAllById( 'userRoleIds', 'availableList' )" class='filterButton' />
-		</td>
-		<td>
-			<select style="height:200px;width:100%;" id="userRoleIds" name="userRoleIds" multiple="multiple" style="min-width:20em;height:20em" ondblclick="moveSelectedById( 'userRoleIds', 'availableList' )">
-			#foreach ( $userRole in $program.userRoles )
-              <option value="$userRole.id">$encoder.htmlEncode( $userRole.name )</option>
-            #end
-			</select>
-        </td>
-	</tr>
-</table>
-<br>
-<input type="submit" value="$i18n.getString( 'ok' )" style="width:100px"/>
-<input type="button" value="$i18n.getString( 'cancel' )"  style="width:100px" onclick="window.location = 'program.action'"/>
+<form name="userRole" action="defineProgramUserrole.action" method="POST" onsubmit="$('#urSelected').find('option').attr('selected', 'selected')">
+  <input type="hidden" name="id" value="$program.id"/>
+
+  #jqSelected({
+    "prefix": "ur",
+    "i18n_available": "available",
+    "i18n_selected": "selected",
+    "objects": $!program.userRoles
+  })
+
+  <br>
+  <input type="submit" value="$i18n.getString( 'ok' )" style="width:100px"/>
+  <input type="button" value="$i18n.getString( 'cancel' )" style="width:100px" onclick="window.location = 'program.action'"/>
 </form>
-
-<script>
-	$(document).ready(function(){
-		sortList('availableList', 'ASC');
-		sortList('selectedList', 'ASC');
-		
-		jQuery("#availableList").dhisAjaxSelect({
-			source: '../dhis-web-commons-ajax-json/getUserRoles.action',
-			iterator: 'userRoles',
-			connectedTo: 'selectedList',
-			handler: function(item){
-				var option = jQuery( "<option/>" );
-				option.attr( "value", item.id );
-				option.text( item.name );
-				
-				return option;
-			}
-		});
-	});
-</script>
\ No newline at end of file