← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5744: Implemented function for including the data element total for all category options in custom data...

 

------------------------------------------------------------
revno: 5744
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-01-18 07:11:17 +0100
message:
  Implemented function for including the data element total for all category options in custom data entry forms
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java
  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/cacheManifest.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-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.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-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2012-01-18 06:11:17 +0000
@@ -43,6 +43,7 @@
 
     final Pattern INPUT_PATTERN = Pattern.compile( "(<input.*?/>)", Pattern.DOTALL );
     final Pattern IDENTIFIER_PATTERN = Pattern.compile( "(\\d+)-(\\d+)-val" );
+    final Pattern DATAELEMENT_TOTAL_PATTERN = Pattern.compile( "dataelementid=\"(.*?)\"" );
     final Pattern INDICATOR_PATTERN = Pattern.compile( "indicatorid=\"(.*?)\"" );
     final Pattern VALUE_TAG_PATTERN = Pattern.compile( "value=\"(.*?)\"", Pattern.DOTALL );
     final Pattern TITLE_TAG_PATTERN = Pattern.compile( "title=\"(.*?)\"", Pattern.DOTALL );

=== 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-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-01-18 06:11:17 +0000
@@ -172,7 +172,11 @@
             String inputHtml = inputMatcher.group();
 
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
+            Matcher dataElementTotalMatcher = DATAELEMENT_TOTAL_PATTERN.matcher( inputHtml );
             Matcher indicatorMatcher = INDICATOR_PATTERN.matcher( inputHtml );
+            
+            String displayValue = null;
+            String displayTitle = null;
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
@@ -183,40 +187,39 @@
                 DataElementCategoryOptionCombo categegoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId );
                 String optionComboName = categegoryOptionCombo != null ? categegoryOptionCombo.getName() : "[ " + i18n.getString( "cate_option_combo_not_exist" ) + " ]";
 
-                // -------------------------------------------------------------
-                // Insert name of data element operand as value and title
-                // -------------------------------------------------------------
-
                 StringBuilder title = dataElement != null ? 
                     new StringBuilder( "title=\"" ).append( dataElement.getId() ).append( " - " ).
                     append( dataElement.getName() ).append( " - " ).append( optionComboId ).append( " - " ).
                     append( optionComboName ).append( " - " ).append( dataElement.getType() ).append( "\"" ) : new StringBuilder();
 
-                String displayValue = dataElement != null ? "value=\"[ " + dataElement.getName() + " " + optionComboName + " ]\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
-                String displayTitle = dataElement != null ? title.toString() : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
-
-                inputHtml = inputHtml.contains( EMPTY_VALUE_TAG ) ? inputHtml.replace( EMPTY_VALUE_TAG, displayValue ) : inputHtml + " " + displayValue;
-                inputHtml = inputHtml.contains( EMPTY_TITLE_TAG ) ? inputHtml.replace( EMPTY_TITLE_TAG, displayTitle ) : " " + displayTitle;
-
-                inputMatcher.appendReplacement( sb, inputHtml );
+                displayValue = dataElement != null ? "value=\"[ " + dataElement.getName() + " " + optionComboName + " ]\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
+                displayTitle = dataElement != null ? title.toString() : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
+            }
+            else if ( dataElementTotalMatcher.find() && dataElementTotalMatcher.groupCount() > 0 )
+            {
+                int dataElementId = Integer.parseInt( dataElementTotalMatcher.group( 1 ) );
+                DataElement dataElement = dataElementService.getDataElement( dataElementId );
+
+                displayValue = dataElement != null ? "value=\"[ " + dataElement.getName() + " ]\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
+                displayTitle = dataElement != null ? "title=\"" + dataElement.getName() + "\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
             }
             else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
             {
                 int indicatorId = Integer.parseInt( indicatorMatcher.group( 1 ) );
                 Indicator indicator = indicatorService.getIndicator( indicatorId );
 
-                // -------------------------------------------------------------
-                // Insert name of indicator as value and title
-                // -------------------------------------------------------------
-
-                String displayValue = indicator != null ? "value=\"[ " + indicator.getName() + " ]\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
-                String displayTitle = indicator != null ? "title=\"" + indicator.getName() + "\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
-
-                inputHtml = inputHtml.contains( EMPTY_VALUE_TAG ) ? inputHtml.replace( EMPTY_VALUE_TAG, displayValue ) : inputHtml + " " + displayValue;
-                inputHtml = inputHtml.contains( EMPTY_TITLE_TAG ) ? inputHtml.replace( EMPTY_TITLE_TAG, displayTitle ) : " " + displayTitle;
-
-                inputMatcher.appendReplacement( sb, inputHtml );
-            }
+                displayValue = indicator != null ? "value=\"[ " + indicator.getName() + " ]\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
+                displayTitle = indicator != null ? "title=\"" + indicator.getName() + "\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
+            }            
+
+            // -----------------------------------------------------------------
+            // Insert name of data element operand as value and title
+            // -----------------------------------------------------------------
+
+            inputHtml = inputHtml.contains( EMPTY_VALUE_TAG ) ? inputHtml.replace( EMPTY_VALUE_TAG, displayValue ) : inputHtml + " " + displayValue;
+            inputHtml = inputHtml.contains( EMPTY_TITLE_TAG ) ? inputHtml.replace( EMPTY_TITLE_TAG, displayTitle ) : " " + displayTitle;
+
+            inputMatcher.appendReplacement( sb, inputHtml );
         }
 
         inputMatcher.appendTail( sb );

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm	2012-01-11 07:51:55 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm	2012-01-18 06:11:17 +0000
@@ -1,5 +1,5 @@
 CACHE MANIFEST
