← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20773: Attribute and data element UI. Disabluing value type when option set is selected, and setting val...

 

------------------------------------------------------------
revno: 20773
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-10-19 21:21:51 +0200
message:
  Attribute and data element UI. Disabluing value type when option set is selected, and setting value type to value type of option set.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm


--
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/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-10-15 14:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-10-19 19:21:51 +0000
@@ -706,7 +706,7 @@
 closed_date=Closed date
 active=Active
 type=Type
-value_type=Value Type
+value_type=Value type
 actual=Actual
 target=Target
 percent=Percent

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java	2015-10-15 10:22:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java	2015-10-19 19:21:51 +0000
@@ -123,9 +123,9 @@
         this.domainType = domainType;
     }
 
-    private String valueType;
+    private ValueType valueType;
 
-    public void setValueType( String valueType )
+    public void setValueType( ValueType valueType )
     {
         this.valueType = valueType;
     }
@@ -215,13 +215,15 @@
         OptionSet commentOptionSet = optionService.getOptionSet( selectedCommentOptionSetId );
         LegendSet legendSet = legendService.getLegendSet( selectedLegendSetId );
 
+        valueType = optionSet != null && optionSet.getValueType() != null ? optionSet.getValueType() : valueType;
+        
         dataElement.setName( StringUtils.trimToNull( name ) );
         dataElement.setShortName( StringUtils.trimToNull( shortName ) );
         dataElement.setCode( StringUtils.trimToNull( code ) );
         dataElement.setDescription( StringUtils.trimToNull( description ) );
         dataElement.setFormName( StringUtils.trimToNull( formName ) );
         dataElement.setDomainType( DataElementDomain.valueOf( domainType ) );
-        dataElement.setValueType( ValueType.valueOf( valueType ) );
+        dataElement.setValueType( valueType );
         dataElement.setAggregationType( AggregationType.valueOf( aggregationType ) );
         dataElement.setUrl( url );
         dataElement.setZeroIsSignificant( zeroIsSignificant );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java	2015-10-15 10:22:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java	2015-10-19 19:21:51 +0000
@@ -136,9 +136,9 @@
         this.domainType = domainType;
     }
 
-    private String valueType;
+    private ValueType valueType;
 
-    public void setValueType( String valueType )
+    public void setValueType( ValueType valueType )
     {
         this.valueType = valueType;
     }
@@ -236,13 +236,15 @@
         OptionSet commentOptionSet = optionService.getOptionSet( selectedCommentOptionSetId );
         LegendSet legendSet = legendService.getLegendSet( selectedLegendSetId );
 
+        valueType = optionSet != null && optionSet.getValueType() != null ? optionSet.getValueType() : valueType;
+        
         dataElement.setName( StringUtils.trimToNull( name ) );
         dataElement.setShortName( StringUtils.trimToNull( shortName ) );
         dataElement.setCode( StringUtils.trimToNull( code ) );
         dataElement.setDescription( StringUtils.trimToNull( description ) );
         dataElement.setFormName( StringUtils.trimToNull( formName ) );
         dataElement.setDomainType( DataElementDomain.valueOf( domainType ) );
-        dataElement.setValueType( ValueType.valueOf( valueType ) );
+        dataElement.setValueType( valueType );
         dataElement.setAggregationType( AggregationType.valueOf( aggregationType ) );
         dataElement.setUrl( url );
         dataElement.setZeroIsSignificant( zeroIsSignificant );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2015-09-26 16:08:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2015-10-19 19:21:51 +0000
@@ -28,7 +28,7 @@
 indicator_group=Indicator Group
 indicator_groups=Indicator Groups
 create_new_data_element=Create new data element
-domain_type=Domain Type
+domain_type=Domain type
 create_new_data_element_group=Create new data element group
 group_members=Group members
 available_data_elements=Available data elements

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementForm.vm	2015-10-15 10:22:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementForm.vm	2015-10-19 19:21:51 +0000
@@ -19,17 +19,17 @@
         'rules': getValidationRules("dataElement")
       } );
 
