← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8104: WIP dynamic fields

 

------------------------------------------------------------
revno: 8104
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-09-16 16:44:45 +0200
message:
  WIP dynamic fields
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-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
  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-09-15 14:27:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2012-09-16 14:44:45 +0000
@@ -48,7 +48,7 @@
     final Pattern DATAELEMENT_TOTAL_PATTERN = Pattern.compile( "dataelementid=\"(.*?)\"" );
     final Pattern INDICATOR_PATTERN = Pattern.compile( "indicatorid=\"(.*?)\"" );
     final Pattern DYNAMIC_INPUT_PATTERN = Pattern.compile( "(.*?)-(.*?)-dyninput" );
-    final Pattern DYNAMIC_SELECT_PATTERN = Pattern.compile( "(.*?)-(.*?)-dynselect" );
+    final Pattern DYNAMIC_SELECT_PATTERN = Pattern.compile( "dynselect=\"(.*?)\"" );
     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-09-16 00:11:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-09-16 14:44:45 +0000
@@ -230,7 +230,7 @@
             }
             else if ( dynamicSelectMatcher.find() && dynamicSelectMatcher.groupCount() > 0 )
             {
-                int categoryComboId = Integer.parseInt( dynamicSelectMatcher.group( 2 ) );
+                int categoryComboId = Integer.parseInt( dynamicSelectMatcher.group( 1 ) );
                 DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( categoryComboId );
                 
                 displayValue = categoryCombo != null ? "value=\"[ " + categoryCombo.getDisplayName() + " ]\"" : "[ " + i18n.getString( "cat_combo_not_exist" );
@@ -283,6 +283,7 @@
             String inputHtml = inputMatcher.group();
 
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
+            Matcher dynamicInputMather = DYNAMIC_INPUT_PATTERN.matcher( inputHtml );
             Matcher dynamicSelectMatcher = DYNAMIC_SELECT_PATTERN.matcher( inputHtml );
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
@@ -328,6 +329,20 @@
                 inputHtml += "<span id=\"" + dataElement.getId() + "-dataelement\" style=\"display:none\">" + dataElement.getFormNameFallback() + "</span>";
                 inputHtml += "<span id=\"" + categoryOptionCombo.getId() + "-optioncombo\" style=\"display:none\">" + categoryOptionCombo.getName() + "</span>";
             }
+            else if ( dynamicInputMather.find() && dynamicInputMather.groupCount() > 0 )
+            {
+                int optionComboId = Integer.parseInt( dynamicInputMather.group( 2 ) );
+
+                DataElementCategoryOptionCombo categoryOptionCombo = categoryService
+                    .getDataElementCategoryOptionCombo( optionComboId );
+
+                if ( categoryOptionCombo == null )
+                {
+                    return i18n.getString( "category_option_combo_with_id" ) + ": " + optionComboId + " " + i18n.getString( "does_not_exist" );
+                }
+                
+                inputHtml = inputHtml.replace( TAG_CLOSE, " name=\"dyninput\" tabindex=\"" + i++ + "\"" + TAG_CLOSE );
+            }
             else if ( dynamicSelectMatcher.find() && dynamicSelectMatcher.groupCount() > 0 )
             {
                 inputHtml = inputHtml.replace( "<input", "<select name=\"dynselect\"" );

=== 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	2012-09-16 07:37:56 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2012-09-16 14:44:45 +0000
@@ -329,7 +329,7 @@
             viewHist( dataElementId, optionComboId );
         } );
 
-        $( this ).keyup( function(event)
+        $( this ).keyup( function( event )
         {
             keyPress( event, this );
         } );
@@ -368,7 +368,28 @@
         $( this ).css( 'width', '100%' );
     } );
     
-    $( '[name="dynselect"]' ).each( function( i )
+    $( '[name="dyninput"]' ).each( function( i ) // Custom only
+    {
+    	var id = $( this ).attr( 'id' );
+    	var code = id.split( '-' )[0];
+        var optionComboId = id.split( '-' )[1];
+        
+        $( this ).unbind( 'focus' );
+        $( this ).unbind( 'change' );
+
+        $( this ).change( function()
+        {
+            var dataElementId = $( '#' + code + '-dynselect option:selected' ).val();
+            saveVal( dataElementId, optionComboId );
+        } );
+
+        $( this ).keyup( function( event )
+        {
+            keyPress( event, this );
+        } );
+    } );
+    
+    $( '[name="dynselect"]' ).each( function( i ) // Custom only
     {
     	$( this ).append( optionMarkup );
     } );
@@ -471,25 +492,26 @@
     {
         var $trTargetChildren = $trTarget.find( 'td:first-child' );
 
-        $trTargetChildren.each(function(idx, item) {
+        $trTargetChildren.each( function( idx, item ) 
+        {
             var text1 = $this.val().toUpperCase();
             var text2 = $(item).find('span').html().toUpperCase();
 
-            if(text2.indexOf(text1) >= 0)
+            if( text2.indexOf( text1 ) >= 0 )
             {
-                $(item).parent().show();
+                $( item ).parent().show();
             }
             else
             {
-                $(item).parent().hide();
+                $( item ).parent().hide();
             }
-        });
+        } );
     }
 
-    refreshZebraStripes($tbody);
+    refreshZebraStripes( $tbody );
 }
 
-function refreshZebraStripes($tbody)
+function refreshZebraStripes( $tbody )
 {
     $tbody.find( 'tr:not([colspan]):visible:even' ).find( 'td:first-child' ).removeClass( 'reg alt' ).addClass('alt' );
     $tbody.find( 'tr:not([colspan]):visible:odd' ).find( 'td:first-child' ).removeClass( 'reg alt' ).addClass('reg' );

=== 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-16 00:11:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2012-09-16 14:44:45 +0000
@@ -369,26 +369,26 @@
 
 /**
  * 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 
- * identifier is:
+ * fields for each category option combo.  The format for select / drop down list
+ * is:
  * 
- * "<unique code>-dyncselect"
+ * id="<unique code>-dynselect" dyncselect="<category combo id>"
  */
 function insertDropDownList() {
 	var oEditor = $("#designTextarea").ckeditorGet();
-	
 	if ( currentDynamicElementCode && currentCategoryComboId ) {
-		var id = currentDynamicElementCode + "-" + currentCategoryComboId + "-dynselect";
-		var template = '<input id="' + id + '" value="[ ' + currentCategoryComboName + ' ]" title="' + currentCategoryComboName + '" style="width:15em;" />';
+		var id = currentDynamicElementCode + "-dynselect";
+		var template = '<input id="' + id + '" dynselect="' + currentCategoryComboId + '" value="[ ' + currentCategoryComboName + ' ]" title="' + currentCategoryComboName + '" style="width:15em;" />';
 		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 input field identifier is:
+ * fields for each category option combo. The format for input field identifier 
+ * is:
  * 
- * "<unique code>-<category option combo id>-dyninput"
+ * id="<unique code>-<category option combo id>-dyninput"
  */
 function insertDynamicElement() {
 	var oEditor = $("#designTextarea").ckeditorGet();