← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10535: wip, remove need for psiid in program stage entry form

 

------------------------------------------------------------
revno: 10535
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-04-13 12:50:01 +0700
message:
  wip, remove need for psiid in program stage entry form
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
  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/jsonProgramStageInstance.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/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-04-12 04:20:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-04-13 05:50:01 +0000
@@ -17,18 +17,18 @@
 
 <div id='entryFormContainer'>
 
-<input type='hidden' id='incidentDate' value='$!format.formatDate($programStageInstance.programInstance.dateOfIncident)'>
-<input type='hidden' name='programStageInstanceId' id='programStageInstanceId' value='$!programStageInstance.id'>
-<input type='hidden' name='programInstanceId' id='programInstanceId' value='$!programStageInstance.programInstance.id'>
-<input type='hidden' name='irregular' id='irregular' value='$!programStage.irregular'>
-<input type='hidden' name='displayGenerateEventBox' id='displayGenerateEventBox' value='$!programStage.displayGenerateEventBox'>
-<input type='hidden' name='completed' id='completed' value='$!programStageInstance.completed'>
-<input type='hidden' name='programStageUid' id='programStageUid' value='$!programStage.uid'>
-<input type='hidden' name='programId' id='programId' value='$!program.id'>
-<input type='hidden' name='validCompleteOnly' id='validCompleteOnly' value='$!programStage.validCompleteOnly'>
-<input type='hidden' name='currentUsername' id='currentUsername' value='$!currentUsername'>
-<input type='hidden' name='blockEntryForm' id='blockEntryForm'  value='$!program.blockEntryForm'>
-<input type='hidden' name='remindCompleted' id='remindCompleted'  value='$!program.remindCompleted'>
+<input type='hidden' name='incidentDate' id='incidentDate'>
+<input type='hidden' name='programStageInstanceId' id='programStageInstanceId'>
+<input type='hidden' name='programInstanceId' id='programInstanceId'>
+<input type='hidden' name='irregular' id='irregular'>
+<input type='hidden' name='displayGenerateEventBox' id='displayGenerateEventBox'>
+<input type='hidden' name='completed' id='completed'>
+<input type='hidden' name='programStageUid' id='programStageUid'>
+<input type='hidden' name='programId' id='programId'>
+<input type='hidden' name='validCompleteOnly' id='validCompleteOnly'>
+<input type='hidden' name='currentUsername' id='currentUsername'>
+<input type='hidden' name='blockEntryForm' id='blockEntryForm'>
+<input type='hidden' name='remindCompleted' id='remindCompleted'>
 
 <div id='entryForm' #if($!programStageInstance.executionDate) class='visible' #else class='hidden' #end>					
 	<table style="width:600px;margin-top:-9px" class="listTable">

=== 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-12 04:48:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-13 05:50:01 +0000
@@ -1,5 +1,63 @@
 var DAO = DAO || {};
 
