← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13377: Data entry, re-arranged js code

 

------------------------------------------------------------
revno: 13377
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-12-21 22:21:51 +0100
message:
  Data entry, re-arranged js code
modified:
  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/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-12-21 20:56:46 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-12-21 21:21:51 +0000
@@ -705,8 +705,9 @@
 // Supportive methods
 //------------------------------------------------------------------------------
 
-// splits a id based on the multiOrgUnit var
-
+/**
+ * Splits an id based on the multi org unit variable.
+ */
 function splitFieldId( id )
 {
     var split = {};
@@ -832,7 +833,7 @@
         {
             filteredDataSetList.push(item);
         }
-    });
+    } );
 
     return filteredDataSetList;
 }
@@ -923,55 +924,6 @@
 }
 
 // -----------------------------------------------------------------------------
-// Next/Previous Periods Selection
-// -----------------------------------------------------------------------------
-
-function nextPeriodsSelected()
-{
-    if ( dhis2.de.currentPeriodOffset < 0 ) // Cannot display future periods
-    {
-    	dhis2.de.currentPeriodOffset++;
-        displayPeriodsInternal();
-    }
-}
-
-function previousPeriodsSelected()
-{
-	dhis2.de.currentPeriodOffset--;
-    displayPeriodsInternal();
-}
-
-function displayPeriodsInternal()
-{
-    var dataSetId = $( '#selectedDataSetId' ).val();
-    var periodType = dhis2.de.dataSets[dataSetId].periodType;
-    var allowFuturePeriods = dhis2.de.dataSets[dataSetId].allowFuturePeriods;
-    var periods = dhis2.de.periodTypeFactory.get( periodType ).generatePeriods( dhis2.de.currentPeriodOffset );
-    periods = dhis2.de.periodTypeFactory.reverse( periods );
-    
-    if ( allowFuturePeriods == false )
-    {
-    	periods = dhis2.de.periodTypeFactory.filterFuturePeriods( periods );
-    }
-
-    clearListById( 'selectedPeriodId' );
-
-    if ( periods.length > 0 )
-    {
-    	addOptionById( 'selectedPeriodId', '-1', '[ ' + i18n_select_period + ' ]' );
-    }
-    else
-    {
-    	addOptionById( 'selectedPeriodId', '-1', i18n_no_periods_click_prev_year_button );
-    }
-    
-    $.safeEach( periods, function( idx, item ) 
-    {
-        addOptionById( 'selectedPeriodId', item.iso, item.name );
-    } );
-}
-
-// -----------------------------------------------------------------------------
 // DataSet Selection
 // -----------------------------------------------------------------------------
 
@@ -1060,6 +1012,51 @@
     }
 }
 
+function nextPeriodsSelected()
+{
+    if ( dhis2.de.currentPeriodOffset < 0 ) // Cannot display future periods
+    {
+    	dhis2.de.currentPeriodOffset++;
+        displayPeriodsInternal();
+    }
+}
+
+function previousPeriodsSelected()
+{
+	dhis2.de.currentPeriodOffset--;
+    displayPeriodsInternal();
+}
+
+function displayPeriodsInternal()
+{
+    var dataSetId = $( '#selectedDataSetId' ).val();
+    var periodType = dhis2.de.dataSets[dataSetId].periodType;
+    var allowFuturePeriods = dhis2.de.dataSets[dataSetId].allowFuturePeriods;
+    var periods = dhis2.de.periodTypeFactory.get( periodType ).generatePeriods( dhis2.de.currentPeriodOffset );
+    periods = dhis2.de.periodTypeFactory.reverse( periods );
+    
+    if ( allowFuturePeriods == false )
+    {
+    	periods = dhis2.de.periodTypeFactory.filterFuturePeriods( periods );
+    }
+
+    clearListById( 'selectedPeriodId' );
+
+    if ( periods.length > 0 )
+    {
+    	addOptionById( 'selectedPeriodId', '-1', '[ ' + i18n_select_period + ' ]' );
+    }
+    else
+    {
+    	addOptionById( 'selectedPeriodId', '-1', i18n_no_periods_click_prev_year_button );
+    }
+    
+    $.safeEach( periods, function( idx, item ) 
+    {
+        addOptionById( 'selectedPeriodId', item.iso, item.name );
+    } );
+}
+
 // -----------------------------------------------------------------------------
 // Form
 // -----------------------------------------------------------------------------
