← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4187: Keeping min-max values in javascript rather than forms, reduces size of forms

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4187 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-07-21 16:15:14 +0200
message:
  Keeping min-max values in javascript rather than forms, reduces size of forms
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm
  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/javascript/history.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2011-07-20 03:42:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2011-07-21 14:01:52 +0000
@@ -240,9 +240,7 @@
         final String historyCode = " ondblclick='javascript:viewHist( $DATAELEMENTID, $OPTIONCOMBOID )' ";
         
         final String metaDataCode = "<span id=\"$DATAELEMENTID-dataelement\" style=\"display:none\">$DATAELEMENTNAME</span>"
-            + "<span id=\"$DATAELEMENTID-type\" class=\"hidden\">$DATAELEMENTTYPE</span>"
-            + "<span id=\"$DATAELEMENTID-$OPTIONCOMBOID-min\" name=\"min\" class=\"hidden\"></span>"
-            + "<span id=\"$DATAELEMENTID-$OPTIONCOMBOID-max\" name=\"max\" class=\"hidden\"></span>";
+            + "<span id=\"$DATAELEMENTID-type\" class=\"hidden\">$DATAELEMENTTYPE</span>";
 
         StringBuffer sb = new StringBuffer();
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js	2011-07-21 11:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js	2011-07-21 12:37:10 +0000
@@ -38,10 +38,6 @@
 		
 		for ( var j = 0; j < periods.length; j++ )
 		{
-			var c = periods[j];
-			var d = periods[j]['startDate'];
-			var e = null;
-			
 			if ( $.date( periods[j]['startDate'], dateFormat ).date().getTime() < now )
 			{
 				array[i++] = periods[j];

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java	2011-07-19 21:49:16 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/PageInitAction.java	2011-07-21 14:11:46 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 
 import com.opensymphony.xwork2.Action;
 
@@ -77,6 +78,13 @@
         this.dataSetService = dataSetService;
     }
 
+    private OrganisationUnitSelectionManager selectionManager;
+
+    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
+    {
+        this.selectionManager = selectionManager;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -108,6 +116,8 @@
 
     public String execute()
     {
+        selectionManager.clearSelectedOrganisationUnits();
+        
         significantZeros = dataElementService.getDataElementsByZeroIsSignificant( true );
         
         indicators = indicatorService.getIndicatorsWithDataSets();

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2011-07-20 21:38:30 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2011-07-21 14:11:46 +0000
@@ -17,6 +17,7 @@
 	<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
 	<property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
 	<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+    <property name="selectionManager" ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
   </bean>
 
   <bean id="org.hisp.dhis.de.action.GetDataValuesForDataSetAction" class="org.hisp.dhis.de.action.GetDataValuesForDataSetAction"

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml	2011-07-21 11:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml	2011-07-21 14:01:52 +0000
@@ -64,7 +64,7 @@
     <action name="viewHistory" class="org.hisp.dhis.de.action.HistoryAction">
       <result name="success" type="velocity">/popup.vm</result>
       <param name="page">/dhis-web-dataentry/history.vm</param>
-      <param name="javascripts">javascript/history.js</param>
+      <param name="javascripts">javascript/form.js,javascript/history.js</param>
     </action>
 
     <action name="registerCompleteDataSet" class="org.hisp.dhis.de.action.RegisterCompleteDataSetAction">

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm	2011-07-13 15:09:37 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm	2011-07-21 14:01:52 +0000
@@ -40,8 +40,7 @@
       <span id="${dataElement.id}-type" class="hidden">$dataElement.getDetailedNumberType()</span>
     </td>
     #foreach( $optionCombo in $optionCombos )
-	    #set( $dataEntryId = "${dataElement.id}-${optionCombo.id}-val" )
-	    <span id="${dataElement.id}-${optionCombo.id}-min" name="min" class="hidden"></span><span id="${dataElement.id}-${optionCombo.id}-max" name="max" class="hidden"></span>
+	    #set( $dataEntryId = "${dataElement.id}-${optionCombo.id}-val" )	    
 	    <td>
 	    #if( $dataElement.type == "bool" )
 		    <select name="entryselect" id="$dataEntryId" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) ) onchange="saveBoolean($dataElement.id,$optionCombo.id )"  #else disabled="disabled" #end style="width:100%" tabindex="$tabIndex" #if( $locked ) disabled="disabled"#end>

=== 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-07-19 21:49:16 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-07-21 14:01:52 +0000
@@ -135,8 +135,8 @@
                 }
             }
 
