← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10584: if user is offline, save data values locally. no upload yet.

 

------------------------------------------------------------
revno: 10584
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-04-16 20:25:17 +0700
message:
  if user is offline, save data values locally. no upload yet.
modified:
  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/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-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-04-16 10:02:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-16 13:25:17 +0000
@@ -281,6 +281,7 @@
         jQuery( '#programId' ).append(
             '<option value="' + arr[i].key
             + '" puid="' + arr[i].uid
+            + '" programType="' + arr[i].type
             + '" psid="' + arr[i].programStages[0].id
             + '" psuid="' + arr[i].programStages[0].uid
             + '" reportDateDes="' + arr[i].programStages[0].reportDateDescription + '">'

=== 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-04-16 10:02:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-04-16 13:25:17 +0000
@@ -110,6 +110,16 @@
     }
 }
 
+function getProgramType() {
+    var programType = jQuery( '.stage-object-selected' ).attr( 'programType' );
+
+    if ( programType == undefined ) {
+        programType = jQuery( '#programId option:selected' ).attr( 'programType' );
+    }
+
+    return programType;
+}
+
 function getProgramStageUid() {
     var programStageUid = jQuery( '.stage-object-selected' ).attr( 'psuid' );
 
@@ -224,17 +234,19 @@
 	var value = value_;
 	var type = dataElementType_;
     var resultColor = resultColor_;
-	
+
     this.save = function()
     {
-		var params  = 'dataElementUid=' + dataElementUid;
-			params += '&programStageInstanceId=' + getFieldValue('programStageInstanceId');
-		
-		params += '&providedElsewhere=';
+        var params = 'dataElementUid=' + dataElementUid;
+            params += '&programStageInstanceId=' + getFieldValue( 'programStageInstanceId' );
+
+        params += '&providedElsewhere=';
+
 		if( byId( providedElsewhereId ) != null )
 			params += byId( providedElsewhereId ).checked;
 		
 		params += '&value=';
+
         if ( value != '' )
             params += htmlEncode( value );
 
@@ -246,7 +258,7 @@
            success: function(result){
                 handleResponse (result);
            },
-           error: function(request,status,errorThrown) {
+           error: function(request) {
                 handleHttpError (request);
            }
         });
@@ -273,8 +285,35 @@
  
     function handleHttpError( errorCode )
     {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+        if( getProgramType() == 3 && DAO.dataValues ) {
+            var data = {
+                providedElsewhere: byId( providedElsewhereId ) != null ? byId( providedElsewhereId ).checked : false,
+                value: value != '' ? htmlEncode( value ) : value
+            };
+
+            var dataValueKey = $( '#programStageInstanceId' ).val();
+            var key = dataElementUid;
+
+            DAO.dataValues.fetch( dataValueKey, function ( store, arr ) {
+                if ( arr.length == 0 ) {
+                    var obj = {
+                        key: data
+                    };
+
+                    store.add( dataValueKey, obj );
+                } else {
+                    var obj = arr[0];
+                    obj[key] = data;
+
+                    store.add( dataValueKey, obj );
+                }
+
+                markValue( resultColor );
+            } );
+        } else {
+            markValue( ERROR );
+            window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+        }
     }
  
     function markValue( color )
@@ -513,9 +552,7 @@
                     showCreateNewEvent( programInstanceId, programStageUid );
                 }
 
-                var selectedProgram = jQuery('.stage-object-selected');
-
-                if( selectedProgram.attr('programType')=='2' || json.response == 'programcompleted' ) {
+                if( getProgramType()=='2' || json.response == 'programcompleted' ) {
                     var completedRow = jQuery('#td_' + programInstanceId).html();
                     jQuery('#completedList' ).append('<option value="' +  programInstanceId + '">' + getInnerHTML('infor_' + programInstanceId ) + '</option>');
                 }