← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10544: wip, offline anonymous. Load forms from local db. Hide/show search when offline/online. Add store...

 

------------------------------------------------------------
revno: 10544
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-15 11:08:05 +0700
message:
  wip, offline anonymous. Load forms from local db. Hide/show search when offline/online. Add stored for saving offline data (data values, execution dates, not in used yet).
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java
  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
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2013-03-26 15:19:15 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java	2013-04-15 04:08:05 +0000
@@ -62,7 +62,6 @@
 
 /**
  * @author Chau Thu Tran
- * 
  * @version $GenerateTabularReportAction.java Feb 29, 2012 10:15:05 AM$
  */
 public class GenerateTabularReportAction
@@ -307,6 +306,11 @@
     public String execute()
         throws Exception
     {
+        if ( programStageId == null )
+        {
+            return INPUT;
+        }
+
         // ---------------------------------------------------------------------
         // Get user orgunits
         // ---------------------------------------------------------------------

=== 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-13 07:47:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-15 04:08:05 +0000
@@ -1,27 +1,18 @@
 var DAO = DAO || {};
 
-var DEFAULT_WAIT_CHECK_TIMEOUT = 10;
+var PROGRAMS_STORE = 'anonymous_programs';
+var PROGRAM_STAGES_STORE = 'anonymous_programStages';
+var EXECUTION_DATES_STORE = 'anonymous_executionDates';
+var DATA_VALUES_STORE = 'anonymous_dataValues';
 
 function initalizeProgramStages() {
-    var programStagesInitialized = false;
-
-    DAO.programStages = new dhis2.storage.Store( {name: 'programStages', adapter: 'dom-ss'}, function(store) {
-        programStagesInitialized = true;
+    DAO.programStages = new dhis2.storage.Store( {name: PROGRAM_STAGES_STORE, adapter: 'dom-ss'}, function(store) {
+        $( document ).trigger('dhis2.anonymous.programStagesInitialized');
     });
-
-    function waitCheck() {
-        if(!programStagesInitialized) {
-            setTimeout(waitCheck, DEFAULT_WAIT_CHECK_TIMEOUT);
-        }
-    }
-
-    waitCheck();
 }
 
 function initializePrograms() {
-    var programsInitialized = false;
-
-    DAO.programs = new dhis2.storage.Store( {name: 'programs', adapter: 'dom-ss'}, function ( store ) {
+    DAO.programs = new dhis2.storage.Store( {name: PROGRAMS_STORE, adapter: 'dom-ss'}, function ( store ) {
         jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
             var keys = _.keys( data.metaData.programs );
             var objs = _.values( data.metaData.programs );
@@ -41,21 +32,25 @@
                 deferred.resolve();
 
                 selection.setListenerFunction( organisationUnitSelected );
-                programsInitialized = true;
+                $( document ).trigger('dhis2.anonymous.programsInitialized');
             } );
         } ).fail( function () {
             selection.setListenerFunction( organisationUnitSelected );
-            programsInitialized = true;
+            $( document ).trigger('dhis2.anonymous.programsInitialized');
         } );
     } );
-
-    function waitCheck() {
-        if(!programsInitialized) {
-            setTimeout(waitCheck, DEFAULT_WAIT_CHECK_TIMEOUT);
-        }
-    }
-
-    waitCheck();
+}
+
+function initializeExecutionDates() {
+    DAO.executionDates = new dhis2.storage.Store( {name: EXECUTION_DATES_STORE, adapter: 'dom'}, function(store) {
+        $( document ).trigger('dhis2.anonymous.executionDatesInitialized');
+    });
+}
+
+function initializeDataValues() {
+    DAO.dataValues = new dhis2.storage.Store( {name: DATA_VALUES_STORE, adapter: 'dom'}, function(store) {
+        $( document ).trigger('dhis2.anonymous.dataValueInitialized');
+    });
 }
 
 $( document ).ready( function () {
@@ -66,13 +61,25 @@
 
     $( "#orgUnitTree" ).one( "ouwtLoaded", function () {
         // initialize the stores, and then try and add the data
+        $( document ).one('dhis2.anonymous.programStagesInitialized', initializePrograms);
+        $( document ).one('dhis2.anonymous.programsInitialized', initializeExecutionDates);
+        $( document ).one('dhis2.anonymous.executionDatesInitialized', initializeDataValues);
+
         initalizeProgramStages();
-        initializePrograms();
     } );
 
     $( document ).bind( 'dhis2.online', function ( event, loggedIn ) {
         if ( loggedIn ) {
             setHeaderDelayMessage( i18n_online_notification );
+            enableFiltering();
+
+            var search = getFieldValue( 'programStageId' ) != undefined && getFieldValue( 'programStageId' ).length != 0;
+
+            if ( search ) {
+                searchEvents( eval( getFieldValue( 'listAll' ) ) );
+            }
+
+            $('#commentInput').removeAttr('disabled');
         }
         else {
             var form = [
@@ -88,18 +95,36 @@
             setHeaderMessage( form );
             ajax_login();
         }
-
-        $('#commentInput').removeAttr('disabled');
     } );
 
     $( document ).bind( 'dhis2.offline', function () {
         setHeaderMessage( i18n_offline_notification );
         $('#commentInput').attr('disabled', true);
+        disableFiltering();
     } );
 
     dhis2.availability.startAvailabilityCheck();
 } );
 
+function disableFiltering() {
+    $('#listDiv').hide();
+    $('#filterBtn').attr('disabled', true);
+    $('#listBtn').attr('disabled', true);
+    $('#incompleted').attr('disabled', true);
+    $('#removeBtn').attr('disabled', true);
+}
+
+function enableFiltering() {
+    var filtering = getFieldValue( 'programStageId' ) != undefined && getFieldValue( 'programStageId' ).length != 0;
+
+    if ( filtering ) {
+        $( '#filterBtn' ).removeAttr( 'disabled' );
+        $( '#listBtn' ).removeAttr( 'disabled' );
+        $( '#incompleted' ).removeAttr( 'disabled' );
+        $( '#removeBtn' ).removeAttr( 'disabled' );
+    }
+}
+
 function ajax_login()
 {
     $( '#login_button' ).bind( 'click', function()
@@ -691,17 +716,6 @@
 
 // execution date module
 var service = (function () {
-    var anonymousExecutionDatesInitialized = false;
-    var anonymousDataValuesInitialized = false;
-
-    var anonymousExecutionDates = new dhis2.storage.Store( {name: 'anonymousExecutionDates', adapter: 'dom' }, function ( store ) {
-        anonymousExecutionDatesInitialized = true;
-    } );
-
-    var anonymousDataValues = new dhis2.storage.Store( {name: 'anonymousDataValues', adapter: 'dom' }, function ( store ) {
-        anonymousDataValuesInitialized = true;
-    } );
-
     return {
         saveExecutionDate: function( programId, programStageInstanceId, executionDate, organisationUnitId ) {
             $.ajax( {
@@ -723,18 +737,10 @@
                     showWarningMessage( json.message );
                 }
             } ).fail( function () {
-                function waitForExecutionDateStore() {
-                    if(!anonymousExecutionDatesInitialized) {
-                        setTimeout(waitForExecutionDateStore, 50);
-                    }
-                }
-
-                waitForExecutionDateStore();
-
                 var data = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId);
 
                 if(programStageInstanceId == 0) {
-                    anonymousExecutionDates.keys(function(store, keys) {
+                    /*anonymousExecutionDates.keys(function(store, keys) {
                         var i = 100;
 
                         for(; i<10000; i++) {
@@ -747,6 +753,7 @@
                         jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
                         showUpdateEvent( programStageInstanceId );
                     });
+                    */
                 } else {
                     // if we have a programStageInstanceId, just reuse that one
                     setFieldValue( 'programStageInstanceId', programStageInstanceId );
@@ -802,16 +809,24 @@
 }
 
 function createExecutionDate( programId, programStageInstanceId, executionDate, organisationUnitId ) {
-    return {
-        programId: programId,
-        programStageInstanceId: programStageInstanceId,
-        executionDate: executionDate,
-        organisationUnitId: organisationUnitId
-    }
+    var data = {};
+
+    if(programId)
+        data.programId = programId;
+
+    if(programStageInstanceId)
+        data.programStageInstanceId = programStageInstanceId;
+
+    if(executionDate)
+        data.executionDate = executionDate;
+
+    if(organisationUnitId)
+        data.organisationUnitId = organisationUnitId;
+
+    return data;
 }
 
 function loadProgramStage( programStageId, programStageInstanceId, organisationUnitId, success, fail ) {
-    /*
     DAO.programStages.fetch(programStageId, function(store, arr) {
         if ( arr.length > 0 ) {
             if(success) success(arr[0]);
@@ -839,27 +854,4 @@
             });
         }
     });
-    */
-
-    var data = {};
-
-    if(programStageId)
-        data.programStageId = programStageId;
-
-    if(programStageInstanceId)
-        data.programStageInstanceId = programStageInstanceId;
-
-    if(organisationUnitId)
-        data.organisationUnitId = organisationUnitId;
-
-    $.ajax( {
-        url: 'dataentryform.action',
-        data: data,
-        dataType: 'html'
-    } ).done(function(data) {
-        DAO.programStages.add(programStageId, data);
-        if(success) success(data);
-    } ).fail(function() {
-        if(fail) fail();
-    });
 }

=== 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-13 08:00:15 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-04-15 04:08:05 +0000
@@ -634,38 +634,48 @@
         type: 'GET',
         dataType: 'json'
     } ).done(function(data) {
-        $( "#programStageInstanceId" ).val( data.id );
-        $( "#entryFormContainer input[id='programStageInstanceId']" ).val( data.id );
-        $( "#entryFormContainer input[id='incidentDate']" ).val( data.programInstance.dateOfIncident );
-        $( "#entryFormContainer input[id='programInstanceId']" ).val( data.programInstance.id );
+        $( "#entryFormContainer input[id='programId']" ).val( data.program.id );
+        $( "#entryFormContainer input[id='blockEntryForm']" ).val( data.program.blockEntryForm );
+        $( "#entryFormContainer input[id='remindCompleted']" ).val( data.program.remindCompleted );
+
         $( "#entryFormContainer input[id='irregular']" ).val( data.programStage.irregular );
         $( "#entryFormContainer input[id='displayGenerateEventBox']" ).val( data.programStage.displayGenerateEventBox );
-        $( "#entryFormContainer input[id='completed']" ).val( data.completed );
         $( "#entryFormContainer input[id='programStageId']" ).val( data.programStage.id  );
         $( "#entryFormContainer input[id='programStageUid']" ).val( data.programStage.uid  );
-        $( "#entryFormContainer input[id='programId']" ).val( data.program.id );
         $( "#entryFormContainer input[id='validCompleteOnly']" ).val( data.programStage.validCompleteOnly );
+
+        $( "#programStageInstanceId" ).val( data.id );
+        $( "#entryFormContainer input[id='programStageInstanceId']" ).val( data.id );
+        $( "#entryFormContainer input[id='completed']" ).val( data.completed );
         $( "#entryFormContainer input[id='currentUsername']" ).val( data.currentUsername );
-        $( "#entryFormContainer input[id='blockEntryForm']" ).val( data.program.blockEntryForm );
-        $( "#entryFormContainer input[id='remindCompleted']" ).val( data.program.remindCompleted );
-
         $( "#entryFormContainer input[id='dueDate']" ).val( data.dueDate );
         $( "#entryFormContainer input[id='executionDate']" ).val( data.executionDate );
 
+        $( "#entryFormContainer input[id='incidentDate']" ).val( data.programInstance.dateOfIncident );
+        $( "#entryFormContainer input[id='programInstanceId']" ).val( data.programInstance.id );
+
         if ( data.program.type != '1' ) {
             hideById( 'newEncounterBtn' );
         }
 
+        if ( data.program.type == '1' && data.programInstance.status == '1' ) {
+            jQuery("[id=entryFormContainer] :input").prop('disabled', true);
+            jQuery("[id=entryFormContainer] :input").datepicker("destroy");
+            jQuery("[id=executionDate]").prop('disabled', true);
+            jQuery("[id=executionDate]").datepicker("destroy");
+        }
+
+        if ( data.programStage.captureCoordinates ) {
+            $( '#longitude' ).val( data.longitude );
+            $( '#latitude' ).val( data.latitude );
+        }
+
         if(data.executionDate) {
+            $( '#executionDate' ).val(data.executionDate);
             $( '#entryForm' ).removeClass( 'hidden' ).addClass( 'visible' );
             $( '#inputCriteriaDiv' ).removeClass( 'hidden' );
         }
 
-        if ( data.programStage.captureCoordinates ) {
-            $( '#longitude' ).val( data.longitude );
-            $( '#latitude' ).val( data.latitude );
-        }
-
         if(data.comments.length > 0) {
             $.each(data.comments, function(idx, item) {
                 var comment = [
@@ -679,15 +689,8 @@
                 $( '#commentTB' ).append( comment )
             });
         }
-
-        if ( data.program.type == '1' && data.programInstance.status == '1' ) {
-            jQuery("[id=entryFormContainer] :input").prop('disabled', true);
-            jQuery("[id=entryFormContainer] :input").datepicker("destroy");
-            jQuery("[id=executionDate]").prop('disabled', true);
-            jQuery("[id=executionDate]").datepicker("destroy");
-        }
     } ).fail(function() {
-        $('#commentInput').attr('disabled', true)
+        $('#commentInput').attr('disabled', true);
     });
 }
 
@@ -696,7 +699,7 @@
 	var currentFocus = undefined;
     var programStageInstanceId = getFieldValue( 'programStageInstanceId' );
 
-    loadProgramStageInstance(programStageInstanceId ).done(function() {
+    loadProgramStageInstance( programStageInstanceId ).done(function() {
         if( jQuery("#entryFormContainer") ) {
 
             if( jQuery("#executionDate").val() != '' )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm	2013-04-04 07:57:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm	2013-04-15 04:08:05 +0000
@@ -3,15 +3,27 @@
 #set( $psize = $programs.size() )
 #foreach( $program in $programs )
 "${program.id}":{
-"name":"$encoder.jsonEncode( ${program.displayName} )",
-"description":"$encoder.jsonEncode( ${program.description} )",
-"enrollmentDescription":"$encoder.jsonEncode( ${program.dateOfEnrollmentDescription} )",
-"incidentDescription":"$encoder.jsonEncode( ${program.dateOfIncidentDescription} )",
-"programStages":[#set( $pssize = $program.programStages.size() )
-#foreach( $ps in $program.programStages )
-{ "id": "${ps.id}", "name": "$encoder.jsonEncode( ${ps.displayName} )", "reportDateDescription": "$encoder.jsonEncode( ${ps.reportDateDescription} )" }#if( $velocityCount < $pssize ),#end
-#end],
-"programAssociations": $programAssociations.get(${program.id})
+    "name":"$encoder.jsonEncode( ${program.displayName} )",
+    "description":"$encoder.jsonEncode( ${program.description} )",
+    "enrollmentDescription":"$encoder.jsonEncode( ${program.dateOfEnrollmentDescription} )",
+    "incidentDescription":"$encoder.jsonEncode( ${program.dateOfIncidentDescription} )",
+    "type": "$!program.type",
+    "blockEntryForm": $!program.blockEntryForm,
+    "remindCompleted": $!program.remindCompleted,
+    "programStages":[#set( $pssize = $program.programStages.size() )
+    #foreach( $ps in $program.programStages )
+    {
+        "id": "${ps.id}",
+        "uid": "$encoder.jsonEncode( $!ps.uid )",
+        "name": "$encoder.jsonEncode( ${ps.displayName} )",
+        "reportDateDescription": "$encoder.jsonEncode( ${ps.reportDateDescription} )",
+        "irregular": $!ps.irregular,
+        "displayGenerateEventBox": $!ps.displayGenerateEventBox,
+        "validCompleteOnly": $!ps.validCompleteOnly,
+        "captureCoordinates": $!ps.captureCoordinates
+    }#if( $velocityCount < $pssize ),#end
+    #end],
+    "programAssociations": $programAssociations.get(${program.id})
 }#if( $velocityCount < $psize ),#end
 #end }
 }}