← Back to team overview

dhis2-devs team mailing list archive

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

 

------------------------------------------------------------
revno: 8102
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-09-16 02:11:12 +0200
message:
  WIP dynamic fields
modified:
  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/java/org/hisp/dhis/de/action/LoadFormAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm
  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-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-15 22:53:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-09-16 00:11:12 +0000
@@ -168,6 +168,8 @@
 
     public String prepareDataEntryFormForEdit( String htmlCode, I18n i18n )
     {
+        //TODO HTML encode names
+        
         StringBuffer sb = new StringBuffer();
 
         Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode );
@@ -258,6 +260,8 @@
 
     public String prepareDataEntryFormForEntry( String htmlCode, I18n i18n, DataSet dataSet )
     {
+        //TODO HTML encode names
+        
         // ---------------------------------------------------------------------
         // Inline javascript/html to add to HTML before output
         // ---------------------------------------------------------------------
@@ -270,9 +274,6 @@
 
         Map<Integer, DataElement> dataElementMap = getDataElementMap( dataSet );
 
-        Set<DataElement> dataElementsNotInForm = new HashSet<DataElement>( dataSet.getDataElements() );
-        dataElementsNotInForm.removeAll( getDataElementsInDataEntryForm( dataSet ) );
-        
         while ( inputMatcher.find() )
         {
             // -----------------------------------------------------------------
@@ -326,12 +327,14 @@
                 inputHtml = inputHtml.replace( TAG_CLOSE, appendCode );
                 inputHtml += "<span id=\"" + dataElement.getId() + "-dataelement\" style=\"display:none\">" + dataElement.getFormNameFallback() + "</span>";
                 inputHtml += "<span id=\"" + categoryOptionCombo.getId() + "-optioncombo\" style=\"display:none\">" + categoryOptionCombo.getName() + "</span>";
-
-                inputMatcher.appendReplacement( sb, inputHtml );
             }
             else if ( dynamicSelectMatcher.find() && dynamicSelectMatcher.groupCount() > 0 )
             {
+                inputHtml = inputHtml.replace( "<input", "<select name=\"dynselect\"" );
+                inputHtml = inputHtml.replace( TAG_CLOSE, "</select>" );
             }
+
+            inputMatcher.appendReplacement( sb, inputHtml );
         }
 
         inputMatcher.appendTail( sb );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java	2012-08-24 10:09:45 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java	2012-09-16 00:11:12 +0000
@@ -188,6 +188,13 @@
         return greyedFields;
     }
 
+    private List<DataElement> dataElementsNotInForm = new ArrayList<DataElement>();
+
+    public List<DataElement> getDataElementsNotInForm()
+    {
+        return dataElementsNotInForm;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -325,6 +332,10 @@
         {
             customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry( dataEntryForm.getHtmlCode(),
                 i18n, dataSet );
+
+            dataElementsNotInForm = new ArrayList<DataElement>( dataSet.getDataElements() );
+            dataElementsNotInForm.removeAll( dataEntryFormService.getDataElementsInDataEntryForm( dataSet ) );        
+            Collections.sort( dataElementsNotInForm, IdentifiableObjectNameComparator.INSTANCE );
         }
 
         List<DataElement> des = new ArrayList<DataElement>();
@@ -337,5 +348,6 @@
 
             orderedDataElements.put( categoryCombo, des );
         }
+
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties	2012-09-13 14:34:32 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties	2012-09-16 00:11:12 +0000
@@ -101,4 +101,5 @@
 dataelement_with_id=Data element with identifier
 category_option_combo_with_id=Category option combination identifier
 does_not_exist=does not exist
-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
+select_data_element=Select data element
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm	2012-06-04 16:20:41 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/customForm.vm	2012-09-16 00:11:12 +0000
@@ -2,4 +2,11 @@
 #set( $css = "cde cde-${dataEntryForm.style}" )
 <div class="${css}">
 $customDataEntryFormCode
-</div>
\ No newline at end of file
+</div>
+
+<select id="dynselect" class="hidden">
+<option value="">[ $i18n.getString( "select_data_element" ) ]</option>
+#foreach( $element in $dataElementsNotInForm )
+<option value="${element.id}">$encoder.htmlEncode( ${element.displayName} )</option>
+#end
+</select>
\ No newline at end of file

=== 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-15 07:27:54 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2012-09-16 00:11:12 +0000
@@ -308,6 +308,7 @@
 {
     var dataSetId = $( '#selectedDataSetId' ).val();
 	var formType = dataSets[dataSetId].type;
+	var optionMarkup = $( '#dynselect' ).html();
 
     $( '[name="entryfield"]' ).each( function( i )
     {
@@ -374,6 +375,11 @@
 
         $( this ).css( 'width', '100%' );
     } );
+    
+    $( '[name="dynselect"]' ).each( function( i )
+    {
+    	$( this ).append( optionMarkup );
+    } );
 }
 
 function clearPeriod()

=== 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-15 22:53:29 +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 00:11:12 +0000
@@ -379,7 +379,7 @@
 	
 	if ( currentDynamicElementCode && currentCategoryComboId ) {
 		var id = currentDynamicElementCode + "-" + currentCategoryComboId + "-dynselect";
-		var template = '<input id="' + id + '" value="[ ' + currentCategoryComboName + ' ]" title="' + currentCategoryComboName + '" style="width:12em;" />';
+		var template = '<input id="' + id + '" value="[ ' + currentCategoryComboName + ' ]" title="' + currentCategoryComboName + '" style="width:15em;" />';
 		oEditor.insertHtml( template );
 	}
 }