← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 351: Added auto suggestion to Custom Value dataset option. While typing more than 2 chars in new Custo...

 

------------------------------------------------------------
revno: 351
committer: Miri <murodlatifov@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-06-02 16:50:10 +0200
message:
  Added auto suggestion to Custom Value dataset option. While typing more than 2 chars in new CustomValue field list of suggestions will appear, user can select one from the list and press Add.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/DefaultCustomValueService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/hibernate/HibernateCustomValueStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/GetCustomValuesAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editCustomValues.vm

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueService.java	2009-05-04 12:51:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueService.java	2009-06-02 14:50:10 +0000
@@ -60,28 +60,28 @@
     /**
      * Get all CustomValues by DataSet.
      * 
-     * @return A collection containing all CustomValues.
+     * @return A collection containing all CustomValues within given dataset.
      */
     Collection<CustomValue> getCustomValuesByDataSet( DataSet dataSet );
 
     /**
      * Get all CustomValues by DataElement.
      * 
-     * @return A collection containing all CustomValues.
+     * @return A collection containing all CustomValues within given dataelement.
      */
     Collection<CustomValue> getCustomValuesByDataElement( DataElement dataElement );
 
     /**
      * Get all CustomValues by DataElementCategoryCombo.
      * 
-     * @return A collection containing all CustomValues.
+     * @return A collection containing all CustomValues within given categorycombo.
      */
     Collection<CustomValue> getCustomValuesByCategoryCombo( DataElementCategoryCombo categoryCombo );
 
     /**
      * Get all CustomValues by DataSet, DataElement, DataElementCategoryCombo.
      * 
-     * @return A collection containing all CustomValues.
+     * @return A collection containing all CustomValues in a given criteria.
      */
     Collection<CustomValue> getCustomValues( DataSet dataSet, DataElement dataElement,
         DataElementCategoryOptionCombo dataElementCategoryOptionCombo );
@@ -92,4 +92,12 @@
      * @return CustomValue object.
      */
     CustomValue getCustomValuesById( Integer id );
+    
+    /**
+     * Get CustomValue by value.
+     * 
+     * @return A collection containing found CustomValues.
+     */
+    Collection<CustomValue> findCustomValues( String searchValue );
+    
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueStore.java	2009-05-04 12:51:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValueStore.java	2009-06-02 14:50:10 +0000
@@ -92,4 +92,12 @@
      * @return CustomValue object.
      */
     CustomValue getCustomValuesById( Integer id );
+    
+    /**
+     * Get CustomValue by value.
+     * 
+     * @return A collection containing found CustomValues.
+     */
+    Collection<CustomValue> findCustomValues( String searchValue );
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/DefaultCustomValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/DefaultCustomValueService.java	2009-05-11 13:32:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/DefaultCustomValueService.java	2009-06-02 14:50:10 +0000
@@ -99,4 +99,9 @@
     {
         return customValueStore.getCustomValues( dataSet, dataElement, dataElementCategoryOptionCombo );
     }
+
+	public Collection<CustomValue> findCustomValues(String searchValue) 
+	{
+		return customValueStore.findCustomValues( searchValue );
+	}
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/hibernate/HibernateCustomValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/hibernate/HibernateCustomValueStore.java	2009-05-11 13:32:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/customvalue/hibernate/HibernateCustomValueStore.java	2009-06-02 14:50:10 +0000
@@ -31,6 +31,8 @@
 
 import org.hibernate.Criteria;
 import org.hibernate.Session;
+import org.hibernate.criterion.MatchMode;
+import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.customvalue.CustomValue;
 import org.hisp.dhis.customvalue.CustomValueStore;
@@ -132,4 +134,16 @@
 
         return criteria.list();
     }
