← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9860: (mobile) - Implemented a new option that allow to send SMS based on selected user group.

 

------------------------------------------------------------
revno: 9860
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-21 13:44:09 +0700
message:
  (mobile) - Implemented a new option that allow to send SMS based on selected user group.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSendSMSFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module_vi_VN.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sendSMS.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendBeneficiarySMSPage.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.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-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java	2013-01-22 08:31:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java	2013-02-21 06:44:09 +0000
@@ -47,6 +47,8 @@
 import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserGroup;
+import org.hisp.dhis.user.UserGroupService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
@@ -72,6 +74,9 @@
     private PatientService patientService;
 
     @Autowired
+    private UserGroupService userGroupService;
+
+    @Autowired
     private MessageSender messageSender;
 
     @Autowired
@@ -109,6 +114,13 @@
         this.sendTarget = sendTarget;
     }
 
+    private Integer userGroup;
+
+    public void setUserGroup( Integer userGroup )
+    {
+        this.userGroup = userGroup;
+    }
+
     private Set<String> recipients = new HashSet<String>();
 
     public void setRecipients( Set<String> recipients )
@@ -157,6 +169,8 @@
             return ERROR;
         }
 
+        User currentUser = currentUserService.getCurrentUser();
+
         if ( sendTarget != null && sendTarget.equals( "phone" ) )
         {
             try
@@ -179,8 +193,28 @@
                 e.printStackTrace();
             }
 
-            message = messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), true,
-                recipients, gatewayId );
+            message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, true, recipients, gatewayId );
+        }
+        else if ( sendTarget.equals( "userGroup" ) )
+        {
+            UserGroup group = userGroupService.getUserGroup( userGroup );
+
+            if ( group == null )
+            {
+                message = "selected_user_group_is_unavailable";
+
+                return ERROR;
+            }
+
+            if ( group.getMembers() == null || group.getMembers().isEmpty() )
+            {
+                message = "selected_user_group_has_no_member";
+
+                return ERROR;
+            }
+
+            message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, false, group.getMembers(),
+                gatewayId );
         }
         else if ( sendTarget.equals( "user" ) )
         {
@@ -195,8 +229,14 @@
                     users.addAll( unit.getUsers() );
                 }
 
-                message = messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(),
-                    false, users, gatewayId );
+                if ( users.isEmpty() )
+                {
+                    message = "there_is_no_user_assigned_to_selected_units";
+
+                    return ERROR;
+                }
+
+                message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, false, users, gatewayId );
             }
         }
         else if ( sendTarget.equals( "unit" ) )
@@ -209,8 +249,14 @@
                 }
             }
 
-            message = messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), true,
-                recipients, gatewayId );
+            if ( recipients.isEmpty() )
+            {
+                message = "selected_units_have_no_phone_number";
+
+                return ERROR;
+            }
+
+            message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, true, recipients, gatewayId );
         }
         else
         {
@@ -247,8 +293,14 @@
                 }
             }
 
-            message = messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), true,
-                phones, gatewayId );
+            if ( phones.isEmpty() )
+            {
+                message = "selected_persons_have_no_phone_number";
+
+                return ERROR;
+            }
+
+            message = messageSender.sendMessage( smsSubject, smsMessage, currentUser, true, phones, gatewayId );
         }
 
         if ( message != null && !message.equals( "success" ) )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSendSMSFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSendSMSFormAction.java	2012-03-14 10:36:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowSendSMSFormAction.java	2013-02-21 06:44:09 +0000
@@ -27,9 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
+import org.hisp.dhis.user.UserGroup;
+import org.hisp.dhis.user.UserGroupService;
+import org.hisp.dhis.user.comparator.UserGroupComparator;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
@@ -49,15 +55,37 @@
     @Autowired
     private OutboundSmsTransportService transportService;
 
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
+    @Autowired
+    private UserGroupService userGroupService;
+
+    // -------------------------------------------------------------------------
+    // Input && Output
+    // -------------------------------------------------------------------------
+
+    private String sendTo;
+
+    public void setSendTo( String sendTo )
+    {
+        this.sendTo = sendTo;
+    }
+
+    public String getSendTo()
+    {
+        return sendTo == null || sendTo.trim().isEmpty() ? "phone" : sendTo;
+    }
 
     public Map<String, String> getGatewayMap()
     {
         return transportService.getGatewayMap();
     }
 
