← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21401: aggregate-data-entry: optionsets now use select2

 

------------------------------------------------------------
revno: 21401
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-12-10 12:07:47 +0100
message:
  aggregate-data-entry: optionsets now use select2
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
  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/style/dhis-web-dataentry.css


--
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-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2015-10-12 17:55:30 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2015-12-10 11:07:47 +0000
@@ -15,6 +15,7 @@
     <link type="text/css" rel="stylesheet" media="print" href="../dhis-web-commons/css/print.css?_rev=$!{buildRevision}" />
     <link type="text/css" rel="stylesheet" media="screen" href="../dhis-web-commons/css/menu.css?_rev=$!{buildRevision}" />
     <link type="text/css" rel="stylesheet" media="screen" href="../dhis-web-commons/javascripts/jQuery/calendars/css/jquery.calendars.picker.css?_rev=$!{buildRevision}" />
+	<link type="text/css" rel="stylesheet" media="screen" href="../dhis-web-commons/select2/select2.css?_rev=$!{buildRevision}" />
     #foreach ( $style in $stylesheets )
     <link type="text/css" rel="stylesheet" href="${style}?_rev=$!{buildRevision}">
     #end
@@ -62,6 +63,7 @@
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.select.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.min.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.plus.min.js?_rev=$!{buildRevision}"></script>
+	<script type="text/javascript" src="../dhis-web-commons/select2/select2.min.js?_rev=$!{buildRevision}"></script>
     #if( $keyCalendar == "coptic" || $keyCalendar == "ethiopian" || $keyCalendar == "islamic"  || $keyCalendar == "julian" || $keyCalendar == "nepali" || $keyCalendar == "thai" )
     <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.${keyCalendar}.min.js?_rev=$!{buildRevision}"></script>
     #end

=== 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	2015-12-08 13:14:21 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2015-12-10 11:07:47 +0000
@@ -563,14 +563,7 @@
         var split = dhis2.de.splitFieldId( id );
 
         var dataElementId = split.dataElementId;
-        var optionComboId = split.optionComboId;
-
-        /*$( this ).unbind( 'focus' );
-        $( this ).unbind( 'change' );
-
-        $( this ).focus( valueFocus );
-
-        $( this ).blur( valueBlur );*/
+        var optionComboId = split.optionComboId;       
 
         $( this ).change( function()
         {
@@ -605,13 +598,7 @@
 
         var dataElementId = split.dataElementId;
         var optionComboId = split.optionComboId;
-
-        $( this ).unbind( 'focus' );
-        $( this ).unbind( 'change' );
-
-        $( this ).focus( valueFocus );
-        $( this ).blur( valueBlur );
-
+        
         $( this ).change( function()
         {
             saveVal( dataElementId, optionComboId, id );
@@ -1555,13 +1542,11 @@
     $( '.entryfield' ).val( '' );
     $( '.entryselect' ).removeAttr( 'checked' );
     $( '.entrytrueonly' ).removeAttr( 'checked' );
-    $( '.entryoptionset' ).val( '' );
 
     $( '.entryfield' ).css( 'background-color', dhis2.de.cst.colorWhite ).css( 'border', '1px solid ' + dhis2.de.cst.colorBorder );
     $( '.entryselect' ).css( 'background-color', dhis2.de.cst.colorWhite ).css( 'border', '1px solid ' + dhis2.de.cst.colorBorder );
     $( '.indicator' ).css( 'background-color', dhis2.de.cst.colorWhite ).css( 'border', '1px solid ' + dhis2.de.cst.colorBorder );
     $( '.entrytrueonly' ).css( 'background-color', dhis2.de.cst.colorWhite );
-    $( '.entryoptionset' ).css( 'background-color', dhis2.de.cst.colorWhite );
 
     clearFileEntryFields();
 
@@ -1646,14 +1631,12 @@
 	if ( json.locked )
 	{
         $( '#contentDiv input').attr( 'readonly', 'readonly' );
-        $( '.entryoptionset').autocomplete( 'disable' );
         $( '.sectionFilter').removeAttr( 'disabled' );
         $( '#completenessDiv' ).hide();
 		setHeaderDelayMessage( i18n_dataset_is_locked );
 	}
 	else
 	{
-        $( '.entryoptionset' ).autocomplete( 'enable' );
         $( '#contentDiv input' ).removeAttr( 'readonly' );
 		$( '#completenessDiv' ).show();
 	}
@@ -2913,7 +2896,9 @@
 		if ( obj && obj.optionSet && obj.optionSet.options ) {			
 			$.each( obj.optionSet.options, function( inx, option ) {
 				if ( option && option.code == value.val ) {
-					$( fieldId ).val( option.name );
+                                        option.id = option.code;
+                                        option.text = option.name;					
+                                        $( fieldId ).select2("val", option.text );
 					return false;
 				}
 			} );
@@ -3050,18 +3035,40 @@
 {
     $( '.entryoptionset').each( function( idx, item ) {
     	var optionSetKey = dhis2.de.splitFieldId( item.id );
-
+        var s2prefix = 's2id_';        
+        optionSetKey.dataElementId = optionSetKey.dataElementId.indexOf(s2prefix) != -1 ? optionSetKey.dataElementId.substring(s2prefix.length, optionSetKey.dataElementId.length) : optionSetKey.dataElementId;
+        
         if ( dhis2.de.multiOrganisationUnit ) {
         	item = optionSetKey.organisationUnitId + '-' + optionSetKey.dataElementId + '-' + optionSetKey.optionComboId;
         } 
         else {
         	item = optionSetKey.dataElementId + '-' + optionSetKey.optionComboId;
         }
-
+        
         item = item + '-val';
         optionSetKey = optionSetKey.dataElementId + '-' + optionSetKey.optionComboId;
         var optionSetUid = dhis2.de.optionSets[optionSetKey].uid;
-        dhis2.de.autocompleteOptionSetField( item, optionSetUid );
+        //dhis2.de.autocompleteOptionSetField( item, optionSetUid );
+        
+        DAO.store.get( 'optionSets', optionSetUid ).done( function( obj ) {		
+		if ( obj && obj.optionSet && obj.optionSet.options ) {
+                    
+                    $.each( obj.optionSet.options, function( inx, option ) {
+                        option.text = option.name;
+                        option.id = option.code;
+                    } );
+                    
+                    $("#" + item).select2({
+                        placeholder: i18n_select_option ,
+                        allowClear: true,
+                        dataType: 'json',
+                        data: obj.optionSet.options
+                    }).on("select2:unselecting", function (e) {
+                        $(this).select2("val", "");
+                        e.preventDefault();
+                    });
+		}		
+	} );        
     } );
 };
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css	2015-10-19 23:11:55 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css	2015-12-10 11:07:47 +0000
@@ -140,6 +140,11 @@
   border: 1px solid #aaa;
 }
 
+.entryoptionset {
+    width: 85%;
+    max-height: 400px;
+}
+
 .entryselect
 {
   padding: 4px 1px;
@@ -400,4 +405,17 @@
     display: inline-block;
     position: absolute;
     top: 16px;
+}
+
+.select2-container .select2-choice {
+    border-radius: 0;
+}
+
+
+.select2-container .select2-choice .select2-arrow {
+    border-radius: 0;
+}
+
+.select2-chosen {
+    padding-top: 6px;
 }
\ No newline at end of file