+
+	@SuppressWarnings("unchecked")
+	public Collection<CustomValue> findCustomValues(String searchValue) 
+	{
+        Session session = sessionManager.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( CustomValue.class );
+//        criteria.setProjection(Projections.distinct(Projections.property("customValue")));
+        criteria.add( Restrictions.like( "customValue", searchValue, MatchMode.ANYWHERE ) );
+
+        return criteria.list();
+	}
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/GetCustomValuesAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/GetCustomValuesAction.java	2009-05-04 12:51:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/GetCustomValuesAction.java	2009-06-02 14:50:10 +0000
@@ -204,10 +204,17 @@
             customValue = customValueService.getCustomValuesById( customValueId );
             customValueService.deleteCustomValue( customValue );
         }
-
-        List<CustomValue> customValues = new ArrayList<CustomValue>( customValueService.getCustomValues( dataSet,
-            dataElement, dataElementCategoryOptionCombo ) );
-
+        List<CustomValue> customValues = null;
+        
+        if ( operation.equalsIgnoreCase( "find" ) )
+        {
+            customValues = new ArrayList<CustomValue>( customValueService.findCustomValues( value ) );
+        }else
+        {
+	        customValues = new ArrayList<CustomValue>( customValueService.getCustomValues( dataSet,
+	            dataElement, dataElementCategoryOptionCombo ) );
+        }
+        
         Iterator<CustomValue> customValueIterator = customValues.iterator();
 
         while ( customValueIterator.hasNext() )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editCustomValues.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editCustomValues.vm	2009-05-20 14:35:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/editCustomValues.vm	2009-06-02 14:50:10 +0000
@@ -661,6 +661,9 @@
   }
   
   var messageContainer = document.getElementById('message');
+  
+  //here add if single value dissable and make the only element selected
+  
   if( (custom_ValueList.length ==1 &&  custom_ValueList[0]=="NULL") || (custom_ValueList.length ==0) )
   {
     messageContainer.innerHTML = "$i18n.getString( "no_more_categories_to_select" )";   
@@ -716,6 +719,83 @@
 }
 
 
+//get suggestions for custom value
+function getSuggestedCustomValuesCompleted( customValueElement )
+{
+  var custom_Values = customValueElement.getElementsByTagName( 'customValues' )[0];
+  var custom_ValueList = customValueElement.getElementsByTagName( 'customValue' );
+
+  var availableCustomValue = document.getElementById( 'availableCustomValue' );
+  
+  for ( var i = 0; i < custom_ValueList.length; i++ )
+  {
+    var custom_ValueOption = custom_ValueList[i];
+    var name = custom_ValueOption.firstChild.nodeValue;
+    var id = custom_ValueOption.getAttribute( 'id' );   
+        
+    var option = new Option( name, name );
+        
+    availableCustomValue.add( option, null );
+  }
+  
+  var messageContainer = document.getElementById('message');
+  
+  //here add if single value dissable and make the only element selected
+  
+  if( (custom_ValueList.length ==1 &&  custom_ValueList[0]=="NULL") || (custom_ValueList.length ==0) )
+  {
+    messageContainer.innerHTML = " ";   
+  }
+  else
+  {
+    messageContainer.innerHTML = " ";   
+  }
+}
+
+// -----------------------------------------------------------------------------
+// Get Suggested CustomValues for typed chars
+// -----------------------------------------------------------------------------
+function getSuggestedCustomValues(operation)
+{
+  var request = new Request();
+  request.setResponseTypeXML( 'customValue' );
+  request.setCallbackSuccess( getSuggestedCustomValuesCompleted );
+  
+  var dataElementSelector = document.getElementById( 'dataElementSelector' );
+  var dataElementId = dataElementSelector.options[dataElementSelector.selectedIndex].value;
+  
+  var optionComboSelector = document.getElementById( 'optionComboSelector' );
+  var categoryoptioncomboid = optionComboSelector.options[optionComboSelector.selectedIndex].value;
+
+  if(operation=='delete')
+  {
+  var customValueSelector = document.getElementById( 'customValueSelector' );
+  var customValueId = customValueSelector.options[customValueSelector.selectedIndex].value;
+  }
+  
+  // Clear the suggestedcustomValue list
+  var availableCustomValueList = document.getElementById( 'availableCustomValue' );
+  availableCustomValueList.options.length = 0;
+
+  var requestString = 'getCustomValues.action';
+  
+  var params = 'dataElementId=' + dataElementId;
+  var params = params + '&categoryOptionComboId='+categoryoptioncomboid;  
+  var params = params + '&dataSetId='+ document.getElementById( 'dataSetIdField' ).value;
+  var params = params + '&operation='+operation;
+  var params = params + '&value='+ document.getElementById( 'newCustomValue' ).value;
+  
+  if(operation=='delete')
+  {
+  var params = params + '&customValueId='+customValueId;
+  }
+  
+  request.sendAsPost( params );
+  request.send( requestString );
+
+  return false;
+}
+
 function addNew()
 {
 
@@ -756,28 +836,50 @@
 }
 
 function remove()
