← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13383: Data entry, impl save and get values with attributes

 

------------------------------------------------------------
revno: 13383
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-12-22 11:06:39 +0100
message:
  Data entry, impl save and get values with attributes
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
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.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-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	2013-12-22 09:34:24 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2013-12-22 10:06:39 +0000
@@ -201,8 +201,7 @@
     
     var color = warning ? COLOR_ORANGE : COLOR_GREEN;
     
-    var valueSaver = new ValueSaver( dataElementId, optionComboId, 
-    	getCurrentOrganisationUnit(), periodId, value, fieldId, color );
+    var valueSaver = new ValueSaver( dataElementId,	periodId, optionComboId, value, fieldId, color );
     valueSaver.save();
 
     updateIndicators(); // Update indicators for custom form
@@ -224,8 +223,7 @@
 
     var periodId = $( '#selectedPeriodId' ).val();
 
-    var valueSaver = new ValueSaver( dataElementId, optionComboId, 
-    	getCurrentOrganisationUnit(), periodId, value, fieldId, COLOR_GREEN );
+    var valueSaver = new ValueSaver( dataElementId, periodId, optionComboId, value, fieldId, COLOR_GREEN );
     valueSaver.save();
 }
 
@@ -241,8 +239,7 @@
 
     var periodId = $( '#selectedPeriodId' ).val();
 
-    var valueSaver = new ValueSaver( dataElementId, optionComboId,
-        getCurrentOrganisationUnit(), periodId, value, fieldId, COLOR_GREEN );
+    var valueSaver = new ValueSaver( dataElementId, periodId, optionComboId, value, fieldId, COLOR_GREEN );
     valueSaver.save();
 }
 
@@ -271,8 +268,18 @@
 // Saver objects
 // -----------------------------------------------------------------------------
 
-function ValueSaver( de, co, ou, pe, value, fieldId, resultColor )
+/**
+ * @param de data element identifier.
+ * @param pe iso period.
+ * @param co category option combo.
+ * @param value value.
+ * @param fieldId identifier of data input field.
+ * @param resultColor the color code to set on input field for success.
+ */
+function ValueSaver( de, pe, co, value, fieldId, resultColor )
 {
+	var ou = getCurrentOrganisationUnit();
+	
     var dataValue = {
         'de' : de,
         'co' : co,
@@ -281,6 +288,15 @@
         'value' : value
     };
 
+    var cc = dhis2.de.getCurrentCategoryCombo();
+    var cp = dhis2.de.getCurrentCategoryOptionsQueryValue();
+    
+    if ( cc && cp )
+    {
+    	dataValue.cc = cc;
+    	dataValue.cp = cp;
+    }
+    
     this.save = function()
     {
     	dhis2.de.storageManager.saveDataValue( dataValue );

=== 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-22 09:15:53 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-12-22 10:06:39 +0000
@@ -1121,9 +1121,9 @@
 };
 
 /**
-* Returns the identifier of the current attribute category combo. Based on the
-* dhis2.de.currentDataSetId global variable. Returns null if there is no 
-* current data set or if current data set has the default category combo.
+* Returns attribute category combo identifier. Based on the dhis2.de.currentDataSetId 
+* global variable. Returns null if there is no current data set or if current 
+* data set has the default category combo.
 */
 dhis2.de.getCurrentCategoryCombo = function()
 {
@@ -1133,13 +1133,13 @@
 		return null;
 	}
 	
-	return dataSet.categoryCombo.id;
+	return dataSet.categoryCombo;
 };
 
 /**
-* Returns an array of the currently selected attribute category options. Based
-* on the dhis2.de.currentCategories global variable. Returns null if there are
-* no current categories.
+* Returns an array of the currently selected attribute category option identifiers. 
+* Based on the dhis2.de.currentCategories global variable. Returns null if there 
+* are no current categories.
 */
 dhis2.de.getCurrentCategoryOptions = function()
 {
@@ -1161,6 +1161,29 @@
 };
 
 /**
+ * Returns a query param value for the currently selected category options where
+ * each option is separated by the ; character.
+ */
+dhis2.de.getCurrentCategoryOptionsQueryValue = function()
+{
+	if ( !dhis2.de.getCurrentCategoryOptions() ) {
+		return null;
+	}
+	
+	var value = '';
+	
+	$.safeEach( dhis2.de.getCurrentCategoryOptions(), function( idx, option ) {
+		value += option + ';';
+	} );
+	
+	if ( value ) {
+		value = value.slice( 0, -1 );
+	}
+	
+	return value;
+}
+
+/**
 * Returns markup for drop down boxes to be put in the selection box for the
 * given categories. The empty string is returned if no categories are given. 
 */
@@ -1234,6 +1257,15 @@
         organisationUnitId : getCurrentOrganisationUnit(),
         multiOrganisationUnit: dhis2.de.multiOrganisationUnit
     };
+
+    var cc = dhis2.de.getCurrentCategoryCombo();
+    var cp = dhis2.de.getCurrentCategoryOptionsQueryValue();
+    
+    if ( cc && cp )
+    {
+    	params.cc = cc;
+    	params.cp = cp;
+    }
     
     $.ajax( {
     	url: 'getDataValues.action',

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm	2013-12-21 23:00:20 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm	2013-12-22 10:06:39 +0000
@@ -78,7 +78,7 @@
 "categories": {
 #set( $size1 = $categories.size() )
 #foreach( $category in $categories )
-"${category.uid}":{"name":"$encoder.jsonEncode( ${category.displayName} )","options":[
+"${category.uid}":{"id":"${category.uid}","name":"$encoder.jsonEncode( ${category.displayName} )","options":[
 #set( $size2 = $category.categoryOptions.size() )
 #foreach( $option in $category.categoryOptions )
 {"id":"${option.uid}","name":"$encoder.jsonEncode( ${option.displayName} )"}#if( $velocityCount < $size2 ),#end