+var DEFAULT_WAIT_CHECK_TIMEOUT = 10;
+
+function initalizeProgramStages() {
+    var programStagesInitialized = false;
+
+    DAO.programStages = new dhis2.storage.Store( {name: 'programStages', adapter: 'dom-ss'}, function(store) {
+        programStagesInitialized = true;
+    });
+
+    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 ) {
+        jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
+            var keys = _.keys( data.metaData.programs );
+            var objs = _.values( data.metaData.programs );
+
+            DAO.programs.addAll( keys, objs, function ( store ) {
+                var deferred = $.Deferred();
+                var promise = deferred.promise();
+
+                _.each( _.values(data.metaData.programs), function(el, idx) {
+                    var psid = el.programStages[0].id;
+
+                    promise = promise.pipe(function () {
+                        return loadProgramStage(psid);
+                    });
+                });
+
+                deferred.resolve();
+
+                selection.setListenerFunction( organisationUnitSelected );
+                programsInitialized = true;
+            } );
+        } ).fail( function () {
+            selection.setListenerFunction( organisationUnitSelected );
+            programsInitialized = true;
+        } );
+    } );
+
+    function waitCheck() {
+        if(!programsInitialized) {
+            setTimeout(waitCheck, DEFAULT_WAIT_CHECK_TIMEOUT);
+        }
+    }
+
+    waitCheck();
+}
+
 $( document ).ready( function () {
     $.ajaxSetup( {
         type: 'POST',
@@ -8,20 +66,8 @@
 
     $( "#orgUnitTree" ).one( "ouwtLoaded", function () {
         // initialize the stores, and then try and add the data
-        DAO.programs = new dhis2.storage.Store( {name: 'programs', adapter: 'dom-ss'}, function ( store ) {
-            jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
-                var keys = _.keys( data.metaData.programs );
-                var objs = _.values( data.metaData.programs );
-
-                DAO.programs.addAll( keys, objs, function ( store ) {
-                    selection.setListenerFunction( organisationUnitSelected );
-                    hideHeaderMessage();
-                } );
-            } ).fail( function () {
-                selection.setListenerFunction( organisationUnitSelected );
-                hideHeaderMessage();
-            } );
-        } );
+        initalizeProgramStages();
+        initializePrograms();
     } );
 
     $( document ).bind( 'dhis2.online', function ( event, loggedIn ) {
@@ -531,7 +577,7 @@
     setInnerHTML( 'dataEntryFormDiv', '' );
     showLoader();
 
-    service.loadDataEntryForm( getFieldValue( 'programStageId' ), programStageInstanceId, getFieldValue( 'orgunitId' ) );
+    service.displayProgramStage( getFieldValue( 'programStageId' ), programStageInstanceId, getFieldValue( 'orgunitId' ) );
 }
 
 function backEventList() {
@@ -642,15 +688,15 @@
 
 // execution date module
 var service = (function () {
-    var executionDateStoreInitialized = false;
-    var dataValueStoreInitialized = false;
+    var anonymousExecutionDatesInitialized = false;
+    var anonymousDataValuesInitialized = false;
 
-    var executionDateStore = new dhis2.storage.Store( {name: 'anonymousExecutionDate' }, function ( store ) {
-        executionDateStoreInitialized = true;
+    var anonymousExecutionDates = new dhis2.storage.Store( {name: 'anonymousExecutionDates', adapter: 'dom' }, function ( store ) {
+        anonymousExecutionDatesInitialized = true;
     } );
 
-    var dataValueStore = new dhis2.storage.Store( {name: 'anonymousDataValue' }, function ( store ) {
-        dataValueStoreInitialized = true;
+    var anonymousDataValues = new dhis2.storage.Store( {name: 'anonymousDataValues', adapter: 'dom' }, function ( store ) {
+        anonymousDataValuesInitialized = true;
     } );
 
     return {
@@ -675,7 +721,7 @@
                 }
             } ).fail( function () {
                 function waitForExecutionDateStore() {
-                    if(!executionDateStoreInitialized) {
+                    if(!anonymousExecutionDatesInitialized) {
                         setTimeout(waitForExecutionDateStore, 50);
                     }
                 }
@@ -685,35 +731,33 @@
                 var data = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId);
 
                 if(programStageInstanceId == 0) {
-                    executionDateStore.keys(function(store, keys) {
+                    anonymousExecutionDates.keys(function(store, keys) {
                         var i = 100;
 
                         for(; i<10000; i++) {
                             if( keys.indexOf(i) == -1 ) break;
                         }
 
-                        console.log("i: ", i);
+                        programStageInstanceId = "local"+i;
 
-                        setFieldValue( 'programStageInstanceId', "local"+i );
+                        setFieldValue( 'programStageInstanceId', programStageInstanceId );
                         jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
                         showUpdateEvent( programStageInstanceId );
-                        console.log("programStageInstanceId: ", getFieldValue('programStageInstanceId'));
                     });
                 } else {
                     // if we have a programStageInstanceId, just reuse that one
                     setFieldValue( 'programStageInstanceId', programStageInstanceId );
                     jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
                     showUpdateEvent( programStageInstanceId );
-                    console.log("programStageInstanceId: ", getFieldValue('programStageInstanceId'));
                 }
             } );
         },
 
-        loadDataEntryForm: function( programStageId, programStageInstanceId, organisationUnitId ) {
-            loadFormAjax( programStageId, programStageInstanceId, organisationUnitId ).done(function ( data ) {
+        displayProgramStage: function( programStageId, programStageInstanceId, organisationUnitId ) {
+            loadProgramStage( programStageId, programStageInstanceId, organisationUnitId, function ( data ) {
                 $( '#dataEntryFormDiv' ).html( data );
                 updateDataForm();
-            } ).fail( function () {
+            },function () {
                 $( '#dataEntryFormDiv' ).html( "<div class='message message-info'>Unable to load form.</div>" );
                 hideById( 'loaderDiv' );
             } );
@@ -762,7 +806,37 @@
     }
 }
 
-function loadFormAjax( programStageId, programStageInstanceId, organisationUnitId ) {
+function loadProgramStage( programStageId, programStageInstanceId, organisationUnitId, success, fail ) {
+    /*
+    DAO.programStages.fetch(programStageId, function(store, arr) {
+        if ( arr.length > 0 ) {
+            if(success) success(arr[0]);
+        } else {
+            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();
+            });
+        }
+    });
+    */
+
     var data = {};
 
     if(programStageId)
@@ -774,9 +848,14 @@
     if(organisationUnitId)
         data.organisationUnitId = organisationUnitId;
 
-    return $.ajax( {
+    $.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-10 04:22:14 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-04-13 05:50:01 +0000
@@ -625,39 +625,68 @@
     }
 };
 
+function loadProgramStageInstance(programStageInstanceId) {
+    return $.ajax({
+        url: 'getProgramStageInstance.action',
+        data: {
+            'programStageInstanceId': programStageInstanceId
+        },
+        type: 'GET',
+        dataType: 'json'
+    } ).done(function(data) {
+        $( "#entryFormContainer input[id='incidentDate']" ).val( data.programInstance.dateOfIncident );
+        $( "#entryFormContainer input[id='programStageInstanceId']" ).val( data.id );
+        $( "#entryFormContainer input[id='programInstanceId']" ).val( data.programInstance.id );
+        $( "#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='programStageUid']" ).val( data.programStage.uid  );
+        $( "#entryFormContainer input[id='programId']" ).val( data.program.id );
+        $( "#entryFormContainer input[id='validCompleteOnly']" ).val( data.programStage.validCompleteOnly );
+        $( "#entryFormContainer input[id='currentUsername']" ).val( data.currentUsername );
+        $( "#entryFormContainer input[id='blockEntryForm']" ).val( data.program.blockEntryForm );
+        $( "#entryFormContainer input[id='remindCompleted']" ).val( data.program.remindCompleted );
+    });
+}
+
 function entryFormContainerOnReady()
 {
 	var currentFocus = undefined;
-
-    if( jQuery("#entryFormContainer") ) {
-		
-        if( jQuery("#executionDate").val() != '' )
-        {
-            toggleContentForReportDate(true);
+    var programStageInstanceId = getFieldValue( 'programStageInstanceId' );
+
+    loadProgramStageInstance(programStageInstanceId ).done(function() {
+        if( jQuery("#entryFormContainer") ) {
+
+            if( jQuery("#executionDate").val() != '' )
+            {
+                toggleContentForReportDate(true);
+            }
+
+            jQuery("input[name='entryfield'],select[name='entryselect']").each(function(){
+                jQuery(this).focus(function(){
+                    currentFocus = this;
+                });
+
+                jQuery(this).addClass("inputText");
+            });
+
+            TOGGLE.init();
+
+    		jQuery("#entryForm :input").each(function()
+    		{
+    			if( jQuery(this).attr( 'options' )!= null && jQuery(this).attr( 'options' )== 'true' )
+    			{
+    				autocompletedField(jQuery(this).attr('id'));
+    			}
+    			else if( jQuery(this).attr( 'username' )!= null && jQuery(this).attr( 'username' )== 'true' )
+    			{
+    				autocompletedUsernameField(jQuery(this).attr('id'));
+    			}
+    		});
         }
-		
-        jQuery("input[name='entryfield'],select[name='entryselect']").each(function(){
-            jQuery(this).focus(function(){
-                currentFocus = this;
-            });
-            
-            jQuery(this).addClass("inputText");
-        });
-		
-        TOGGLE.init();
-				
-		jQuery("#entryForm :input").each(function()
-		{ 
-			if( jQuery(this).attr( 'options' )!= null && jQuery(this).attr( 'options' )== 'true' )
-			{
-				autocompletedField(jQuery(this).attr('id'));
-			}
-			else if( jQuery(this).attr( 'username' )!= null && jQuery(this).attr( 'username' )== 'true' )
-			{
-				autocompletedUsernameField(jQuery(this).attr('id'));
-			}
-		});
-    }
+    } ).fail(function() {
+        console.log("failed, do something smart")
+    });
 }
 
 //------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstance.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstance.vm	2013-04-13 05:13:24 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramStageInstance.vm	2013-04-13 05:50:01 +0000
@@ -1,5 +1,5 @@
 {
-    "currentUser": "$currentUsername",
+    "currentUsername": "$currentUsername",
     "id": "$!programStageInstance.id",
     "dueDate": "$format.formatDate( $!programStageInstance.dueDate )",
     "executionDate": "$format.formatDate( $!programStageInstance.executionDate )",