← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16582: Data entry, option sets, using option set name as label and option set code as value to save

 

------------------------------------------------------------
revno: 16582
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-08-29 17:50:39 +0200
message:
  Data entry, option sets, using option set name as label and option set code as value to save
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.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-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	2014-08-29 14:07:04 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-08-29 15:50:39 +0000
@@ -1381,13 +1381,13 @@
 	    success: function( json ) // online
 	    {
 	    	insertDataValues( json );
-      },
-      complete: function()
-      {
-        $( '.indicator' ).attr( 'readonly', 'readonly' );
-        $( '.dataelementtotal' ).attr( 'readonly', 'readonly' );
-        $( document ).trigger( dhis2.de.event.dataValuesLoaded );
-      }
+        },
+        complete: function()
+        {
+            $( '.indicator' ).attr( 'readonly', 'readonly' );
+            $( '.dataelementtotal' ).attr( 'readonly', 'readonly' );
+            $( document ).trigger( dhis2.de.event.dataValuesLoaded );
+        }
 	} );
 }
 
@@ -1448,7 +1448,11 @@
             if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' && 'true' == value.val ) 
             {
                 $( fieldId ).attr( 'checked', true );
-            } 
+            }
+            else if ( $( fieldId ).attr( 'name' ) == 'entryoptionset' )
+            {
+            	dhis2.de.setOptionNameInField( fieldId, value );            	
+            }
             else 
             {
                 $( fieldId ).val( value.val );
@@ -2543,6 +2547,30 @@
 // -----------------------------------------------------------------------------
 
 /**
+ * Inserts the name of the option set in the input field with the given identifier.
+ * The option set input fields should use the name as label and code as value to
+ * be saved.
+ * 
+ * @fieldId the identifier of the field on the form #deuid-cocuid-val.
+ * @value the value with properties id (deuid-cocuid) and val (option name).
+ */
+dhis2.de.setOptionNameInField = function( fieldId, value )
+{
+	var optionSetUid = dhis2.de.optionSets[value.id].uid;
+	
+	DAO.store.get( 'optionSets', optionSetUid ).done( function( obj ) {		
+		if ( obj && obj.optionSet && obj.optionSet.options ) {			
+			$.each( obj.optionSet.options, function( inx, option ) {
+				if ( option && option.code == value.val ) {
+					$( fieldId ).val( option.name );
+					return false;
+				}
+			} );
+		}		
+	} );
+};
+
+/**
  * Performs a search for options for the option set with the given identifier based
  * on the given query. If query is null, the first MAX options for the option set
  * is used. Checks and uses option set from local store, if not fetches option
@@ -2699,7 +2727,7 @@
             dhis2.de.searchOptionSet( optionSetUid, input.val(), response );
         },
         select: function ( event, ui ) {
-            input.val( ui.item.value );
+            input.val( ui.item.id );
             input.autocomplete( 'close' );
             input.change();
         },