+    private List<UserGroup> userGroups;
+
+    public List<UserGroup> getUserGroups()
+    {
+        return userGroups;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -65,6 +93,10 @@
     public String execute()
         throws Exception
     {
+        userGroups = new ArrayList<UserGroup>( userGroupService.getAllUserGroups() );
+
+        Collections.sort( userGroups, new UserGroupComparator() );
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2013-01-22 09:45:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2013-02-21 06:44:09 +0000
@@ -139,6 +139,12 @@
 smpp_gw=SMPP gateway
 processing=Processing
 mark_as_default=Mark as default
+user_group=User Group
+there_is_no_user_assigned_to_selected_units=There is no user assigned to selected units
+selected_units_have_no_phone_number=The selected units have no phone number
+selected_persons_have_no_phone_number=The selected persons have no phone number
+selected_user_group_is_unavailable=The selected user group is unavailable
+selected_user_group_has_no_member=The selected user group has no member
 
 # ------------------------------------------------------------------------------
 # SMS COMMAND LOCALIZATION 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module_vi_VN.properties	2013-01-22 09:45:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module_vi_VN.properties	2013-02-21 06:44:09 +0000
@@ -75,6 +75,12 @@
 sms_configuration_not_initialized=D\u1ecbch v\u1ee5 tin nh\u1eafn ch\u01b0a \u0111\u01b0\u1ee3c kh\u1edfi t\u1ea1o.\nH\u00e3y cung c\u1ea5p hai th\u00f4ng s\u1ed1 b\u00ean d\u01b0\u1edbi v\u00e0o l\u01b0u l\u1ea1i.
 processing=\u0110ang x\u1eed l\u00fd
 mark_as_default=Ch\u1ecdn l\u00e0m m\u1eb7c \u0111\u1ecbnh
+user_group=Nh\u00f3m ng\u01b0\u1eddi d\u00f9ng
+there_is_no_user_assigned_to_selected_units=Kh\u00f4ng c\u00f3 ng\u01b0\u1eddi d\u00f9ng n\u00e0o \u0111\u01b0\u1ee3c g\u00e1n v\u00e0o c\u00e1c \u0111\u01a1n v\u1ecb \u0111\u01b0\u1ee3c ch\u1ecdn
+selected_units_have_no_phone_number=C\u00e1c \u0111\u01a1n v\u1ecb \u0111\u01b0\u1ee3c ch\u1ecdn \u0111\u1ec1u kh\u00f4ng c\u00f3 s\u1ed1 di \u0111\u1ed9ng \u0111i k\u00e8m
+selected_persons_have_no_phone_number=C\u00e1c b\u1ec7nh nh\u00e2n \u0111\u01b0\u1ee3c ch\u1ecdn \u0111\u1ec1u kh\u00f4ng c\u00f3 s\u1ed1 di \u0111\u1ed9ng \u0111i k\u00e8m
+selected_user_group_is_unavailable=Nh\u00f3m ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0\u1ee3c ch\u1ecdn hi\u1ec7n kh\u00f4ng t\u1ed3n t\u1ea1i
+selected_user_group_has_no_member=Nh\u00f3m ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0\u1ee3c ch\u1ecdn hi\u1ec7n kh\u00f4ng c\u00f3 th\u00e0nh vi\u00ean
 
 # ------------------------------------------------------------------------------
 # SMS COMMAND LOCALIZATION 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sendSMS.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sendSMS.js	2013-01-22 08:31:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sendSMS.js	2013-02-21 06:44:09 +0000
@@ -11,6 +11,14 @@
 	if ( _value == "phone" ) 
 	{
 		showById( 'phoneType' );
+		showById( 'trRawPhone' );
+		hideById( 'orgunitType' );
+		hideById( 'trUserGroup' );
+	}
+	else if ( _value == "userGroup" )
+	{
+		showById( 'trUserGroup' );
+		hideById( 'trRawPhone' );
 		hideById( 'orgunitType' );
 	}
 	else if ( _value == "user" || _value == "unit" )
@@ -18,8 +26,10 @@
 		selectionTree.clearSelectedOrganisationUnits();
 		selectionTree.buildSelectionTree();
 	
+		showById( 'orgunitType' );
 		hideById( 'phoneType' );
-		showById( 'orgunitType' );
+		hideById( 'trRawPhone' );
+		hideById( 'trUserGroup' );
 	}
 	else {
 		window.location.href = "showBeneficiarySMSForm.action";

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendBeneficiarySMSPage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendBeneficiarySMSPage.vm	2013-01-22 08:31:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendBeneficiarySMSPage.vm	2013-02-21 06:44:09 +0000
@@ -50,8 +50,9 @@
 			
 			<tr>
 				<td>$i18n.getString( "send_sms_to_target" ): 
-					<select id="sendTarget" name="sendTarget" onchange="javascript:toggleBasicSMSGUI();">
+					<select id="sendTarget" name="sendTarget" onchange="javascript:toggleBasicSMSGUI( this.value );">
 						<option value="phone">$i18n.getString( "raw_phone_number" )</option>
+						<option value="userGroup">$i18n.getString( "user_group" )</option>
 						<option value="user">$i18n.getString( "assigned_user_number" )</option>
 						<option value="unit">$i18n.getString( "stakeholder_number" )</option>
 						<option value="patient" selected="true">$i18n.getString( "patient_number" )</option>
@@ -136,9 +137,9 @@
 
 	var isOrgunitSelected = false;
 
-	function toggleBasicSMSGUI()
+	function toggleBasicSMSGUI( _value )
 	{
-		window.location.href = "showSMSForm.action";
+		window.location.href = "showSMSForm.action?sendTo=" + _value;
 	}
 
 	function selectedOrganisationUnitSendSMS( unitIds )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm	2013-01-22 08:31:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm	2013-02-21 06:44:09 +0000
@@ -4,7 +4,17 @@
 		
 		selectionTreeSelection.setListenerFunction( selectedOrganisationUnitSendSMS );
 
-		toggleSMSGUI( "phone" );
+		var target = '${sendTo}';
+		
+		jQuery( "#sendTarget > option" ).each( function( item ) {
+			
+			if ( item.value == target )
+			{
+				item.selected = true;
+			}
+		} );
+		
+		toggleSMSGUI( target );
 	});
 	
 	var i18n_no_recipient = '$encoder.jsEscape( $i18n.getString( "no_recipient" ) , "'")';
@@ -46,13 +56,22 @@
 				<td>$i18n.getString( "send_sms_to_target" ):
 					<select id="sendTarget" name="sendTarget" onchange="javascript:toggleSMSGUI( this.value );">
 						<option value="phone">$i18n.getString( "raw_phone_number" )</option>
+						<option value="userGroup">$i18n.getString( "user_group" )</option>
 						<option value="user">$i18n.getString( "assigned_user_number" )</option>
 						<option value="unit">$i18n.getString( "stakeholder_number" )</option>
 						<option value="patient">$i18n.getString( "patient_number" )</option>
 					</select>
 				</td>
 			</tr>
-			<tr>
+			<tr id="trUserGroup" style="display:none">
+				<td>$i18n.getString( "user_group" ):
+				<select id="userGroup" name="userGroup">
+				#foreach( $group in $userGroups )
+					<option value="$group.id">$!encoder.htmlEncode( $group.name )</option>
+				#end
+				</select></td>
+			</tr>
+			<tr id="trRawPhone">
 				<td>$i18n.getString( "phone_number" ): <input type="text" id="recipient" name="recipient" style="width:53%"/></td>
 			</tr>