@@ -1370,43 +1367,49 @@
 }
 
 /**
- * Returns an array of category combo objects for the given data set. Default
- * category combos are omitted.
+ * Returns an array of category objects for the given data set identifier. Categories 
+ * are looked up using the category combo of the data set. Null is returned if 
+ * the given data set has the default category combo.
  */
-dhis2.de.getCategoryCombos = function( dataSets )
+dhis2.de.getCategories = function( dataSetId )
 {
-	var combos = [];
-	
-	$.safeEach( dataSets, function( idx, item ) {
-		if ( item.categoryCombo && dhis2.de.defaultCategoryCombo != item.categoryCombo ) {
-			var combo = dhis2.de.categoryCombos[item.categoryCombo];
-			combos.push( combo );
-		}
+	var dataSet = dhis2.de.dataSets[dataSetId];
+	
+	if ( !dataSet || dhis2.de.defaultCategoryCombo === dataSet.categoryCombo ) {
+		return null;
+	}
+	
+	var categoryCombo = dhis2.de.categoryCombos[dataSet.categoryCombo];
+	
+	var categories = [];
+	
+	$.safeEach( combo.categories, function( idx, cat ) {
+		var category = dhis2.de.categories[cat];
+		categories.push( category );
 	} );
 	
-	return combos;
+	return categories;
 }
 
 /**
  * Returns markup for drop down boxes to be put in the selection box for the
- * given category combos.
+ * given categories. If no categories are given the empty string is returned.
  */
-dhis2.de.getAttributeComboMarkup = function( categoryCombos )
+dhis2.de.getAttributesMarkup = function( categories )
 {
 	var html = '';
 	
-	if ( undefined === categoryCombos || categoryCombos.length == 0 ) {
+	if ( !categories || categories.length == 0 ) {
 		return html;
 	}
 	
-	$.safeEach( categoryCombos, function( idx, combo ) {
+	$.safeEach( categories, function( idx, category ) {
 		html += '<div class="selectionBoxRow">';
-		html += '<div class="selectionLabel">' + combo.name + '</div>';
-		html += '<select id="combo-' + combo.id + '" class="selectionBoxSelect">';
+		html += '<div class="selectionLabel">' + category.name + '</div>';
+		html += '<select id="category-' + category.id + '" class="selectionBoxSelect">';
 		
-		$.safeEach( combo.categories, function( idx, cat ) {
-			var category = dhis2.de.categories[cat];
-			html += '<option value="' + category.id + '">' + category.name + '</option>';
+		$.safeEach( category.options, function( idx, option ) {
+			html += '<option value="' + option.id + '">' + option.name + '</option>';
 		} );
 		
 		html += '</select>';

=== 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 20:44:52 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm	2013-12-21 21:21:51 +0000
@@ -82,7 +82,7 @@
 "${category.uid}":{"name":"$encoder.jsonEncode( ${category.displayName} )","options":[
 #set( $size2 = $category.categoryOptions.size() )
 #foreach( $option in $category.categoryOptions )
-{"id":"${option.uid}","id":"${option.uid}","name":"$encoder.jsonEncode( ${option.displayName} )"}#if( $velocityCount < $size2 ),#end
+{"id":"${option.uid}","name":"$encoder.jsonEncode( ${option.displayName} )"}#if( $velocityCount < $size2 ),#end
 #end
 ] }#if( $velocityCount < $size1 ),#end
 #end