← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8076: WIP dynamic fields in cdf

 

------------------------------------------------------------
revno: 8076
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-09-13 17:48:05 +0200
message:
  WIP dynamic fields in cdf
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-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


--
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	2012-01-28 17:42:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2012-09-13 15:48:05 +0000
@@ -47,6 +47,7 @@
     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 DYNAMIC_ELEMENT_PATTERN = Pattern.compile( "categoryoptioncomboid=\"(.*?)\"" );
     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	2012-08-14 04:37:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-09-13 15:48:05 +0000
@@ -176,6 +176,7 @@
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
             Matcher dataElementTotalMatcher = DATAELEMENT_TOTAL_PATTERN.matcher( inputHtml );
             Matcher indicatorMatcher = INDICATOR_PATTERN.matcher( inputHtml );
+            Matcher dynamicElementMatcher = DYNAMIC_ELEMENT_PATTERN.matcher( inputHtml );
             
             String displayValue = null;
             String displayTitle = null;
@@ -187,14 +188,14 @@
 
                 int optionComboId = Integer.parseInt( identifierMatcher.group( 2 ) );
                 DataElementCategoryOptionCombo categegoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId );
-                String optionComboName = categegoryOptionCombo != null ? categegoryOptionCombo.getName() : "[ " + i18n.getString( "cate_option_combo_not_exist" ) + " ]";
+                String optionComboName = categegoryOptionCombo != null ? categegoryOptionCombo.getName() : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
 
                 StringBuilder title = dataElement != null ? 
                     new StringBuilder( "title=\"" ).append( dataElement.getId() ).append( " - " ).
                     append( dataElement.getDisplayName() ).append( " - " ).append( optionComboId ).append( " - " ).
                     append( optionComboName ).append( " - " ).append( dataElement.getType() ).append( "\"" ) : new StringBuilder();
 
-                displayValue = dataElement != null ? "value=\"[ " + dataElement.getDisplayName() + " " + optionComboName + " ]\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
+                displayValue = dataElement != null ? "value=\"[ " + dataElement.getDisplayName() + " " + optionComboName + " ]\"" : "[ " + i18n.getString( "data_element_not_exist" ) + " ]";
                 displayTitle = dataElement != null ? title.toString() : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
             }
             else if ( dataElementTotalMatcher.find() && dataElementTotalMatcher.groupCount() > 0 )
@@ -202,8 +203,8 @@
                 int dataElementId = Integer.parseInt( dataElementTotalMatcher.group( 1 ) );
                 DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
