← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10891: fixed upload of coordinate in anonymous (offline), also other minor fixes

 

------------------------------------------------------------
revno: 10891
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-05-19 16:15:33 +0700
message:
  fixed upload of coordinate in anonymous (offline), also other minor fixes
removed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.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-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java	2013-05-18 06:07:28 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java	2013-05-19 09:15:33 +0000
@@ -47,10 +47,10 @@
     {
     }
 
-    public Coordinate( Double latitude, Double longitude )
+    public Coordinate( Double longitude, Double latitude )
     {
+        this.longitude = longitude;
         this.latitude = latitude;
-        this.longitude = longitude;
     }
 
     @JsonProperty( required = true )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java	2013-04-18 15:32:46 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java	2013-05-19 09:15:33 +0000
@@ -32,6 +32,7 @@
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dxf2.event.Coordinate;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -139,7 +140,25 @@
 
         Boolean completed = (Boolean) executionDate.get( "completed" );
 
-        ProgramStageInstance programStageInstance = saveExecutionDate( programId, organisationUnitId, date, completed );
+        Coordinate coordinate = null;
+        Map<String, String> coord = (Map<String, String>) input.get( "coordinate" );
+
+        if ( coord != null )
+        {
+            try
+            {
+                double lng = Double.parseDouble( coord.get( "longitude" ) );
+                double lat = Double.parseDouble( coord.get( "latitude" ) );
+
+                coordinate = new Coordinate( lng, lat );
+            }
+            catch ( NullPointerException ignored )
+            {
+            }
+
+        }
+
+        ProgramStageInstance programStageInstance = saveExecutionDate( programId, organisationUnitId, date, completed, coordinate );
 
         Map<String, Object> values = (Map<String, Object>) input.get( "values" );
 
@@ -160,7 +179,8 @@
         return SUCCESS;
     }
 
-    private ProgramStageInstance saveExecutionDate( Integer programId, Integer organisationUnitId, Date date, Boolean completed )
+    private ProgramStageInstance saveExecutionDate( Integer programId, Integer organisationUnitId, Date date, Boolean completed,
+        Coordinate coordinate )
     {
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
         Program program = programService.getProgram( programId );
@@ -181,6 +201,18 @@
             programStageInstance.setCompletedUser( currentUserService.getCurrentUsername() );
         }
 
+        if ( programStage.getCaptureCoordinates() )
+        {
+            if ( coordinate != null && coordinate.isValid() )
+            {
+                programStageInstance.setCoordinates( coordinate.getCoordinateString() );
+            }
+            else
+            {
+                programStageInstance.setCoordinates( null );
+            }
+        }
+
         programStageInstanceService.addProgramStageInstance( programStageInstance );
 
         message = programStageInstance.getId() + "";

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2013-05-15 09:14:57 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2013-05-19 09:15:33 +0000
@@ -131,7 +131,6 @@
         ,javascript/commons.js
         ,javascript/anonymousRegistration.js
         ,javascript/entry.js
-        ,javascript/dhis2.storage.anonymous.js
         ,../dhis-web-commons/javascripts/date.js
       </param>
       <param name="stylesheets">style/style.css</param>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-05-19 05:57:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-05-19 09:15:33 +0000
