dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26669
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13189: sms-web support quick send option
------------------------------------------------------------
revno: 13189
committer: Hong Em <em.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-10 18:23:29 +0700
message:
sms-web support quick send option
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ProcessingSendQuickSMSAction.java
modified:
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
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ProcessingSendQuickSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ProcessingSendQuickSMSAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/ProcessingSendQuickSMSAction.java 2013-12-10 11:23:29 +0000
@@ -0,0 +1,288 @@
+package org.hisp.dhis.mobile.action.incoming;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
+import org.hisp.dhis.sms.task.SendSmsTask;
+import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.system.scheduling.Scheduler;
+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.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.opensymphony.xwork2.Action;
+
+public class ProcessingSendQuickSMSAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private SelectionTreeManager selectionTreeManager;
+
+ @Autowired
+ private CurrentUserService currentUserService;
+
+ @Autowired
+ private UserGroupService userGroupService;
+
+ @Autowired
+ private OutboundSmsTransportService transportService;
+
+ @Autowired
+ private Scheduler scheduler;
+
+ @Autowired
+ private Notifier notifier;
+
+ @Autowired
+ private SendSmsTask sendSmsTask;
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
+
+ private String gatewayId;
+
+ public void setGatewayId( String gatewayId )
+ {
+ this.gatewayId = gatewayId;
+ }
+
+ private String smsSubject;
+
+ public void setSmsSubject( String smsSubject )
+ {
+ this.smsSubject = smsSubject;
+ }
+
+ private String text;
+
+ public void setText( String text )
+ {
+ this.text = text;
+ }
+
+ private String sendTarget;
+
+ public void setSendTarget( String sendTarget )
+ {
+ 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 )
+ {
+ this.recipients = recipients;
+ }
+
+ private String message = "success";
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ // -------------------------------------------------------------------------
+ // I18n
+ // -------------------------------------------------------------------------
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action Implementation
+ // -------------------------------------------------------------------------
+
+ @SuppressWarnings( "unchecked" )
+ public String execute()
+ throws Exception
+ {
+ gatewayId = transportService.getDefaultGateway();
+
+ if ( gatewayId == null || gatewayId.trim().length() == 0 )
+ {
+ message = i18n.getString( "please_select_a_gateway_type_to_send_sms" );
+
+ return ERROR;
+ }
+
+ if ( text == null || text.trim().length() == 0 )
+ {
+ message = i18n.getString( "no_message" );
+
+ return ERROR;
+ }
+
+ User currentUser = currentUserService.getCurrentUser();
+
+ List<User> recipientsList = new ArrayList<User>();
+
+ // Set<User> recipientsList = new HashSet<User>();
+
+ if ( sendTarget != null && sendTarget.equals( "phone" ) )
+ {
+ ObjectMapper mapper = new ObjectMapper().setVisibility( PropertyAccessor.FIELD,
+ JsonAutoDetect.Visibility.ANY );
+ mapper.disable( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES );
+ recipients = mapper.readValue( recipients.iterator().next(), Set.class );
+
+ for ( String each : recipients )
+ {
+ if ( !each.startsWith( "+" ) )
+ {
+ each = "+" + each;
+ }
+
+ User user = new User();
+ user.setPhoneNumber( each );
+ recipientsList.add( user );
+ }
+ // message = messageSender.sendMessage( smsSubject, smsMessage,
+ // currentUser, true, recipients, gatewayId );
+ }
+ else if ( sendTarget.equals( "userGroup" ) )
+ {
+ UserGroup group = userGroupService.getUserGroup( userGroup );
+
+ if ( group == null )
+ {
+ message = i18n.getString( "selected_user_group_is_unavailable" );
+
+ return ERROR;
+ }
+
+ if ( group.getMembers() == null || group.getMembers().isEmpty() )
+ {
+ message = i18n.getString( "selected_user_group_has_no_member" );
+
+ return ERROR;
+ }
+
+ recipientsList = new ArrayList<User>( group.getMembers() );
+ }
+ else if ( sendTarget.equals( "user" ) )
+ {
+ Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits();
+
+ if ( units != null && !units.isEmpty() )
+ {
+ for ( OrganisationUnit unit : units )
+ {
+ recipientsList.addAll( unit.getUsers() );
+ }
+
+ if ( recipientsList.isEmpty() )
+ {
+ message = i18n.getString( "there_is_no_user_assigned_to_selected_units" );
+
+ return ERROR;
+ }
+
+ // message = messageSender.sendMessage( smsSubject, smsMessage,
+ // currentUser, false, users, gatewayId );
+ }
+ }
+ else if ( sendTarget.equals( "unit" ) )
+ {
+ for ( OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits() )
+ {
+ if ( unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty() )
+ {
+ User user = new User();
+ user.setPhoneNumber( unit.getPhoneNumber() );
+ recipientsList.add( user );
+ }
+ }
+
+ if ( recipientsList.isEmpty() )
+ {
+ message = i18n.getString( "selected_units_have_no_phone_number" );
+
+ return ERROR;
+ }
+ }
+
+ TaskId taskId = new TaskId( TaskCategory.SENDING_SMS, currentUser );
+ notifier.clear( taskId );
+
+ sendSmsTask.setTaskId( taskId );
+ sendSmsTask.setCurrentUser( currentUser );
+ sendSmsTask.setRecipientsList( recipientsList );
+ sendSmsTask.setSmsSubject( smsSubject );
+ sendSmsTask.setText( text );
+
+ scheduler.executeTask( sendSmsTask );
+
+ if ( message != null && !message.equals( "success" ) )
+ {
+ message = i18n.getString( message );
+
+ return ERROR;
+ }
+ if ( message == null )
+ {
+ message = "An inter error occurs, please contact your administration";
+ 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-11-29 08:05:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml 2013-12-10 11:23:29 +0000
@@ -14,6 +14,16 @@
<param name="page">/dhis-web-maintenance-mobile/index.vm</param>
<param name="menu">/dhis-web-maintenance-mobile/menu.vm</param>
</action>
+
+ <!-- Sending SMS Action -->
+
+ <action name="sendSMS"
+ class="org.hisp.dhis.mobile.action.ProcessingSendQuickSMSAction">
+ <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>
+ <param name="requiredAuthorities">F_MOBILE_SENDSMS</param>
+ </action>
<!-- Sent SMS -->
=== 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-09-10 17:59:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/receiveSMSPage.vm 2013-12-10 11:23:29 +0000
@@ -111,6 +111,7 @@
function makeVisible( idInput, idText )
{
+
if ( document.getElementById( idInput ).type == 'hidden')
{
document.getElementById( idInput ).type = 'text';
@@ -142,7 +143,28 @@
);
}
};
+ function sendQuickSMS(message, originator)
+ {
+ var p = {};
+ p.recipients.push( originator );
+
+ jQuery.postUTF8( sendSMS.action,
+ {
+ recipient: JSON.stringify( p.recipients ),
+ text: getFieldValue('sm' + message),
+ sendTarget: 'phone',
+ }, function ( json )
+ {
+ if ( json.response == "success" ) {
+ setHeaderDelayMessage( json.message );
+ }
+ else {
+ setHeaderDelayMessage( json.message, 7000 );
+ }
+ } );
+ };
+
function criteriaChanged(list)
{
var status = list.options[list.selectedIndex].value;
@@ -153,11 +175,30 @@
};
var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_sms" ) , "'")';
+
+ function conceal() {
+ if(document.getElementById('idDiv').style.display=='block') {
+ document.getElementById('idDiv').style.display='none';
+ }
+ }
+
+ function show(divId) {
+ if(document.getElementById('dv' + divId).style.display=='none') {
+ document.getElementById('dv' + divId).style.display='block';
+ }
+ }
+
+
+
</script>
<input id="pollingInterval" name="pollingInterval" type="hidden" value="$pollingInterval"/>
<h3>$i18n.getString( "show_receive_sms_form" )</h3>
<form id="receiveSmsPage" name="receiveSmsPage" action="showReceivingPage.action" method="get" >
+
+
+
+
<table border="0px" style="width:100%">
<tr>
<td style="width:130px">$i18n.getString('filter_by_status'):</td>
@@ -175,7 +216,7 @@
<td style="width:135px">$i18n.getString('filter_by_phone_number'):</td>
<td style="width:150px"><input type="text" name="keyword" #if($keyword) value="$keyword" #else value="" #end style="width: 150px; height: 10px"/></td>
<td style="width:50px"><input type="submit" name="filter" value="Filter"/></td>
- <td style="text-align:right"><input type="button" name="btnDelete" value="$i18n.getString( 'delete_checked_option' )" onclick="deleteChecked()"/></td>
+ <td style="text-align:right"><input type="button" name="btnDelete" value="$i18n.getString( 'delete_checked_option' )" onclick="deleteChecked()"/></td>
</tr>
<tr>
<td style="width:130px">$i18n.getString( "total_number_of_result" ):</td>
@@ -198,14 +239,28 @@
<th style="text-align:center">$i18n.getString( "delete" )</th>
</thead>
<tbody>
+
#foreach( $incomingSms in $listIncomingSms )
+
<tr id="tr${incomingSms.id}" height="40">
<td style="text-align:center"><input type="checkbox" name="mycheck" value="$incomingSms.id"/></td>
<td style="text-align:center">$velocityCount</td>
<td>
+
<a id="$velocityCount" style="display: block" href="#" onclick="makeVisible( $incomingSms.id, $velocityCount )">$incomingSms.text</a>
<input type="hidden" id="$incomingSms.id" value="$incomingSms.text" onblur="makeVisible( $incomingSms.id, $velocityCount )"/></td>
- <td>$incomingSms.originator</td>
+
+ <td>
+
+ <a id="$incomingSms.id" href="#" onclick="show($velocityCount)" >$incomingSms.originator</a><br/>
+ <div id="dv$velocityCount" style="display: none;">
+ <textarea name="textArea" id="sm$velocityCount" rows="3" style="width:160px;"></textarea><br/>
+ <input type="submit" name="send" value="$i18n.getString( 'send' )" style="float: center;" onclick="sendQuickSMS($velocityCount, $incomingSms.originator)"/>
+ <input type="submit" name="btnCancel" value="$i18n.getString( 'cancel' )" style="float: center;"/>
+ </div>
+
+ </td>
+
<td>$senderNames.get($velocityCount)</td>
<td>$incomingSms.status</td>
<td>$incomingSms.sentDate.toLocaleString()</td>