← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13405: Data entry, stronger validation before form loading

 

------------------------------------------------------------
revno: 13405
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-23 16:39:16 +0100
message:
  Data entry, stronger validation before form loading
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.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-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-12-23 14:04:33 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-12-23 15:39:16 +0000
@@ -55,9 +55,6 @@
 // Array with category objects, null if default category combo / no categories
 dhis2.de.currentCategories = null;
 
-// Currently selected iso period
-dhis2.de.currentPeriodId = null;
-
 // Current offset, next or previous corresponding to increasing or decreasing value
 dhis2.de.currentPeriodOffset = 0;
 
@@ -834,16 +831,16 @@
     }
 
     if ( !dhis2.de.multiOrganisationUnit && dataSetValid && dataSetId != null ) {
-        $( '#selectedDataSetId' ).val( dataSetId );
+        $( '#selectedDataSetId' ).val( dataSetId ); // Restore selected data set
 
-        if ( periodId && periodId != -1 && dhis2.de.dataEntryFormIsLoaded ) {
+        if ( dhis2.de.inputSelected() && dhis2.de.dataEntryFormIsLoaded ) {
             resetSectionFilters();
             showLoader();
             loadDataValues();
         }
     } 
     else if ( dhis2.de.multiOrganisationUnit && multiDataSetValid && dataSetId != null ) {
-        $( '#selectedDataSetId' ).val( dataSetId );
+        $( '#selectedDataSetId' ).val( dataSetId ); // Restore selected data set
         dataSetSelected();
     }
     else {
@@ -927,8 +924,15 @@
     $( '#prevButton' ).removeAttr( 'disabled' );
     $( '#nextButton' ).removeAttr( 'disabled' );
 
+    var x = dhis2.de.currentDataSetId;
+    
     var dataSetId = $( '#selectedDataSetId' ).val();
     var periodId = $( '#selectedPeriodId' ).val();
+
+    var previousDataSetValid = ( dhis2.de.currentDataSetId && dhis2.de.currentDataSetId != -1 );    
+    var previousPeriodType = previousDataSetValid ? dhis2.de.dataSets[dhis2.de.currentDataSetId].periodType : null;
+
+    dhis2.de.currentDataSetId = dataSetId;
     
     if ( dataSetId && dataSetId != -1 )
     {
@@ -966,15 +970,10 @@
             addOptionById( 'selectedPeriodId', item.iso, item.name );
         } );
 
-        var previousPeriodType = dhis2.de.currentDataSetId ? dhis2.de.dataSets[dhis2.de.currentDataSetId].periodType : null;
-
-        dhis2.de.currentDataSetId = dataSetId;
-        
-        if ( periodId && periodId != -1 && previousPeriodType && previousPeriodType == periodType )
+        if ( dhis2.de.inputSelected() && previousPeriodType && previousPeriodType == periodType )
         {
-            showLoader();
+            showLoader();            
             $( '#selectedPeriodId' ).val( periodId );
-
             loadForm();
         }
         else
@@ -1000,11 +999,9 @@
     $( '#currentPeriod' ).html( periodName );
 
     var periodId = $( '#selectedPeriodId' ).val();
-
-    if ( periodId && periodId != -1 )
-    {
-    	dhis2.de.currentPeriodId = periodId;
-    	
+	
+    if ( dhis2.de.inputSelected() )
+    {    	
         showLoader();
 
         if ( dhis2.de.dataEntryFormIsLoaded )
@@ -1213,11 +1210,14 @@
  */
 dhis2.de.inputSelected = function()
 {
+    var dataSetId = $( '#selectedDataSetId' ).val();
+    var periodId = $( '#selectedPeriodId' ).val();
+
 	if (
 	    dhis2.de.currentOrganisationUnitId &&
-	    dhis2.de.currentDataSetId &&
-	    dhis2.de.currentPeriodId &&
-	    dhis2.de.categoriesSelected ) {
+	    dataSetId && dataSetId != -1 &&
+	    periodId && periodId != -1 &&
+	    dhis2.de.categoriesSelected() ) {
 		return true;
 	}