@@ -14,7 +14,8 @@
 
     $.ajax( {
         url: 'getProgramMetaData.action',
-        dataType: 'json'
+        dataType: 'json',
+        cache: false
     } ).done(function ( data ) {
         var programs = _.values( data.metaData.programs );
         DAO.store.setAll( 'programs', programs ).then( function () {
@@ -44,7 +45,8 @@
             return $.ajax( {
                 url: 'dataentryform.action',
                 data: data,
-                dataType: 'html'
+                dataType: 'html',
+                cache: false
             } ).done( function ( data ) {
                     var obj = {};
                     obj.id = psid;
@@ -76,7 +78,8 @@
         promise = promise.then( function () {
             return $.ajax( {
                 url: 'getOptionSet.action?dataElementUid=' + item,
-                dataType: 'json'
+                dataType: 'json',
+                cache: false
             } ).done( function ( data ) {
                 var obj = {};
                 obj.id = item;
@@ -90,7 +93,8 @@
         promise = promise.then( function () {
             return $.ajax( {
                 url: 'getUsernames.action',
-                dataType: 'json'
+                dataType: 'json',
+                cache: false
             } ).done( function ( data ) {
                     var obj = {};
                     obj.id = 'usernames';
@@ -163,14 +167,15 @@
     } );
 }
 
-function uploadOfflineData( item ) {
+function uploadOfflineData( event ) {
     $.ajax( {
         url: 'uploadAnonymousEvent.action',
         contentType: 'application/json',
-        data: JSON.stringify( item )
+        data: JSON.stringify( event ),
+        cache: false
     } ).done( function ( json ) {
         if ( json.response == 'success' ) {
-            DAO.store.delete( 'dataValues', item.id ).done( function () {
+            DAO.store.delete( 'dataValues', event.id ).done( function () {
                 updateOfflineEvents();
                 searchEvents( eval( getFieldValue( 'listAll' ) ) );
             } );
@@ -282,7 +287,7 @@
     $( document ).bind( 'dhis2.offline', function () {
         setHeaderMessage( i18n_offline_notification );
         $('#commentInput').attr('disabled', true);
-        $('#commentButton').attr('disabled', true);
+        $('#commentInput').attr('disabled', true);
         $('#validateBtn').attr('disabled', true);
         disableFiltering();
         showOfflineEvents();
@@ -498,6 +503,7 @@
             $.ajax( {
                 url: "getOptions.action?id=" + searchObjectId + "&query=" + input.val(),
                 dataType: "json",
+                cache: false,
                 success: function ( data ) {
                     response( $.map( data.options, function ( item ) {
                         return {
@@ -560,7 +566,7 @@
             $.ajax( {
                 url: "getUsernameList.action?query=" + input.val(),
                 dataType: "json",
-                cache: true,
+                cache: false,
                 success: function ( data ) {
                     response( $.map( data.usernames, function ( item ) {
                         return {
@@ -742,6 +748,7 @@
         url: 'searchProgramStageInstances.action',
         data: params,
         dataType: 'text',
+        cache: false,
         success: function ( data ) {
             if ( data.indexOf( "<!DOCTYPE" ) != 0 ) {
                 hideById( 'dataEntryInfor' );
@@ -944,7 +951,8 @@
         url: 'saveExecutionDate.action',
         data: createExecutionDate( programId, programStageInstanceId, executionDate, organisationUnitId ),
         type: 'POST',
-        dataType: 'json'
+        dataType: 'json',
+        cache: false
     } );
 }
 
@@ -1085,7 +1093,8 @@
         $.ajax( {
             url: 'dataentryform.action',
             data: data,
-            dataType: 'html'
+            dataType: 'html',
+            cache: false
         } ).done(function(data) {
             if(success) success(data);
         } ).fail(function() {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-05-19 06:46:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-05-19 09:15:33 +0000
@@ -2028,6 +2028,7 @@
                 longitude: longitude,
                 latitude: latitude
             },
+            cache: false,
             dataType: 'json'
         } ).done(function() {
             byId( 'longitude' ).style.backgroundColor = SUCCESS_COLOR;
@@ -2035,9 +2036,9 @@
         } ).fail(function() {
             if(DAO.store && programStageInstanceId.indexOf('local') != -1 ) {
                 DAO.store.get( 'dataValues', programStageInstanceId ).done( function ( data ) {
-                    data.coordinates = {};
-                    data.coordinates.longitude = longitude;
-                    data.coordinates.latitude = latitude;
+                    data.coordinate = {};
+                    data.coordinate.longitude = longitude;
+                    data.coordinate.latitude = latitude;
 
                     this.set( 'dataValues', data ).done( function () {
                         byId( 'longitude' ).style.backgroundColor = SUCCESS_COLOR;

=== removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js	2013-05-03 04:18:04 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js	1970-01-01 00:00:00 +0000
@@ -1,32 +0,0 @@
-/*
-dhis2.storage.Store.plugin( 'online-anonymous-programs', (function () {
-    return {
-        call: function ( args, success, failure ) {
-            return $.ajax( {
-                type: 'POST',
-                url: "anonymousPrograms.action",
-                data: args,
-                dataType: 'json'
-            } ).success( function ( data ) {
-                var arr = data.programs;
-
-                for ( var i = 0; i < arr.length; i++ ) {
-                    arr[i].key = arr[i].id;
-                    arr[i].programStages = [];
-                    arr[i].programStages[0] = {
-                        id: arr[i].programStageId,
-                        reportDateDescription: arr[i].reportDateDescription
-                    };
-
-                    delete arr[i].id;
-                    delete arr[i].programStageId;
-                    delete arr[i].reportDateDescription;
-                    delete arr[i].type;
-                }
-
-                if ( success ) success( arr );
-            } ).fail(failure);
-        }
-    };
-})() );
-*/

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-05-19 06:46:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-05-19 09:15:33 +0000
@@ -258,6 +258,7 @@
            url: "saveValue.action",
            data: params,
            dataType: "xml",
+           cache: false,
            success: function(result){
                 handleResponse (result);
            },
@@ -343,6 +344,7 @@
 			   url: "saveProvidingFacility.action",
 			   data: params,
 			   dataType: "xml",
+               cache: false,
 			   success: function(result){
 					handleResponse (result);
 			   },
@@ -387,7 +389,8 @@
 			   url: "saveExecutionDate.action",
 			   data: params,
 			   dataType: "json",
-			   success: function( json ){	
+               cache: false,
+			   success: function( json ){
 					var selectedProgramStageInstance = jQuery( '#' + prefixId + getFieldValue('programStageInstanceId') );
 					var box = jQuery(".stage-object-selected");
 					var boxName = box.attr('psname') + "\n" + executionDate;
@@ -544,6 +547,7 @@
             $.ajax({
                 url: 'completeDataEntry.action',
                 dataType: 'json',
+                cache: false,
                 data: {
                     programStageInstanceId: getFieldValue( 'programStageInstanceId' )
                 },
@@ -628,6 +632,7 @@
         $.ajax({
             url: 'uncompleteDataEntry.action',
             dataType: 'json',
+            cache: false,
             data: {
                 programStageInstanceId: getFieldValue( 'programStageInstanceId' )
             },
@@ -737,9 +742,13 @@
                     });
                 }
 
-                if ( obj.coordinates !== undefined ) {
-                    $( '#longitude' ).val( obj.coordinates.longitude );
-                    $( '#latitude' ).val( obj.coordinates.latitude );
+                if ( obj.coordinate !== undefined ) {
+                    $( '#longitude' ).val( obj.coordinate.longitude );
+                    $( '#latitude' ).val( obj.coordinate.latitude );
+                }
+
+                if ( obj.executionDate.completed !== undefined ) {
+                    $( "#entryFormContainer input[id='completed']" ).val( obj.executionDate.completed );
                 }
             }
 
@@ -752,6 +761,7 @@
     } else {
         return $.ajax({
             url: 'getProgramStageInstance.action',
+            cache: false,
             data: {
                 'programStageInstanceId': programStageInstanceId
             },
@@ -949,7 +959,7 @@
     $.ajax( {
         url: "getOptions.action?id=" + uid + "&query=" + query,
         dataType: "json",
-        cache: true,
+        cache: false,
         success: function ( data ) {
             success( $.map( data.options, function ( item ) {
                 return {
@@ -1076,7 +1086,7 @@
     return $.ajax( {
         url: "getUsernameList.action?query=" + query,
         dataType: "json",
-        cache: true,
+        cache: false,
         success: function ( data ) {
             success( $.map( data.usernames, function ( item ) {
                 return {