← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9562: (mobile) Sending SMS - Post an array to server using jQuery.

 

------------------------------------------------------------
revno: 9562
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-01-21 11:36:02 +0700
message:
  (mobile) Sending SMS - Post an array to server using jQuery.
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/webapp/dhis-web-maintenance-mobile/javascript/sendSMS.js


--
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	2012-05-09 02:52:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java	2013-01-21 04:36:02 +0000
@@ -27,10 +27,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.annotate.JsonMethod;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
@@ -127,6 +134,7 @@
     // Action Implementation
     // -------------------------------------------------------------------------
 
+    @SuppressWarnings( "unchecked" )
     public String execute()
     {
         if ( gatewayId == null || gatewayId.isEmpty() )
@@ -145,6 +153,26 @@
 
         if ( sendTarget != null && sendTarget.equals( "phone" ) )
         {
+            try
+            {
+                ObjectMapper mapper = new ObjectMapper().setVisibility( JsonMethod.FIELD, Visibility.ANY );
+                mapper.configure( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false );
+
+                recipients = mapper.readValue( recipients.iterator().next(), Set.class );
+            }
+            catch ( JsonParseException e )
+            {
+                e.printStackTrace();
+            }
+            catch ( JsonMappingException e )
+            {
+                e.printStackTrace();
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace();
+            }
+
             message = messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), true,
                 recipients, gatewayId );
         }
@@ -183,6 +211,26 @@
             Patient patient = null;
             Set<String> phones = new HashSet<String>();
 
+            try
+            {
+                ObjectMapper mapper = new ObjectMapper().setVisibility( JsonMethod.FIELD, Visibility.ANY );
+                mapper.configure( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false );
+
+                recipients = mapper.readValue( recipients.iterator().next(), Set.class );
+            }
+            catch ( JsonParseException e )
+            {
+                e.printStackTrace();
+            }
+            catch ( JsonMappingException e )
+            {
+                e.printStackTrace();
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace();
+            }
+
             for ( String patientId : recipients )
             {
                 patient = patientService.getPatient( Integer.parseInt( patientId ) );

=== 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	2012-05-09 02:52:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sendSMS.js	2013-01-21 04:36:02 +0000
@@ -40,7 +40,9 @@
 
 function sendSMSMessage( _form )
 {
-	var params = "";
+	var params = "?";
+	var p = {};
+	p.recipients = [];
 
 	if ( _target == "phone" )
 	{
@@ -58,11 +60,9 @@
 		{
 			if ( list[i] && list[i] != '' )
 			{
-				params += "recipients=" + list[i] + "&";
+				p.recipients.push( list[i] );
 			}
 		}
-
-		params = "?" + params.substring( 0, params.length - 1 );
 	}
 	else if ( _target == "user" || _target == "unit" )
 	{
@@ -76,13 +76,18 @@
 	{
 		if ( hasElements( 'recipients' ) )
 		{
-			params = "?" + getParamString( 'recipients', 'recipients' );
+			var list = jQuery( '#recipients' ).children();
+	
+			list.each( function( i, item ){
+				p.recipients.push( item.value );
+			});
 		}
 		else { markInvalid( "recipients", i18n_list_empty ); }
 	}
 
-	jQuery.postUTF8( _form.action + params,
+	jQuery.postUTF8( _form.action,
 	{
+		recipients: JSON.stringify( p.recipients ),
 		gatewayId: getFieldValue( 'gatewayId' ),
 		smsMessage: getFieldValue( 'smsMessage' ),
 		sendTarget: getFieldValue( 'sendTarget' )