-{
-
-if (document.getElementById( 'dataElementSelector' )==-1) 
-{
-alert("\nYou must make a selection from the DataElement panel first.");
-}
-else
-if (document.getElementById( 'optionComboSelector' ).selectedIndex==-1) 
-{
-alert("\nYou must make a selection from the ComboOptions panel first.");
-}
-else
-if (document.getElementById( 'customValueSelector' ).selectedIndex==-1) 
-{
-alert("\nYou must make a selection from the CustomValues panel first.");
-}
-else
-    {
-      getCustomValues('delete');
+    {
+    
+    if (document.getElementById( 'dataElementSelector' )==-1) 
+    {
+    alert("\nYou must make a selection from the DataElement panel first.");
+    }
+    else
+    if (document.getElementById( 'optionComboSelector' ).selectedIndex==-1) 
+    {
+    alert("\nYou must make a selection from the ComboOptions panel first.");
+    }
+    else
+    if (document.getElementById( 'customValueSelector' ).selectedIndex==-1) 
+    {
+    alert("\nYou must make a selection from the CustomValues panel first.");
+    }
+    else
+        {
+          getCustomValues('delete');
     } 
 }
 
+function findSimilar()
+	{
+	
+	if(document.getElementById( 'newCustomValue' ).value.length>1)
+	{
+	getSuggestedCustomValues('find');
+	}
+	else
+	{
+	  // Clear the suggestedcustomValue list
+  var availableCustomValueList = document.getElementById( 'availableCustomValue' );
+  availableCustomValueList.options.length = 0;
+	}
+	}
+	
+function setSuggestedCustomValue()
+	{
+	var availableCustomValue = document.getElementById( 'availableCustomValue' );
+    var availableCustomValueSelected = availableCustomValue.options[availableCustomValue.selectedIndex].value;
+  
+	document.getElementById( 'newCustomValue' ).value = availableCustomValueSelected;
+	}
 </script>
 
 <style type="text/css">
@@ -817,7 +919,7 @@
             </td>
         </tr>                       
         <tr>
-            <td><input type="text" name="newCustomValue" id="newCustomValue" maxlength="160" style="min-width:25em" size="60"/>&nbsp;&nbsp;
+            <td><input type="text" name="newCustomValue" id="newCustomValue" onkeydown="findSimilar()" maxlength="160" style="min-width:25em" size="60"/>&nbsp;&nbsp;
             </td>
             <td>
                 <button type="button" onclick="addNew()">$i18n.getString( "add_new_custom_value" )</button>&nbsp;&nbsp;
@@ -838,7 +940,7 @@
     <tbody>
         <tr>  
             <td>
-                <select name="availableCustomValue" id="availableCustomValue" style="min-width:25em" size="10">
+                <select name="availableCustomValue" id="availableCustomValue" onchange="setSuggestedCustomValue()" style="min-width:25em" size="10">
                 </select>
             </td>                  
             <td>



--
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.