-            var minString = $( '#' + dataElementId + '-' + optionComboId + '-min' ).html();
-            var maxString = $( '#' + dataElementId + '-' + optionComboId + '-max' ).html();
+            var minString = currentMinMaxValueMap[dataElementId + '-' + optionComboId + '-min'];
+            var maxString = currentMinMaxValueMap[dataElementId + '-' + optionComboId + '-max'];
 
             if ( minString && maxString ) // TODO if only one exists?
             {

=== 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-07-21 11:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-07-21 14:01:52 +0000
@@ -7,6 +7,9 @@
 // Array with associative arrays for each data set, populated in select.vm
 var dataSets = [];
 
+// Array with keys on form {dataelementid}-{optioncomboid}-min/max with min/max values
+var currentMinMaxValueMap = [];
+
 // Indicates whether any data entry form has been loaded
 var dataEntryFormIsLoaded = false;
 
@@ -232,7 +235,7 @@
 
 function insertDataValues()
 {
-	var valueMap = new Array();
+	var dataValueMap = new Array();
 	
 	var periodId = $( '#selectedPeriodId' ).val();
     var dataSetId = $( '#selectedDataSetId' ).val();
@@ -261,34 +264,28 @@
 				$( fieldId ).val( value.val );
 			}
 			
-			valueMap[value.id] = value.val;
+			dataValueMap[value.id] = value.val;
 		} );
 		
 		// Set min-max values and colorize violation fields
 		
 		$.each( json.minMaxDataElements, function( i, value )
 		{
-			var minFieldId = '#' + value.id + '-min';
-			var maxFieldId = '#' + value.id + '-max';
+			var minId = value.id + '-min';
+			var maxId = value.id + '-max';
+			
 			var valFieldId = '#' + value.id + '-val';
 			
-			if ( $( minFieldId ) )
-			{
-				$( minFieldId ).html( value.min );
-			}
-			
-			if ( $( maxFieldId ) )
-			{
-				$( maxFieldId ).html( value.max );
-			}
-			
-			var dataValue = valueMap[value.id];
+			var dataValue = dataValueMap[value.id];
 			
 			if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number( value.min ) ) 
 				|| ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) )
 			{
 				$( valFieldId ).css( 'background-color', COLOR_ORANGE );
 			}
+			
+			currentMinMaxValueMap[minId] = value.min;
+			currentMinMaxValueMap[maxId] = value.max;
 		} );
 		
 		// Update indicator values in form

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2011-07-20 21:38:30 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2011-07-21 14:01:52 +0000
@@ -114,11 +114,8 @@
 		$( '#maxSpan' ).html( '' );
 	}
 	
-	if ( window.opener && window.opener.document ) 
-	{
-		window.opener.document.getElementById( currentDataElementId + '-' + currentOptionComboId + '-min' ).innerHTML = minValue;
-    	window.opener.document.getElementById( currentDataElementId + '-' + currentOptionComboId + '-max' ).innerHTML = maxValue;
-	}
+	currentMinMaxValueMap[currentDataElementId + '-' + currentOptionComboId + '-min'] = minValue;
+	currentMinMaxValueMap[currentDataElementId + '-' + currentOptionComboId + '-max'] = maxValue;
 	
     var url = 'saveMinMaxLimits.action?organisationUnitId=' + currentOrganisationUnitId + '&dataElementId=' + currentDataElementId + 
     	'&optionComboId=' + currentOptionComboId + '&minLimit=' + minValue + '&maxLimit=' + maxValue;

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2011-07-13 15:09:37 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2011-07-21 14:01:52 +0000
@@ -58,8 +58,7 @@
         #foreach( $optionCombo in $optionCombos )
         #set( $dataEntryId = "${dataElement.id}-${optionCombo.id}-val" )
         #set( $greyedField = false )
-        #set( $greyedField = $greyedFields.get( "$dataElement.id:$optionCombo.id" ) )
-        <span id="${dataElement.id}-${optionCombo.id}-min" name="min" class="hidden"></span><span id="${dataElement.id}-${optionCombo.id}-max" name="max" class="hidden"></span>
+        #set( $greyedField = $greyedFields.get( "$dataElement.id:$optionCombo.id" ) )        
         <td>
         #if( $dataElement.type == "bool" )
         <select name="entryselect" id="$dataEntryId" #if( $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) ) onchange="saveBoolean($dataElement.id,$optionCombo.id )"  #else disabled="disabled" #end style="width:100%" tabindex="$tabIndex" #if( $locked ) disabled="disabled"#end #if( $greyedField ) disabled="disabled"#end>