← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10974: improve reimport function

 

------------------------------------------------------------
revno: 10974
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Fri 2013-05-24 16:21:22 +0700
message:
  improve reimport function
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sms.js
modified:
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReimportSMSAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.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-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-05-23 08:05:27 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/DefaultParserManager.java	2013-05-24 09:21:22 +0000
@@ -122,6 +122,7 @@
 
     @Transactional
     public void parse( IncomingSms sms )
+        throws SMSParserException
     {
         try
         {
@@ -135,7 +136,7 @@
             sms.setStatus( SmsMessageStatus.FAILED );
             incomingSmsService.update( sms );
             sendSMS( e.getMessage(), sms.getOriginator() );
-            return;
+            throw e;
         }
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReimportSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReimportSMSAction.java	2013-05-23 08:05:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ReimportSMSAction.java	2013-05-24 09:21:22 +0000
@@ -63,6 +63,18 @@
     {
         this.incomingSMS = incomingSMS;
     }
+    
+    private String message;
+    
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public void setMessage( String message )
+    {
+        this.message = message;
+    }
 
     // -------------------------------------------------------------------------
     // Action Implementation
@@ -82,10 +94,12 @@
         try
         {
             parserManager.parse( incomingSMS );
+            message = "SMS imported";
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
+            message = e.getMessage();
+            return "error";
         }
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml	2013-05-23 08:05:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml	2013-05-24 09:21:22 +0000
@@ -55,7 +55,9 @@
     </action>
     
     <action name="reimport" class="org.hisp.dhis.mobile.action.incoming.ReimportSMSAction">
-      <result name="success" type="redirect">showReceivingPage.action</result>
+      <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <result name="error" type="velocity-json">../dhis-web-commons/ajax/jsonResponseError.vm</result>
+      <param name="onExceptionReturn">plainTextError</param>
     </action>
 	
     <!-- Patient Mobile Setting Action -->

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sms.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sms.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/sms.js	2013-05-24 09:21:22 +0000
@@ -0,0 +1,43 @@
+// -----------------------------------------------------------------------------
+// Change what type of sms to show
+// -----------------------------------------------------------------------------
+
+function criteriaChanged()
+{
+    var status = getListValue( "smsStatus" );
+
+    var url = "showReceivingPage.action?smsStatus=" + status;
+
+    window.location.href = url;
+}
+
+function reimport( itemId, itemName, success )
+{                
+    var result = window.confirm( "confirm_delete" + "\n\n" + itemName );
+    var action = "reimport.action";
+    if ( result )
+    {
+    	$.postJSON(
+    	    action,
+    	    {
+    	        "incomingSMSId": itemId   
+    	    },
+    	    function( json )
+    	    { 
+    	    	if ( json.response == "success" )
+    	    	{  
+					if ( success && typeof( success) == "function" )
+					{
+						success.call();
+					}
+  
+					showSuccessMessage( json.message );
+    	    	}
+    	    	else if ( json.response == "error" )
+    	    	{ 
+					showWarningMessage( json.message );
+    	    	}
+    	    }
+    	);
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm	2013-05-23 08:05:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm	2013-05-24 09:21:22 +0000
@@ -1,4 +1,4 @@
-
+<script type="text/javascript" src="javascript/sms.js"></script>
 <script type="text/javascript">
 	 jQuery(document).ready(function() {
 		checkNewMsg();
@@ -198,7 +198,7 @@
 					<input type="hidden" id="$incomingSms.id" value="$incomingSms.text" onblur="makeVisible( $incomingSms.id, $velocityCount )"/></td>
 				<td>$incomingSms.originator</td>
 				<td>$incomingSms.status</td>
-				<td style="text-align:center">#if($incomingSms.status == 'FAILED' || $incomingSms.status == 'INCOMING')<a href="reimport.action?incomingSMSId=$incomingSms.id"> Re-import </a> #else None #end</td>
+				<td style="text-align:center">#if($incomingSms.status == 'FAILED' || $incomingSms.status == 'INCOMING')<a href="javascript:reimport('$incomingSms.id', '$incomingSms.text')"> Re-import </a> #else None #end</td>
 				<td style="text-align:center"><a href="javascript:removeSingleItem( '$incomingSms.id', '$incomingSms.getText()' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></td>				
 			</tr>
 			#end