-# 2.7-SNAPSHOT Version 1
+# 2.7-SNAPSHOT Version 2
 NETWORK:
 *
 CACHE:

=== 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-11-10 20:03:03 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2012-01-18 06:11:17 +0000
@@ -18,6 +18,31 @@
 var FORMULA_PATTERN = /\[.+?\]/g;
 var SEPARATOR = '.';
 
+function updateDataElementTotals()
+{
+	var currentTotals = [];
+	
+	$( 'input[name="total"]' ).each( function( index )
+	{
+		var targetId = $( this ).attr( 'dataelementid' );
+		
+		var totalValue = new Number();
+		
+		$( 'input[name="entryfield"]' ).each( function( index )
+		{	
+			var key = $( this ).attr( 'id' );
+			var entryFieldId = key.substring( 0, key.indexOf( '-' ) );
+			
+			if ( targetId && $( this ).attr( 'value' ) && targetId == entryFieldId )
+			{
+				totalValue += new Number( $( this ).attr( 'value' ) );
+			}
+		} );
+		
+		$( this ).attr( 'value', totalValue );
+	} );
+}
+
 /**
  * Updates all indicator input fields with the calculated value based on the
  * values in the input entry fields in the form.
@@ -174,7 +199,8 @@
     	currentOrganisationUnitId, periodId, value, COLOR_GREEN );
     valueSaver.save();
 
-    updateIndicators(); // Update indicators in case of custom form
+    updateIndicators(); // Update indicators for custom form
+    updateDataElementTotals(); // Update data element totals for custom forms
 }
 
 function saveBoolean( dataElementId, optionComboId )

=== 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-12-23 10:52:08 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2012-01-18 06:11:17 +0000
@@ -699,6 +699,7 @@
 	        // Update indicator values in form
 	
 	        updateIndicators();
+	        updateDataElementTotals();
 	
 	        // Set completeness button
 	

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2011-12-14 08:10:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2012-01-18 06:11:17 +0000
@@ -138,4 +138,5 @@
 assigned=Assigned
 unassigned=Unassigned
 show_selection_box=Show selection box
-greyed_field=Greyed field
\ No newline at end of file
+grey_field=Grey field
+totals=Totals
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-10-23 19:14:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2012-01-18 06:11:17 +0000
@@ -17,10 +17,12 @@
 
 	$("#selectionDialog").parent().bind("resize", function(e) {
 		var dialog = $("#selectionDialog");
+		var dataElementSelector = $("#dataElementSelector");
+		var totalSelector = $("#totalSelector");
 		var indicatorSelector = $("#indicatorSelector");
-		var dataElementSelector = $("#dataElementSelector");
 
 		dataElementSelector.height( dialog.height() - 97 );
+		totalSelector.height( dialog.height() - 97 );
 		indicatorSelector.height( dialog.height() - 97 );
 	});
 
@@ -28,6 +30,7 @@
 	$(":submit").button();
 
 	$("#dataElementInsertButton").click(insertDataElement);
+	$("#totalInsertButton").click(insertTotal);
 	$("#indicatorInsertButton").click(insertIndicator);
 
 	$("#selectionDialog").bind("dialogopen", function(event, ui) {
@@ -46,18 +49,28 @@
 	
 	showDataElements();
 
+	$("#dataElementsButton").addClass("ui-state-active2");
+
 	$("#dataElementsButton").click(function() {
 		$("#dataElementsButton").addClass("ui-state-active2");
+		$("#totalsButton").removeClass("ui-state-active2");
 		$("#indicatorsButton").removeClass("ui-state-active2");
 
 		showDataElements();
 	});
-
-	$("#dataElementsButton").addClass("ui-state-active2");
-
-	$("#indicatorsButton").click(function() {
+	
+	$("#totalsButton").click(function() {		
+		$("#dataElementsButton").removeClass("ui-state-active2");
+		$("#totalsButton").addClass("ui-state-active2");
+		$("#indicatorsButton").removeClass("ui-state-active2");
+		
+		showTotals();
+	});
+
+	$("#indicatorsButton").click(function() {	
+		$("#dataElementsButton").removeClass("ui-state-active2");
+		$("#totalsButton").removeClass("ui-state-active2");
 		$("#indicatorsButton").addClass("ui-state-active2");
-		$("#dataElementsButton").removeClass("ui-state-active2");
 
 		showIndicators();
 	});
@@ -65,7 +78,11 @@
 	$("#insertButton").click(function() {
 		if( $("#dataElementsTab").is(":visible") ) {
 			insertDataElement();
-		} else {
+		} 
+		else if( $("#totalsTab").is(":visible") ) {
+			insertTotals();
+		}
+		else {
 			insertIndicator();
 		}
 	});
@@ -86,6 +103,15 @@
 		filterSelectList( 'dataElementSelector', $("#dataElementsFilterInput").val() );
 	});
 	
+	$("#totalsFilterButton").button({
+		icons: {
+			primary: "ui-icon-search"
+		},
+		text: false
+	}).click(function() {
+		filterSelectList( 'totalSelector', $("#totalsFilterInput").val() );
+	});
+	
 	$("#indicatorsFilterButton").button({
 		icons: {
 			primary: "ui-icon-search"
@@ -99,15 +125,28 @@
 function showDataElements() {
 	$("#dataElementsTab").show();
 	$("#dataElementsFilter").show();
+	$("#totalsTab").hide();
+	$("#totalsFilter").hide();
+	$("#indicatorsTab").hide();
+	$("#indicatorsFilter").hide();
+}
+
+function showTotals() {
+	$("#dataElementsTab").hide();
+	$("#dataElementsFilter").hide();
+	$("#totalsTab").show();
+	$("#totalsFilter").show();
 	$("#indicatorsTab").hide();
 	$("#indicatorsFilter").hide();
 }
 
 function showIndicators() {
+	$("#dataElementsTab").hide();
+	$("#dataElementsFilter").hide();
+	$("#totalsTab").hide();
+	$("#totalsFilter").hide();
 	$("#indicatorsTab").show();
 	$("#indicatorsFilter").show();
-	$("#dataElementsTab").hide();
-	$("#dataElementsFilter").hide();
 }
 
 function filterSelectList( select_id, filter )
@@ -164,25 +203,6 @@
 	});
 }
 
-function insertIndicator() {
-	var oEditor = $("#designTextarea").ckeditorGet();
-	var $option = $("#indicatorSelector option:selected");
-
-	if( $option.length !== 0 ) {
-		var id = $option.data("id");
-		var title = $option.val();
-		var template = '<input id="indicator' + id + '" value="[ ' + title + ' ]" title="' + title + '" name="indicator" indicatorid="' + id + '" style="width:7em;text-align:center;" readonly="readonly" />';
-
-		if(!checkExisted("indicator" + id)) {
-			oEditor.insertHtml( template );
-		} else {
-			showThenFadeOutMessage( "<b>" + i18n_indicator_already_inserted + "</b>" );
-		}
-	} else {
-		showThenFadeOutMessage( "<b>" + i18n_no_indicator_was_selected + "</b>" );
-	}
-}
-
 function insertDataElement() {
 	var oEditor = $("#designTextarea").ckeditorGet();
 	var $option = $("#dataElementSelector option:selected");
@@ -225,6 +245,46 @@
 	}
 }
 
+function insertTotal() {
+	var oEditor = $("#designTextarea").ckeditorGet();
+	var $option = $("#totalSelector option:selected");
+	
+	if( $option.length !== 0 )
+	{
+		var id = $option.data("id");
+		var title = $option.val();
+		var dataEntryId = 'total' + id;		
+		var template = '<input id="' + dataEntryId + '" name="total" value="[' + title + ']" title="' + title + '" dataelementid="' + id + '" style="width:7em;text-align:center;" readonly="readonly" />';
+		
+		if(!checkExisted(dataEntryId)) {
+			oEditor.insertHtml( template );
+		} else {
+			showThenFadeOutMessage( "<b>" + i18n_dataelement_already_inserted + "</b>" );
+		}
+	} else {
+		showThenFadeOutMessage( "<b>" + i18n_no_dataelement_was_selected + "</b>" );
+	}
+}
+
+function insertIndicator() {
+	var oEditor = $("#designTextarea").ckeditorGet();
+	var $option = $("#indicatorSelector option:selected");
+
+	if( $option.length !== 0 ) {
+		var id = $option.data("id");
+		var title = $option.val();
+		var template = '<input id="indicator' + id + '" value="[ ' + title + ' ]" title="' + title + '" name="indicator" indicatorid="' + id + '" style="width:7em;text-align:center;" readonly="readonly" />';
+
+		if(!checkExisted("indicator" + id)) {
+			oEditor.insertHtml( template );
+		} else {
+			showThenFadeOutMessage( "<b>" + i18n_indicator_already_inserted + "</b>" );
+		}
+	} else {
+		showThenFadeOutMessage( "<b>" + i18n_no_indicator_was_selected + "</b>" );
+	}
+}
+
 function checkExisted(id) {
 	var result = false;
 	var html = $("#designTextarea").ckeditorGet().getData();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2011-11-21 12:44:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2012-01-18 06:11:17 +0000
@@ -32,6 +32,22 @@
 			}
 		});
 
+		jQuery("#totalSelector").dhisAjaxSelect({
+			source: "../dhis-web-commons-ajax-json/getDataElements.action",
+			iterator: "dataElements",
+			handler: function(item) {
+				var option = jQuery("<option />");
+				option.text( item.name );
+				option.data( "id", item.id );
+				option.dblclick(insertTotal);
+
+				return option;
+			},
+			params: {
+				dataSetId: $dataSet.id
+			}
+		});
+
 		jQuery("#indicatorSelector").dhisAjaxSelect({
 			source: "../dhis-web-commons-ajax-json/getIndicators.action",
 			iterator: "indicators",
@@ -86,7 +102,7 @@
 	padding: 2px;
 }
 
-#indicatorSelector, #dataElementSelector {
+#dataElementSelector, #totalSelector, #indicatorSelector,  {
 	padding: 2px;
 }
 </style>
@@ -156,6 +172,11 @@
 					<select id="dataElementSelector" multiple="multiple" style="height: 200px; width: 100%;"></select>
 				</td>
 			</tr>
+			<tr id="totalsTab">
+				<td colspan="2">
+					<select id="totalSelector" multiple="multiple" style="height: 200px; width: 100%;"></select>
+				</td>
+			</tr>
 			<tr id="indicatorsTab">
 				<td colspan="2">
 					<select id="indicatorSelector" multiple="multiple" style="height: 200px; width: 100%;"></select>
@@ -164,11 +185,12 @@
 			<tr>
 				<td>
 					<button type="button" id="dataElementsButton">$i18n.getString( "data_elements" )</button>
+					<button type="button" id="totalsButton">$i18n.getString( "totals" )</button>
 					<button type="button" id="indicatorsButton">$i18n.getString( "indicators" )</button>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
 					<button type="button" id="insertButton">$i18n.getString( "insert" )</button>
-					<input type="checkbox" id="greyedField"><label for="greyedField">$i18n.getString( "greyed_field" )</label>
+					<input type="checkbox" id="greyedField"><label for="greyedField">$i18n.getString( "grey_field" )</label>
 				</td>
-				<td style="width: 190px;">
+				<td style="width:145px">
 					<span id="message_"></span>
 				</td>
 			</tr>