← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7963: Added sorting of data elements and sms commands and simple validation of input in the sms command...

 

------------------------------------------------------------
revno: 7963
committer: Magnus Korvald <korvald@xxxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2012-08-24 14:14:49 +0200
message:
  Added sorting of data elements and sms commands and simple validation of input in the sms command edit view. 
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/smscommand/HibernateSMSCommandStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.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/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.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-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java	2012-06-13 08:44:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java	2012-08-24 12:14:49 +0000
@@ -2,46 +2,66 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 
-public class SMSCode {
-    
+public class SMSCode
+{
+
     int id; // hibernate
-    
+
     String code;
+
     DataElement dataElement;
+
     int optionId;
-    
-    public SMSCode(String code, DataElement dataElement, int optionId) {
+
+    public SMSCode( String code, DataElement dataElement, int optionId )
+    {
         this.code = code;
         this.dataElement = dataElement;
         this.optionId = optionId;
     }
-    
-    public SMSCode(){
-        
+
+    public SMSCode()
+    {
+
     }
-    
-    public int getId() {
+
+    public int getId()
+    {
         return id;
     }
-    public void setId(int id) {
+
+    public void setId( int id )
+    {
         this.id = id;
     }
-    public String getCode() {
+
+    public String getCode()
+    {
         return code;
     }
-    public void setCode(String code) {
+
+    public void setCode( String code )
+    {
         this.code = code;
     }
-    public DataElement getDataElement() {
+
+    public DataElement getDataElement()
+    {
         return dataElement;
     }
-    public void setDataElement(DataElement dataElement) {
+
+    public void setDataElement( DataElement dataElement )
+    {
         this.dataElement = dataElement;
     }
-    public int getOptionId() {
+
+    public int getOptionId()
+    {
         return optionId;
     }
-    public void setOptionId(int optionId) {
+
+    public void setOptionId( int optionId )
+    {
         this.optionId = optionId;
     }
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java	2012-08-22 06:31:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java	2012-08-24 12:14:49 +0000
@@ -1,5 +1,8 @@
 package org.hisp.dhis.smscommand;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 
 import org.hisp.dhis.dataset.DataSet;
@@ -96,6 +99,7 @@
         return codes;
     }
 
+
     public void setCodes(Set<SMSCode> codes) {
         this.codes = codes;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/smscommand/HibernateSMSCommandStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/smscommand/HibernateSMSCommandStore.java	2012-06-13 08:44:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/smscommand/HibernateSMSCommandStore.java	2012-08-24 12:14:49 +0000
@@ -7,66 +7,74 @@
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
+import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.smscommand.SMSCommandStore;
-import org.hisp.dhis.smscommand.SMSCode;
-import org.hisp.dhis.smscommand.SMSCommand;
 import org.springframework.beans.factory.annotation.Required;
 
-public class HibernateSMSCommandStore implements SMSCommandStore {
+public class HibernateSMSCommandStore
+    implements SMSCommandStore
+{
 
     protected SessionFactory sessionFactory;
 
     @Required
-    public void setSessionFactory(SessionFactory sessionFactory) {
+    public void setSessionFactory( SessionFactory sessionFactory )
+    {
         this.sessionFactory = sessionFactory;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     @Override
-    public Collection<SMSCommand> getSMSCommands() {
-        System.out.println("her: " + sessionFactory.getCurrentSession().createQuery("from SMSCommand").list());
-        return sessionFactory.getCurrentSession().createQuery("from SMSCommand").list();
+    public Collection<SMSCommand> getSMSCommands()
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( SMSCommand.class );
+        criteria.addOrder( Order.asc( "name" ) );
+        return criteria.list();
     }
 
-    public int save(SMSCommand cmd) {
+    public int save( SMSCommand cmd )
+    {
         Session s = sessionFactory.getCurrentSession();
         Transaction t = s.beginTransaction();
-        s.saveOrUpdate(cmd);
+        s.saveOrUpdate( cmd );
         t.commit();
         s.flush();
         return 0;
     }
-    
-    public void save(Set<SMSCode> codes){
+
+    public void save( Set<SMSCode> codes )
+    {
         Session s = sessionFactory.getCurrentSession();
         Transaction t = s.beginTransaction();
-        for(SMSCode x : codes){
-            s.saveOrUpdate(x);
+        for ( SMSCode x : codes )
+        {
+            s.saveOrUpdate( x );
         }
         t.commit();
-        s.flush();   
+        s.flush();
     }
 
-    public SMSCommand getSMSCommand(int id) {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SMSCommand.class);
-        criteria.add(Restrictions.eq("id", id));
-        if (criteria.list() != null && criteria.list().size() > 0)
-            return (SMSCommand) criteria.list().get(0);
+    public SMSCommand getSMSCommand( int id )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( SMSCommand.class );
+        criteria.add( Restrictions.eq( "id", id ) );
+        if ( criteria.list() != null && criteria.list().size() > 0 )
+            return (SMSCommand) criteria.list().get( 0 );
         else
             return null;
     }
-    
-    public void delete(SMSCommand cmd) {
+
+    public void delete( SMSCommand cmd )
+    {
         Session s = sessionFactory.getCurrentSession();
-        Transaction t = s.beginTransaction();     
-        for(SMSCode x : cmd.getCodes()){
-            s.delete(x);
+        Transaction t = s.beginTransaction();
+        for ( SMSCode x : cmd.getCodes() )
+        {
+            s.delete( x );
         }
-        s.delete(cmd);
+        s.delete( cmd );
         t.commit();
         s.flush();
     }
-    
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.java	2012-08-10 02:43:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.java	2012-08-24 12:14:49 +0000
@@ -1,11 +1,15 @@
 package org.hisp.dhis.mobile.action.smscommand;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.smscommand.SMSCode;
@@ -43,16 +47,19 @@
         return SUCCESS;
     }
 
-    public Set<DataElement> getDataSetElements()
+    public List<DataElement> getDataSetElements()
     {
         if ( getSMSCommand() != null )
         {
             DataSet d = getSMSCommand().getDataset();
             if ( d != null )
             {
-                return d.getDataElements();
+                List<DataElement> dataElements = new ArrayList<DataElement>( d.getDataElements() );
+                Collections.sort( dataElements, new DataElementSortOrderComparator() );
+                return dataElements;
             }
         }
+
         return null;
     }
 

=== 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	2012-08-22 07:08:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2012-08-24 12:14:49 +0000
@@ -35,7 +35,6 @@
 send_sms_beneficiary=Send SMS to Person
 list_sent_SMS=List Of Sent SMS
 add_gateway=Add Gateway
-gateway_type=Gateway Type
 type=Type
 gateway_configuration=Gateway Configuration
 gateway_name=Gateway Name
@@ -53,7 +52,6 @@
 save_settings=Save Settings
 add_gw=Add gateway
 start_sms_service=Start SMS Service
-stop_sms_service=Stop SMS Service
 show_send_sms_form=Send SMS
 bulk_gw=BulkSMS Gateway
 clickatell_gw=Clickatell Gateway
@@ -74,7 +72,6 @@
 message_not_sent=Message not sent
 message=Message
 send_sms_to_target=Send SMS to
-list_sent_SMS =List Of Sent SMS
 show_receive_sms_form =Receive SMS
 update_success=Update Successfully
 config_my_gateway =Configure My Gateway
@@ -94,7 +91,7 @@
 service_stopped_cannot_send_sms=Service is stopped. SMS cannot be sent.
 please_verify_phone=Please verify the phone number(s). Separate each number with a semicolon (;)
 please_select_orgunit=Please select at least one organisation unit
-no_recipient=There is no recipient. SMS cannot be sent.\nNotes: Make sure that "Message sms notification" Setting is activated.
+no_recipient=There is no recipient. SMS cannot be sent.\nNotes\: Make sure that "Message sms notification" Setting is activated.
 unable_load_gateway=Unable to load gateway
 unable_start_smslib_service=Unable to start smsLib service
 unable_stop_smslib_service=Unable to stop smsLib service
@@ -108,7 +105,6 @@
 list_all_patients=List all beneficiaries
 search=Search
 search_by_selected_unit=Search by selected unit
-please_select_village=Please select village
 please_select=Please Select
 activity_grouping_attribute=Activity Grouping Attribute
 sms_configuration_not_initialized=SMS Service is not initialized.\nPlease fill in two fields as below then click "Save Settings".
@@ -137,3 +133,15 @@
 j2me_client_update_config=J2ME Client Update Configuration
 auto_update_client=Automatic update for J2ME clients
 client_older_than=Update to clients older than version
+
+
+####
+## SMS COMMAND LOCALIZATION 
+####
+
+sms_command_validation_alert=Fix validation problems before you save
+name=Name 
+dataset=Dataset
+selected_dataset=Selected dataset
+code_value_separator=Code and value Separator
+no_codes_message=Reply message if no codes are sent (only the command):

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm	2012-08-22 06:31:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm	2012-08-24 12:14:49 +0000
@@ -1,5 +1,13 @@
 <script langauge="Javascript">
+
+    var VALIDATION_ERRORS = 0;
+
     function prepSubmit(){
+    
+      if(VALIDATION_ERRORS > 0){
+        alert("$i18n.getString( "sms_command_validation_alert" )");
+        return;
+      }
  
       var selectedDataOptions = '{"codes":[';      
       $("#codes input").each(function(){
@@ -12,20 +20,43 @@
      
       $("#codeDataelementOption").val(selectedDataOptions);
       $("#updateSMSCommand").submit(); 
-    }
+
+    }
+    
+    function validate(obj){
+        var validationErrorId = "#" + $(obj).attr("name") + "-validation-error";
+        validationErrorId = validationErrorId.replace(/\./g,'\\\.');
+        if(obj.value != null && obj.value.indexOf(" ") > -1){
+          if(!$(validationErrorId).length>0){
+            $(obj).after("<span id='" + $(obj).attr("name") + "-validation-error' style='color:red'>* whitespace not allowed</span>");
+            VALIDATION_ERRORS++;
+          }
+        }else{
+          if($(validationErrorId).length>0){
+            $(validationErrorId).remove();
+            VALIDATION_ERRORS--;
+          }
+        }
+    }
+    
+    $(document).ready(function() {   
+        $(".validate").each(function(){
+            validate(this);
+        });
+        $(".validate").change(function() {
+            validate(this);
+        });
+    });
+    
 </script>
 
 
 <div>
     </div>
 <h3>Edit command</h3>
+
 <form id="updateSMSCommand" name="updateSMSCommand" action="saveEditSMSCommandForm.action" method="post">
 
- <!-- 
-    * Unik kommando navn
-    * OID
- -->
-    
 	<table>
 	<thead>
       <tr>
@@ -39,18 +70,22 @@
 		</tr>
 		
 		<tr>
-			<td>Name:</td>
-			<td><input type="text" name="name" value="$SMSCommand.name" style="width:20em" /></td>
+			<td>$i18n.getString( "name" )</td>
+			<td><input type="text" name="name" id="name" value="$SMSCommand.name" style="width:20em" class="validate" /></td>
 		</tr>
-		<tr>
-			<td>Code and value Separator:</td>
+		
+		<tr>
+		  <td>$i18n.getString( "dataset" )</td>
+		  <td>#if($SMSCommand.dataset.name) $SMSCommand.dataset.name #end</td>
+		<tr>
+			<td>$i18n.getString( "code_value_separator" )</td>
 			<td>
-				<input type="text"  #if($SMSCommand.separator) value="$SMSCommand.separator" #end name="separator" style="width:20em" />
+				<input type="text"  #if($SMSCommand.separator) value="$SMSCommand.separator" #end name="separator" style="width:20em" class="validate" />
 			</td>
 		</tr> 
         <tr>
-            <td>Reply message if no codes <br /> are sent (only the command):</td>
-            <td><textarea type="text" name="defaultMessage">#if($SMSCommand.defaultMessage)$SMSCommand.defaultMessage#end</textarea></td>
+            <td>$i18n.getString( "no_codes_message" )</td>
+            <td><textarea cols="35" type="text" name="defaultMessage">#if($SMSCommand.defaultMessage)$SMSCommand.defaultMessage#end</textarea></td>
         </tr>	
 	</table>
 	
@@ -77,7 +112,7 @@
                                $dataElement.name $x.name
                            </td>
                            <td>
-                               <input type="text" name="$dataElement.id.$x.id" value='$!codes[$str]'>
+                               <input type="text" name="$dataElement.id.$x.id" value='$!codes[$str]' class="validate">
                            </td>
                        </tr>
                    #end
@@ -92,6 +127,6 @@
 	<br/>
 	
     <input type="hidden" name="codeDataelementOption" id="codeDataelementOption" />
-    <input  type="button" style="width: 100px" onclick="prepSubmit()" value="save" />
+    <input  type="button" style="width: 100px" onclick="prepSubmit()" value="$i18n.getString( "save" )" />
 	
 </form>
\ No newline at end of file