← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4421: Made process of getting data element name/type more robust

 

------------------------------------------------------------
revno: 4421
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-08-23 19:19:45 +0200
message:
  Made process of getting data element name/type more robust
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  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/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-08-20 10:17:48 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-08-23 17:19:45 +0000
@@ -94,10 +94,10 @@
  */
 function saveVal( dataElementId, optionComboId )
 {
-    var dataElementName = dataElements[dataElementId].name;
+    var dataElementName = getDataElementName( dataElementId );
     var fieldId = '#' + dataElementId + '-' + optionComboId + '-val';
     var value = $( fieldId ).val();
-    var type = dataElements[dataElementId].type;
+    var type = getDataElementType( dataElementId );
 
     $( fieldId ).css( 'background-color', COLOR_YELLOW );
 

=== 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	2011-08-23 13:51:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-23 17:19:45 +0000
@@ -48,6 +48,9 @@
 var COLOR_WHITE = '#ffffff';
 var COLOR_GREY = '#cccccc';
 
+var DEFAULT_TYPE = 'int';
+var DEFAULT_NAME = '[unknown]';
+
 /**
  * Page init. The order of events is:
  * 
@@ -266,7 +269,7 @@
         var id = $( this ).attr( 'id' );
         var dataElementId = id.split( '-' )[0];
         var optionComboId = id.split( '-' )[1];
-        var type = dataElements[dataElementId].type;
+        var type = getDataElementType( dataElementId );
 
         $( this ).unbind( 'focus' );
         $( this ).unbind( 'blur' );
@@ -362,7 +365,29 @@
     }
 }
 
-// -----------------------------------------------------------------------------
+function getDataElementType( dataElementId )
+{
+	if ( dataElements[dataElementId] != null )
+	{
+		return dataElements[dataElementId].type
+	}
+	
+	console.log( 'Data element not present in data set, falling back to default type: ' + dataElementId );	
+	return DEFAULT_TYPE;
+}
+
+function getDataElementName( dataElementId )
+{
+	if ( dataElements[dataElementId] != null )
+	{
+		return dataElements[dataElementId].name;
+	}
+	
+	console.log( 'Data element present in data set, falling back to default name: ' + dataElementId );
+	return DEFAULT_NAME;	
+}
+
+// ----------------------------------------------------------------------------
 // OrganisationUnit Selection
 // -----------------------------------------------------------------------------
 
@@ -677,7 +702,7 @@
     var dataElementId = id.split( '-' )[0];
     var optionComboId = id.split( '-' )[1];
 
-    var dataElementName = dataElements[dataElementId].name;
+    var dataElementName = getDataElementName( dataElementId );
     var optionComboName = $( '#' + optionComboId + '-optioncombo' ).text();
 
     $( '#currentDataElement' ).html( dataElementName + ' ' + optionComboName );
@@ -893,7 +918,7 @@
 {
     var periodId = $( '#selectedPeriodId' ).val();
 
-    var dataElementName = dataElements[dataElementId].name;
+    var dataElementName = getDataElementName( dataElementId );
     var optionComboName = $( '#' + optionComboId + '-optioncombo' ).html();
     var operandName = dataElementName + ' ' + optionComboName;