← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15166: (NEW) Sending to multiple individuals on Mobile Lite

 

------------------------------------------------------------
revno: 15166
committer: paulmarkcastillo@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2014-05-06 14:43:36 +0800
message:
  (NEW) Sending to multiple individuals on Mobile Lite
  https://blueprints.launchpad.net/dhis-mobile/+spec/mla-messaging
  https://blueprints.launchpad.net/dhis-mobile/+spec/mla-user-selector
added:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/AddRecipientAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/sendMessageOnMobile2.vm
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/FindUserAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties
  dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.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
=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/AddRecipientAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/AddRecipientAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/message/action/AddRecipientAction.java	2014-05-06 06:43:36 +0000
@@ -0,0 +1,101 @@
+package org.hisp.dhis.light.message.action;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * 
+ * @author Paul Mark Castillo
+ * 
+ */
+public class AddRecipientAction
+    implements Action
+{
+    private static final Log log = LogFactory.getLog( AddRecipientAction.class );
+
+    public AddRecipientAction()
+    {
+    }
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private UserService userService;
+
+    public UserService getUserService()
+    {
+        return userService;
+    }
+
+    public void setUserService( UserService userService )
+    {
+        this.userService = userService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private String recipientCheckBox;
+    public String getRecipientCheckBox()
+    {
+        return recipientCheckBox;
+    }
+
+    public void setRecipientCheckBox( String recipientCheckBox )
+    {
+        this.recipientCheckBox = recipientCheckBox;
+    }
+
+    private Set<User> recipient;
+    public Set<User> getRecipient()
+    {
+        return recipient;
+    }
+
+    public void setRecipients( Set<User> recipient )
+    {
+        this.recipient = recipient;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action Implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        updateRecipients(recipientCheckBox);
+        return SUCCESS;
+    }
+
+    /**
+     * 
+     * @param recipientCheckBox
+     */
+    private void updateRecipients(String recipientCheckBox)
+    {
+        recipient = new HashSet<User>();
+        
+        if ( recipientCheckBox != null )
+        {
+            String rcbArray[] = recipientCheckBox.split( "," );
+
+            for ( int i = 0; i < rcbArray.length; i++ )
+            {
+                rcbArray[i] = rcbArray[i].trim();
+                User u = userService.getUser( Integer.parseInt( rcbArray[i] ) );
+                recipient.add( u );
+            }
+        }
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/FindUserAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/FindUserAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/FindUserAction.java	2014-05-06 06:43:36 +0000
@@ -29,7 +29,11 @@
  */
 
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserService;
 
@@ -38,11 +42,16 @@
 public class FindUserAction
     implements Action
 {
+    private static final Log log = LogFactory.getLog( FindUserAction.class );
 
     private static final String REDIRECT = "redirect";
 
     private UserService userService;
 
+    public FindUserAction()
+    {
+    }
+
     public UserService getUserService()
     {
         return userService;
@@ -101,10 +110,46 @@
         this.userId = userId;
     }
 
+    private String recipientCheckBox;
+    public String getRecipientCheckBox()
+    {
+        return recipientCheckBox;
+    }
+
+    public void setRecipientCheckBox( String recipientCheckBox )
+    {
+        this.recipientCheckBox = recipientCheckBox;
+    }
+
+    private Set<User> recipient;
+    public Set<User> getRecipient()
+    {
+        return recipient;
+    }
+
+    public void setRecipients( Set<User> recipient )
+    {
+        this.recipient = recipient;
+    }
+
+    private int foundUsers;
+    public int getFoundUsers()
+    {
+        return foundUsers;
+    }
+
+    public void setFoundUsers( int foundUsers )
+    {
+        this.foundUsers = foundUsers;
+    }
+    
+    
     @Override
     public String execute()
         throws Exception
     {
+        updateRecipients(recipientCheckBox);
+
         if ( keyword != null )
         {
             int index = keyword.indexOf( ' ' );
@@ -115,7 +160,7 @@
                 keyword = keys[0] + "  " + keys[1];
             }
         }
-        
+
         users = userService.getUsersByName( keyword );
 
         if ( users.size() == 1 )
@@ -125,6 +170,29 @@
             return REDIRECT;
         }
 
+        foundUsers = users.size();
+        
         return SUCCESS;
     }
+    
+    /**
+     * 
+     * @param recipientCheckBox
+     */
+    private void updateRecipients(String recipientCheckBox)
+    {
+        recipient = new HashSet<User>();
+        
+        if ( recipientCheckBox != null )
+        {
+            String rcbArray[] = recipientCheckBox.split( "," );
+
+            for ( int i = 0; i < rcbArray.length; i++ )
+            {
+                rcbArray[i] = rcbArray[i].trim();
+                User u = userService.getUser( Integer.parseInt( rcbArray[i] ) );
+                recipient.add( u );
+            }
+        }
+    } 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/messaging/action/SendMessagesAction.java	2014-05-06 06:43:36 +0000
@@ -31,6 +31,8 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.message.MessageService;
 import org.hisp.dhis.user.User;
@@ -43,6 +45,8 @@
 public class SendMessagesAction
     implements Action
 {
+    private static final Log log = LogFactory.getLog( SendMessagesAction.class );
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -59,12 +63,12 @@
 
     private User user;
 
-    private Integer userId;
-
-    public void setUserId( Integer userId )
-    {
-        this.userId = userId;
-    }
+//    private Integer userId;
+//
+//    public void setUserId( Integer userId )
+//    {
+//        this.userId = userId;
+//    }
 
     public User getUser()
     {
@@ -90,21 +94,71 @@
         this.text = text;
     }
 
+    private String recipientCheckBox;
+    public String getRecipientCheckBox()
+    {
+        return recipientCheckBox;
+    }
+
+    public void setRecipientCheckBox( String recipientCheckBox )
+    {
+        this.recipientCheckBox = recipientCheckBox;
+    }
+
+    private Set<User> recipient;
+    public Set<User> getRecipient()
+    {
+        return recipient;
+    }
+
+    public void setRecipients( Set<User> recipient )
+    {
+        this.recipient = recipient;
+    }    
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
     public String execute()
     {
-        user = userService.getUser( userId );
+        log.info( "SendMessagesAction.execute() called" );        
+        
+        updateRecipients(recipientCheckBox);
+        
+//        user = userService.getUser( userId );
         String metaData = MessageService.META_USER_AGENT
             + ServletActionContext.getRequest().getHeader( ContextUtils.HEADER_USER_AGENT );
 
-        Set<User> users = new HashSet<User>();
-        users.add( user );
-
-        messageService.sendMessage( subject, text, metaData, users );
-
+//        Set<User> users = new HashSet<User>();
+//        users.add( user );
+
+//        messageService.sendMessage( subject, text, metaData, users );
+        messageService.sendMessage( subject, text, metaData, recipient );
+
+        log.debug( "SendMessagesAction.execute() exit: " + SUCCESS);
+                
         return SUCCESS;
     }
+    
+    /**
+     * 
+     * @param recipientCheckBox
+     */
+    private void updateRecipients(String recipientCheckBox)
+    {
+        recipient = new HashSet<User>();
+        
+        if ( recipientCheckBox != null )
+        {
+            String rcbArray[] = recipientCheckBox.split( "," );
+
+            for ( int i = 0; i < rcbArray.length; i++ )
+            {
+                rcbArray[i] = rcbArray[i].trim();
+                User u = userService.getUser( Integer.parseInt( rcbArray[i] ) );
+                recipient.add( u );
+            }
+        }
+    }    
 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2014-02-14 16:13:55 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2014-05-06 06:43:36 +0000
@@ -600,4 +600,9 @@
 		class="org.hisp.dhis.light.messaging.action.FindUserAction" scope="prototype">
 		<property name="userService" ref="org.hisp.dhis.user.UserService" />
 	</bean>
+	
+	<bean id="org.hisp.dhis.light.message.action.AddRecipientAction"
+		class="org.hisp.dhis.light.message.action.AddRecipientAction" scope="prototype">
+		<property name="userService" ref="org.hisp.dhis.user.UserService" />
+	</bean>	
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2014-03-26 07:41:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2014-05-06 06:43:36 +0000
@@ -134,4 +134,10 @@
 search_orgunit=Search Organisation Unit
 date_of_birth_hint=*Approximated: enter age. Declared or Verified: enter date in format [yyyy-mm-dd]
 select_attribute=Select attribute
-tracked_entity=Tracked entity
\ No newline at end of file
+tracked_entity=Tracked entity
+write=Write
+write_message=Write Message
+write_feedback=Write Feedback
+write_new_message=Write new message
+write_to_users=To User(s):
+write_add_to_recipients=Add to Recipient(s)
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2014-04-04 08:11:18 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2014-05-06 06:43:36 +0000
@@ -456,6 +456,11 @@
 		</action>
 
 		<!-- Messages -->
+		
+		<action name="message" class="org.hisp.dhis.light.action.NoAction">
+			<result name="success" type="velocity">/dhis-web-light/main.vm</result>
+			<param name="page">/dhis-web-light/sendMessageOnMobile2.vm</param>
+		</action>
 
 		<action name="messages"
 			class="org.hisp.dhis.light.message.action.GetMessagesAction">
@@ -489,19 +494,25 @@
 			<result name="redirect" type="redirect">showUserList.action?userId=${userId}
 			</result>
 			<result name="success" type="velocity">/dhis-web-light/main.vm</result>
-			<param name="page">/dhis-web-light/messages.vm</param>
+			<param name="page">/dhis-web-light/sendMessageOnMobile2.vm</param>
 		</action>
 
+		<action name="addRecipient"
+			class="org.hisp.dhis.light.message.action.AddRecipientAction">
+			<result name="success" type="velocity">/dhis-web-light/main.vm</result>
+			<param name="page">/dhis-web-light/sendMessageOnMobile2.vm</param>
+		</action>
 
 		<action name="showUserList"
 			class="org.hisp.dhis.light.messaging.action.GetMessageRecipientsAction">
 			<result name="success" type="velocity">/dhis-web-light/main.vm</result>
-			<param name="page">/dhis-web-light/sendMessageOnMobile.vm</param>
+			<param name="page">/dhis-web-light/sendMessageOnMobile2.vm</param>
 		</action>
 
 		<action name="sendMessage"
 			class="org.hisp.dhis.light.messaging.action.SendMessagesAction">
-			<result name="success" type="redirect">/light/messages.action</result>
+			<result name="success" type="velocity">/dhis-web-light/main.vm</result>
+			<param name="page">/dhis-web-light/menu.vm</param>
 		</action>
 
 		<action name="recipients"

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm	2012-12-13 08:06:31 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/messages.vm	2014-05-06 06:43:36 +0000
@@ -13,35 +13,50 @@
 </ul>
 </p>
 
-<p>
+#*
+	<p>
 
-<form method="POST" action="searchUser.action">
-<div class="header-box" align="center">
-	<h3 style="text-align: left;">$i18n.getString("search_user")</h3>
+	<form method="POST" action="searchUser.action">
+	<div class="header-box" align="center">
+		<h3 style="text-align: left;">$i18n.getString("search_user")</h3>
+		
+		<p style="text-align: left;">
+			<input type="text" name="keyword"/>
+		</p>
+		<p style="text-align: left;">
+			 <input type="submit" style="width: 100%;" value="$i18n.getString("search")" />
+		</p>
+	</div>
 	
-	<p style="text-align: left;">
-		<input type="text" name="keyword"/>
-	</p>
-	<p style="text-align: left;">
-		 <input type="submit" style="width: 100%;" value="$i18n.getString("search")" />
-	</p>
-</div>
-
-</form>
-
-<p>
-<ul>
-#foreach( $user in $users)
-	<li><a href="showUserList.action?userId=$user.getId()">$!encoder.htmlEncode( ${user.getName()} )</a></li>
-#end
-</ul>
-</p>
-
-<ul>
-<li>
-<a href="feedback.action">$i18n.getString("feedback")</a>
-</li>
-</ul>
+	</form>
+
+	<p>
+			<form>
+			
+			#foreach( $user in $users)
+			<ul>		
+				<li><a href="showUserList.action?userId=$user.getId()">$!encoder.htmlEncode( ${user.getName()} )</a></li>
+			</ul>
+			#end
+			
+			</form>
+	</p>
+*#
+
+<h2>$i18n.getString( "write" )</h2>
+
+<ul>
+	<li>
+	<a href="message.action">$i18n.getString( "write_message" )</a>
+	</li>
+</ul>
+
+<ul>
+	<li>
+	<a href="feedback.action">$i18n.getString( "write_feedback" )</a>
+	</li>
+</ul>
+
 <h2>$i18n.getString( "last_recipients" )</h2>
 
 <p>

=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/sendMessageOnMobile2.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/sendMessageOnMobile2.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/sendMessageOnMobile2.vm	2014-05-06 06:43:36 +0000
@@ -0,0 +1,79 @@
+## ============================================================================
+<h2>
+	$i18n.getString( "write_new_message" )
+</h2>
+
+
+## ============================================================================
+<form method="POST" action="sendMessage.action">
+	#foreach( $user in $recipient)
+		<input type="hidden" name="recipientCheckBox" value="$user.getId()" />
+	#end
+	<div class="header-box" align="center">
+		<p style="text-align: left;">
+			$i18n.getString( "write_to_users" )<br />
+			
+			#foreach( $user in $recipient)
+				* $!encoder.htmlEncode( ${user.getName()} )<br />
+			#end
+			
+			<br />
+			
+	        $i18n.getString( "subject" ) *<br />
+	        <input type="text" maxlength="255" size="24" name="subject" />
+	
+	        $i18n.getString( "text" ) *<br />
+	        <input type="text" maxlength="255" size="24" name="text" />
+
+	        <input type="submit" style="width: 100%;" value="$i18n.getString("send")" />
+		</p>
+	</div>
+</form>
+
+
+## ============================================================================
+<h3>$i18n.getString("search_user")</h3>
+
+<form method="POST" action="searchUser.action">
+	#foreach( $user in $recipient)
+		<input type="hidden" name="recipientCheckBox" value="$user.getId()" />
+	#end
+	<div class="header-box" align="center">
+		<p style="text-align: left;">			
+			<input type="text" maxlength="255" size="24" name="keyword" />			
+			<input type="submit" style="width: 100%;" value="$i18n.getString("search")" />
+		</p>
+	</div>
+</form>
+
+
+## ============================================================================
+<form method="POST" action="addRecipient.action">
+	#foreach( $user in $recipient)
+		<input type="hidden" name="recipientCheckBox" value="$user.getId()" />
+	#end
+	<div class="header-box" align="center">
+		<p style="text-align: center;">
+			#foreach( $user in $users )
+				<input type="checkbox" name="recipientCheckBox" value="$user.getId()">$!encoder.htmlEncode( ${user.getName()} )<br />
+			#end
+
+			#if($foundUsers > 0)
+				<input type="submit" style="width: 100%;" value="$i18n.getString( "write_add_to_recipients" )" />
+			#end
+		</p>
+	</div>
+</form>
+
+
+## ============================================================================
+<div id="footer">
+	<h2>$i18n.getString( "navigate_to" )</h2>
+		<ul>
+			<li>
+				<a href="index.action">
+					$i18n.getString("home")
+				</a>
+			</li>
+		</ul>
+</div>
\ No newline at end of file