-                displayValue = dataElement != null ? "value=\"[ " + dataElement.getDisplayName() + " ]\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
-                displayTitle = dataElement != null ? "title=\"" + dataElement.getDisplayName() + "\"" : "[ " + i18n.getString( "dataelement_not_exist" ) + " ]";
+                displayValue = dataElement != null ? "value=\"[ " + dataElement.getDisplayName() + " ]\"" : "[ " + i18n.getString( "data_element_not_exist" ) + " ]";
+                displayTitle = dataElement != null ? "title=\"" + dataElement.getDisplayName() + "\"" : "[ " + i18n.getString( "dat_aelement_not_exist" ) + " ]";
             }
             else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
             {
@@ -212,14 +213,22 @@
 
                 displayValue = indicator != null ? "value=\"[ " + indicator.getDisplayName() + " ]\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
                 displayTitle = indicator != null ? "title=\"" + indicator.getDisplayName() + "\"" : "[ " + i18n.getString( "indicator_not_exist" ) + " ]";
-            }            
+            }
+            else if ( dynamicElementMatcher.find() && dynamicElementMatcher.groupCount() > 0 )
+            {
+                String categoryOptionComboUid = dynamicElementMatcher.group( 1 );
+                DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( categoryOptionComboUid );
+                
+                displayValue = categoryOptionCombo != null ? "value=\"[ " + categoryOptionCombo.getDisplayName() + " ]\"" : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
+                displayTitle = categoryOptionCombo != null ? "title=\"" + categoryOptionCombo.getDisplayName() + "\"" : "[ " + i18n.getString( "cat_option_combo_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;
+            inputHtml = inputHtml.contains( EMPTY_TITLE_TAG ) ? inputHtml.replace( EMPTY_TITLE_TAG, displayTitle ) : inputHtml + " " + displayTitle;
 
             inputMatcher.appendReplacement( sb, inputHtml );
         }

=== 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	2012-09-13 14:34:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2012-09-13 15:48:05 +0000
@@ -95,4 +95,7 @@
 start=Start
 insert_data_element_drop_down=Insert data element drop-down
 select_category_combo_for_which_to_insert=Select category combination for which to insert dynamic fields
-insert_input_fields_into_the_form=Insert input fields into the form
\ No newline at end of file
+insert_input_fields_into_the_form=Insert input fields into the form
+cat_option_combo_not_exist=Category option combo does not exist
+data_element_not_exist=Data element does not exist
+indicator_not_exist=Indicator does not exist

=== 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	2012-09-13 14:34:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2012-09-13 15:48:05 +0000
@@ -1,5 +1,6 @@
 
 var currentDynamicElementCode = "";
+var currentCategoryComboUid = "";
 
 $( document ).ready( function() {
 	
@@ -45,7 +46,9 @@
 	$("#startButton").button("option", "icons", { primary: "ui-icon-triangle-1-e" });
 	$("#startButton").click( showDynamicElementInsert );
 	$("#doneButton").click( showDynamicElementSelect );
+	
 	$("#insertDynamicElementButton").button("option", "icons", { primary: "ui-icon-plusthick" });
+	$("#insertDynamicElementButton").click( insertDropDownList );
 	
 	showDataElements();
 
@@ -363,16 +366,39 @@
 	}
 }
 
+/**
+ * A unique code is used to associate the data element drop down with the input
+ * fields for each category option combo. The format for input field is:
+ * 
+ * <input id="<unique code>-dynamic" categoryoptioncomboid="<category option combo uid>" />
+ */
 function insertDynamicElement() {
 	var oEditor = $("#designTextarea").ckeditorGet();
 	var $option = $("#dynamicElementSelector option:selected");
 	
 	if( $option.length !== 0 ) {
-		var categoryOptionComboId = $option.val();
+		var categoryOptionComboUid = $option.val();
 		var categoryOptionComboName = $option.text();
 		var id = currentDynamicElementCode + "-dynamic";
+		var title = categoryOptionComboUid + " - " + categoryOptionComboName;
 		
-		var template = '<input id="' + id + '" categoryoptioncomboid="' + categoryOptionComboId + '" value="[ ' + categoryOptionComboName + ' ]" style="width:7em;text-align:center;" />';
+		var template = '<input id="' + id + '" categoryoptioncomboid="' + categoryOptionComboUid + '" value="[ ' + categoryOptionComboName + ' ]" title="' + title + '" style="width:7em;text-align:center;" />';
+		oEditor.insertHtml( template );
+	}
+}
+
+/**
+ * A unique code is used to associate the data element drop down with the input
+ * fields for each category option combo.  The format for select / drop down list 
+ * is:
+ * 
+ * <select id="<unique code>-categorycombo" />
+ */
+function insertDropDownList() {
+	var oEditor = $("#designTextarea").ckeditorGet();
+	
+	if ( currentDynamicElementCode && currentCategoryComboUid ) {
+		var template = '<select id="' + currentCategoryComboUid + '-categorycombo" style="width:15em;"></select>';
 		oEditor.insertHtml( template );
 	}
 }
@@ -382,19 +408,14 @@
 	$("#dynamicElementInsert").hide();	
 }
 
-/**
- * A unique code is used to associate the data element drop down with the input
- * fields for each category option combo. The format for input field keys is:
- * 
- * <unique code>-<category option combo uid>-dynamic
- */
 function showDynamicElementInsert() {
 	$("#dynamicElementSelect").hide();
 	$("#dynamicElementInsert").show();
 	
+	var categoryComboUid = $("#categoryComboSelect").val();
+
 	currentDynamicElementCode = getRandomCode();
-	
-	var categoryComboUid = $("#categoryComboSelect").val();
+	currentCategoryComboUid = categoryComboUid;
 	
 	clearListById( "dynamicElementSelector" );