← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10513: wip, offline support for anonymous reporting

 

------------------------------------------------------------
revno: 10513
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-04-10 16:52:31 +0700
message:
  wip, offline support for anonymous reporting
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.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-10 04:58:16 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-10 09:52:31 +0000
@@ -650,15 +650,26 @@
 
 // execution date module
 var service = (function () {
+    var executionDateStore = new dhis2.storage.Store( {name: 'anonymousExecutionDate' }, function ( store ) {
+    } );
+
+    var dataValueStore = new dhis2.storage.Store( {name: 'anonymousDataValue' }, function ( store ) {
+    } );
+
+
     return {
         saveExecutionDate: function( programId, programStageInstanceId, executionDate, organisationUnitId ) {
-            jQuery.postJSON( "saveExecutionDate.action", {
-                programId: programId,
-                programStageInstanceId: programStageInstanceId,
-                executionDate: executionDate,
-                organisationUnitId: organisationUnitId
-            },
-            function ( json ) {
+            $.ajax( {
+                url: 'saveExecutionDate.action',
+                data: {
+                    programId: programId,
+                    programStageInstanceId: programStageInstanceId,
+                    executionDate: executionDate,
+                    organisationUnitId: organisationUnitId
+                },
+                type: 'POST',
+                dataType: 'json'
+            } ).done(function ( json ) {
                 if ( json.response == 'success' ) {
                     jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
                     setFieldValue( 'programStageInstanceId', json.message );
@@ -670,45 +681,57 @@
                     jQuery( "#executionDate" ).css( 'background-color', ERROR_COLOR );
                     showWarningMessage( json.message );
                 }
+            } ).fail( function () {
+                console.log("should save execution date locally.")
             } );
         },
 
         loadDataEntryForm: function( programStageInstanceId, organisationUnitId ) {
-            $( '#dataEntryFormDiv' ).load( "dataentryform.action", {
-                programStageInstanceId: programStageInstanceId,
-                organisationUnitId: organisationUnitId
-            }, function () {
-                jQuery( '#inputCriteriaDiv' ).remove();
-                showById( 'programName' );
-                showById( 'actionDiv' );
-                var programName = jQuery( '#programId option:selected' ).text();
-                var programStageId = jQuery( '#programId option:selected' ).attr( 'psid' );
-                jQuery( '.stage-object-selected' ).attr( 'psid', programStageId );
-                setInnerHTML( 'programName', programName );
-                jQuery('#executionDate').css('width',430);
-                jQuery('#executionDate').css('margin-right',30);
-
-                if ( getFieldValue( 'completed' ) == 'true' ) {
-                    disable( "completeBtn" );
-                    enable( "uncompleteBtn" );
-                }
-                else {
-                    enable( "completeBtn" );
-                    disable( "uncompleteBtn" );
-                }
-                hideById( 'loaderDiv' );
-                showById( 'dataEntryInfor' );
-                showById( 'entryFormContainer' );
-
-                jQuery( "#entryForm :input" ).each( function () {
-                    if ( ( jQuery( this ).attr( 'options' ) != null && jQuery( this ).attr( 'options' ) == 'true' )
-                        || ( jQuery( this ).attr( 'username' ) != null && jQuery( this ).attr( 'username' ) == 'true' ) ) {
-                        var input = jQuery( this );
-                        input.parent().width( input.width() + 200 );
-                    }
-                } );
-            } );
-
+            $.ajax( {
+                url: 'dataentryform.action',
+                data: {
+                    programStageInstanceId: programStageInstanceId,
+                    organisationUnitId: organisationUnitId
+                },
+                dataType: 'html'
+            } ).done(function(data) {
+                $( '#dataEntryFormDiv' ).html( data );
+                updateDataForm();
+            } ).fail(function() {
+                $( '#dataEntryFormDiv' ).html( "not available offline." );
+            });
         }
     }
 })();
+
+function updateDataForm() {
+    jQuery( '#inputCriteriaDiv' ).remove();
+    showById( 'programName' );
+    showById( 'actionDiv' );
+    var programName = jQuery( '#programId option:selected' ).text();
+    var programStageId = jQuery( '#programId option:selected' ).attr( 'psid' );
+    jQuery( '.stage-object-selected' ).attr( 'psid', programStageId );
+    setInnerHTML( 'programName', programName );
+    jQuery('#executionDate').css('width',430);
+    jQuery('#executionDate').css('margin-right',30);
+
+    if ( getFieldValue( 'completed' ) == 'true' ) {
+        disable( "completeBtn" );
+        enable( "uncompleteBtn" );
+    }
+    else {
+        enable( "completeBtn" );
+        disable( "uncompleteBtn" );
+    }
+    hideById( 'loaderDiv' );
+    showById( 'dataEntryInfor' );
+    showById( 'entryFormContainer' );
+
+    jQuery( "#entryForm :input" ).each( function () {
+        if ( ( jQuery( this ).attr( 'options' ) != null && jQuery( this ).attr( 'options' ) == 'true' )
+            || ( jQuery( this ).attr( 'username' ) != null && jQuery( this ).attr( 'username' ) == 'true' ) ) {
+            var input = jQuery( this );
+            input.parent().width( input.width() + 200 );
+        }
+    } );
+}