-		#if( $update )
+      #if( $update )
       checkValueIsExist("name", "validateDataElement.action", { id: getFieldValue('id') });
       checkValueIsExist("shortName", "validateDataElement.action", { id: getFieldValue('id') });
       checkValueIsExist("code", "validateDataElement.action", { id: getFieldValue('id') });
-
       updateAggreationOperation(getFieldValue('valueType'));
-		#else
+      dataValueOptionSetChanged();
+      #else
       checkValueIsExist("name", "validateDataElement.action");
       checkValueIsExist("shortName", "validateDataElement.action");
       checkValueIsExist("code", "validateDataElement.action");
-		#end
+      #end
   });
 
   var previousName = '$!encoder.jsEscape( $!dataElement.name, "'" )';
@@ -85,6 +85,17 @@
 		</td>
 	</tr>
 	<tr>
+		<td><label>$i18n.getString( 'option_set_for_data_values' )</label></td>			
+		<td>
+			<select id="selectedOptionSetId" name="selectedOptionSetId" onchange="dataValueOptionSetChanged()">
+				<option value="0">[$i18n.getString('please_select')]</option>
+				#foreach ( $optionSet in $optionSets )
+				<option data-valuetype="$!optionSet.valueType" value="$optionSet.id" #if( $!dataElement.optionSet && $!dataElement.optionSet.id == "$optionSet.id" ) selected #end>$!encoder.htmlEncode( $optionSet.displayName )</option>
+				#end
+			</select>
+		</td>
+    </tr>
+	<tr>
 		<td><label for="valueType">$i18n.getString( "value_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
 			<select id="valueType" name="valueType" onchange="changeValueType( this.value )">
@@ -146,24 +157,13 @@
 			<input type="hidden" id="submitCategoryComboId" name="selectedCategoryComboId"/>
 		</td>
 	</tr>
-	<tr>
-		<td><label>$i18n.getString( 'option_set_for_data_values' )</label></td>			
-		<td>
-			<select id="selectedOptionSetId" name="selectedOptionSetId">
-				<option value="0">[$i18n.getString('please_select')]</option>
-				#foreach ( $optionSet in $optionSets )
-				<option value="$optionSet.id" #if( $!dataElement.optionSet && $!dataElement.optionSet.id == "$optionSet.id" ) selected #end>$!encoder.htmlEncode( $optionSet.displayName )</option>
-				#end
-			</select>
-		</td>
-    </tr>
     <tr>
         <td><label>$i18n.getString( 'option_set_for_comments' )</label></td>            
         <td>
             <select id="selectedCommentOptionSetId" name="selectedCommentOptionSetId">
                 <option value="0">[$i18n.getString('please_select')]</option>
                 #foreach ( $optionSet in $optionSets )
-                <option value="$optionSet.id" #if( $!dataElement.commentOptionSet && $!dataElement.commentOptionSet.id == "$optionSet.id" ) selected #end>$!encoder.htmlEncode( $optionSet.displayName )</option>
+                <option data-valuetype="$optionSet.valueType" value="$optionSet.id" #if( $!dataElement.commentOptionSet && $!dataElement.commentOptionSet.id == "$optionSet.id" ) selected #end>$!encoder.htmlEncode( $optionSet.displayName )</option>
                 #end
             </select>
         </td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js	2015-10-15 10:22:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElement.js	2015-10-19 19:21:51 +0000
@@ -55,6 +55,18 @@
   updateAggreationOperation(value);
 }
 
+function dataValueOptionSetChanged() {
+  var optionSetId = $('#selectedOptionSetId').val();
+  var valueType = $('#selectedOptionSetId').find(':selected').data('valuetype');
+  if ( optionSetId != 0 && valueType ) {
+	  $('#valueType').val(valueType);
+	  $('#valueType').prop('disabled', true);
+  }
+  else {
+	  $('#valueType').prop('disabled', false);
+  }
+}
+
 function updateAggreationOperation( value ) {
   if( isValueTypeText(value) || value == 'DATE' || value == 'TRUE_ONLY' ) {
     hideById("aggregationType");

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java	2015-10-19 14:51:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/AddAttributeAction.java	2015-10-19 19:21:51 +0000
@@ -201,6 +201,8 @@
     {
         OptionSet optionSet = optionService.getOptionSet( optionSetId );
         
+        valueType = optionSet != null && optionSet.getValueType() != null ? optionSet.getValueType() : valueType;
+        
         TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
 
         trackedEntityAttribute.setName( StringUtils.trimToNull( name ) );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java	2015-10-19 14:51:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/trackedentityattribute/UpdateAttributeAction.java	2015-10-19 19:21:51 +0000
@@ -206,6 +206,8 @@
         throws Exception
     {
         OptionSet optionSet = optionService.getOptionSet( optionSetId );
+
+        valueType = optionSet != null && optionSet.getValueType() != null ? optionSet.getValueType() : valueType;
         
         TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute( id );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm	2015-09-03 09:36:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addAttributeForm.vm	2015-10-19 19:21:51 +0000
@@ -79,10 +79,21 @@
 		<td><label for="confidential">$i18n.getString( "confidential" )</label></td>
 		<td>
 			<input type='checkbox' id="confidential" name="confidential" value='true'>
-		</td>		
+		</td>
 		<td></td>				
 	</tr>
 
+	<tr>
+		<td><label for="optionSetId">$i18n.getString( "option_set" )</label></td>
+		<td><select id="optionSetId" name="optionSetId" onchange="optionSetChanged()">
+		    <option value="0">[$i18n.getString('please_select')]</option>
+			#foreach($optionSet in $optionSets)
+				<option data-valuetype="$!optionSet.valueType" value="$optionSet.id">$encoder.htmlEncode($optionSet.name)</option>
+			#end
+			</select>
+		</td>
+	</tr>
+	
     <tr>
       <td><label for="valueType">$i18n.getString( "value_type" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
       <td>
@@ -119,16 +130,6 @@
         </td>
     </tr>
 
-	<tr id="optionSetRow" class="hidden">
-		<td><label for="optionSetId">$i18n.getString( "option_set" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-		<td><select id="optionSetId" name="optionSetId" class="{validate:{required:true}}" disabled>
-				#foreach($optionSet in $optionSets)
-					<option value="$optionSet.id">$encoder.htmlEncode($optionSet.name)</option>
-				#end
-			</select>
-		</td>
-	</tr>
-	
 	<tr id="trackedEntityRow" class="hidden">
 		<td><label for="trackedEntityId">$i18n.getString( "tracked_entity" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td><select id="trackedEntityId" name="trackedEntityId" class="{validate:{required:true}}" disabled>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js	2015-09-03 08:15:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/attribute.js	2015-10-19 19:21:51 +0000
@@ -5,6 +5,7 @@
   });
 
   typeOnChange();
+  optionSetChanged();
 });
 
 // -----------------------------------------------------------------------------
@@ -66,7 +67,6 @@
   typeMap['DATE'] = i18n_date;
   typeMap['PHONE_NUMBER'] = i18n_phone_number;
   typeMap['TRACKER_ASSOCIATE'] = i18n_tracker_associate;
-  typeMap['OPTION_SET'] = i18n_option_set;
   return typeMap;
 }
 
@@ -82,16 +82,10 @@
 function typeOnChange() {
   var type = getFieldValue('valueType');
 
-  hideById("optionSetRow");
-  disable("optionSetId");
   hideById("trackedEntityRow");
   disable("trackedEntityId");
 
-  if( type == "OPTION_SET" ) {
-    showById("optionSetRow");
-    enable("optionSetId");
-  }
-  else if( type == "TRACKER_ASSOCIATE" ) {
+  if( type == "TRACKER_ASSOCIATE" ) {
     showById("trackedEntityRow");
     enable("trackedEntityId");
   }
@@ -104,6 +98,18 @@
   }
 }
 
+function optionSetChanged() {
+  var optionSetId = $('#optionSetId').val();
+  var valueType = $('#optionSetId').find(':selected').data('valuetype');
+  if ( optionSetId != 0 && valueType ) {
+	  $('#valueType').val(valueType);
+	  $('#valueType').prop('disabled', true);
+  }
+  else {
+	  $('#valueType').prop('disabled', false);
+  }
+}
+
 function uniqueOnChange() {
   if( $('#unique').attr('checked') == "checked" ) {
     jQuery('[name=uniqueTR]').show();
@@ -112,7 +118,6 @@
     jQuery('#valueType [value=DATE]').hide();
     jQuery('#valueType [value=TRACKER_ASSOCIATE]').hide();
     jQuery('#valueType [value=USERNAME]').hide();
-    jQuery('#valueType [value=OPTION_SET]').hide();
   }
   else {
     jQuery('[name=uniqueTR]').hide();
@@ -121,6 +126,5 @@
     jQuery('#valueType [value=DATE]').show();
     jQuery('#valueType [value=TRACKER_ASSOCIATE]').show();
     jQuery('#valueType [value=USERNAME]').show();
-    jQuery('#valueType [value=OPTION_SET]').show();
   }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm	2015-09-03 09:36:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateAttibuteForm.vm	2015-10-19 19:21:51 +0000
@@ -79,7 +79,19 @@
 		</td>		
 		<td></td>				
 	</tr>
-      <tr>
+        
+	<tr>
+		<td><label for="optionSetId">$i18n.getString( "option_set" )</label></td>
+		<td><select id="optionSetId" name="optionSetId" onchange="optionSetChanged()">
+		    <option value="0">[$i18n.getString('please_select')]</option>
+			#foreach($optionSet in $optionSets)
+				<option data-valuetype="$!optionSet.valueType" value="$optionSet.id" #if($attribute.optionSet.id==$optionSet.id) selected#end>$encoder.htmlEncode($optionSet.name)</option>
+			#end
+			</select>
+		</td>
+	</tr>
+        
+    <tr>
         <td><label for="valueType">$i18n.getString( "value_type" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
         <td>
           <select id="valueType" name="valueType" onchange="typeOnChange();">
@@ -97,9 +109,9 @@
             <option value="OPTION_SET" #if( $attribute.unique=='true' ) style='display:none' #end #if( $attribute.valueType == 'OPTION_SET' ) selected="selected" #end>$i18n.getString( "option_set" )</option>
           </select>
         </td>
-      </tr>
+    </tr>
 
-      <tr>
+    <tr>
         <td><label for="aggregationType">$i18n.getString( "aggregation_type" )</label></td>
         <td>
             <select id="aggregationType" name="aggregationType">
@@ -114,16 +126,6 @@
         </td>
     </tr>
 
-	<tr id="optionSetRow" #if($attribute.optionSet) #else class="hidden" #end>
-		<td><label for="optionSetId">$i18n.getString( "option_set" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-		<td><select id="optionSetId" name="optionSetId" class="{validate:{required:true}}">
-				#foreach($optionSet in $optionSets)
-					<option value="$optionSet.id" #if($attribute.optionSet.id==$optionSet.id) selected#end>$encoder.htmlEncode($optionSet.name)</option>
-				#end
-			</select>
-		</td>
-	</tr>
-
 	<tr id="trackedEntityRow" #if($attribute.trackedEntity) #else class="hidden" #end>
 			<td><label for="trackedEntityId">$i18n.getString( "tracked_entity" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 			<td><select id="trackedEntityId" name="trackedEntityId" class="{validate:{required:true}}">