← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9933: Add shortName and code fields into Add/Update data-element-group form.

 

------------------------------------------------------------
revno: 9933
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-01 11:09:26 +0700
message:
  Add shortName and code fields into Add/Update data-element-group form.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroup.hbm.xml
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroup.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AddDataElementGroupAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/ValidateDataElementGroupAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementGroupForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementGroupForm.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-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2013-02-26 20:18:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2013-03-01 04:09:26 +0000
@@ -372,7 +372,25 @@
      *         no DataElementGroups exist.
      */
     Collection<DataElementGroup> getAllDataElementGroups();
+    
+    
+    /**
+     * Returns a DataElementGroup with a given shortName.
+     *
+     * @param shortName the shortName of the DataElementGroup to return.
+     * @return the DataElementGroup with the given shortName, or null if no match.
+     */
+    DataElementGroup getDataElementGroupByShortName( String shortName );
+    
+    /**
+     * Returns a DataElementGroup with a given code.
+     *
+     * @param code the shortName of the DataElementGroup to return.
+     * @return the DataElementGroup with the given code, or null if no match.
+     */
+    DataElementGroup getDataElementGroupByCode( String code );
 
+    
     /**
      * Returns all DataElementGroups which contain the given DataElement.
      *

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2013-02-26 20:18:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2013-03-01 04:09:26 +0000
@@ -28,6 +28,7 @@
  */
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.common.GenericNameableObjectStore;
 import org.hisp.dhis.dataelement.comparator.DataElementCategoryComboSizeComparator;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.i18n.I18nService;
@@ -66,9 +67,9 @@
         this.dataElementStore = dataElementStore;
     }
 
-    private GenericIdentifiableObjectStore<DataElementGroup> dataElementGroupStore;
+    private GenericNameableObjectStore<DataElementGroup> dataElementGroupStore;
 
-    public void setDataElementGroupStore( GenericIdentifiableObjectStore<DataElementGroup> dataElementGroupStore )
+    public void setDataElementGroupStore( GenericNameableObjectStore<DataElementGroup> dataElementGroupStore )
     {
         this.dataElementGroupStore = dataElementGroupStore;
     }
@@ -430,14 +431,32 @@
 
     public DataElementGroup getDataElementGroupByName( String name )
     {
-        List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>( dataElementGroupStore.getAllEqName( name ) );
-
-        if ( dataElementGroups.isEmpty() )
-        {
-            return null;
-        }
-
-        return i18n( i18nService, dataElementGroups.get( 0 ) );
+        List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>(
+            dataElementGroupStore.getAllEqName( name ) );
+
+        if ( dataElementGroups.isEmpty() )
+        {
+            return null;
+        }
+
+        return i18n( i18nService, dataElementGroups.get( 0 ) );
+    }
+
+    public DataElementGroup getDataElementGroupByShortName( String shortName )
+    {
+        List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>( dataElementGroupStore.getAllEqShortName( shortName ) );
+
+        if ( dataElementGroups.isEmpty() )
+        {
+            return null;
+        }
+
+        return i18n( i18nService, dataElementGroups.get( 0 ) );
+    }
+
+    public DataElementGroup getDataElementGroupByCode( String code )
+    {
+        return i18n( i18nService, dataElementGroupStore.getByCode( code ) );
     }
 
     public Collection<DataElementGroup> getGroupsContainingDataElement( DataElement dataElement )
@@ -525,7 +544,8 @@
 
     public DataElementGroupSet getDataElementGroupSetByName( String name )
     {
-        List<DataElementGroupSet> dataElementGroupSets = new ArrayList<DataElementGroupSet>( dataElementGroupSetStore.getAllEqName( name ) );
+        List<DataElementGroupSet> dataElementGroupSets = new ArrayList<DataElementGroupSet>(
+            dataElementGroupSetStore.getAllEqName( name ) );
 
         if ( dataElementGroupSets.isEmpty() )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroup.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroup.hbm.xml	2013-02-07 10:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementGroup.hbm.xml	2013-03-01 04:09:26 +0000
@@ -17,6 +17,8 @@
 
     <property name="name" column="name" not-null="true" unique="true" length="230" />
 
+	<property name="shortName" column="shortname" unique="true" length="50" />
+
     <set name="members" table="dataelementgroupmembers">
       <cache usage="read-write" />
       <key column="dataelementgroupid" foreign-key="fk_dataelementgroupmembers_dataelementgroupid" />

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroup.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroup.vm	2012-01-22 11:28:12 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroup.vm	2013-03-01 04:09:26 +0000
@@ -2,6 +2,8 @@
   {
     "id": $!{dataElementGroup.id},
     "name": "$!encoder.jsonEncode( ${dataElementGroup.displayName} )",
+	"shortName": "$!encoder.jsonEncode( ${dataElementGroup.displayShortName} )",
+	"code": "$!encoder.jsonEncode( ${dataElementGroup.code} )",
     "memberCount": "$memberCount"
   } 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js	2012-12-07 14:32:11 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js	2013-03-01 04:09:26 +0000
@@ -265,7 +265,13 @@
             "alphanumericwithbasicpuncspaces" : true,
             "notOnlyDigits" : true,
             "rangelength" : [ 2, 160 ]
-        }
+        },
+        "shortName" : {
+            "required" : true,
+            "rangelength" : [ 2, 40 ],
+            "alphanumericwithbasicpuncspaces" : true,
+            "notOnlyDigits" : true
+        },
     },
     "dataElementGroupSet" : {
         "name" : {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AddDataElementGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AddDataElementGroupAction.java	2012-06-01 11:35:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AddDataElementGroupAction.java	2013-03-01 04:09:26 +0000
@@ -75,6 +75,20 @@
         this.name = name;
     }
 
+    private String shortName;
+
+    public void setShortName( String shortName )
+    {
+        this.shortName = shortName;
+    }
+
+    private String code;
+
+    public void setCode( String code )
+    {
+        this.code = code;
+    }
+
     private Set<String> groupMembers = new HashSet<String>();
 
     public void setGroupMembers( Set<String> groupMembers )
@@ -106,8 +120,12 @@
 
     public String execute()
     {
+        code = ( code != null && code.trim().length() == 0 ) ? null : code;
+        
         dataElementGroup = new DataElementGroup( name );
-
+        dataElementGroup.setShortName( shortName );
+        dataElementGroup.setCode( code );
+        
         for ( String id : groupMembers )
         {
             dataElementGroup.addDataElement( dataElementService.getDataElement( Integer.parseInt( id ) ) );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java	2012-06-01 11:35:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/UpdateDataElementGroupAction.java	2013-03-01 04:09:26 +0000
@@ -83,6 +83,20 @@
         this.name = name;
     }
 
+    private String shortName;
+
+    public void setShortName( String shortName )
+    {
+        this.shortName = shortName;
+    }
+
+    private String code;
+
+    public void setCode( String code )
+    {
+        this.code = code;
+    }
+
     private Set<String> groupMembers = new HashSet<String>();
 
     public void setGroupMembers( Set<String> groupMembers )
@@ -114,8 +128,12 @@
 
     public String execute()
     {
+        code = ( code != null && code.trim().length() == 0 ) ? null : code;
+        
         dataElementGroup = dataElementService.getDataElementGroup( id );
-
+        dataElementGroup.setShortName( shortName );
+        dataElementGroup.setCode( code );
+        
         if ( name != null && name.trim().length() > 0 )
         {
             dataElementGroup.setName( name );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/ValidateDataElementGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/ValidateDataElementGroupAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/ValidateDataElementGroupAction.java	2013-03-01 04:09:26 +0000
@@ -77,6 +77,20 @@
         this.name = name;
     }
 
+    private String shortName;
+
+    public void setShortName( String shortName )
+    {
+        this.shortName = shortName;
+    }
+
+    private String code;
+
+    public void setCode( String code )
+    {
+        this.code = code;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -106,6 +120,33 @@
                 return ERROR;
             }
         }
+        if ( shortName != null )
+        {
+            DataElementGroup match = dataElementService.getDataElementGroupByShortName( shortName );
+
+            if ( match != null && (id == null || match.getId() != id) )
+            {
+                message = i18n.getString( "short_name_in_use" );
+
+                return ERROR;
+            }
+        }
+
+        if ( code != null && !code.trim().isEmpty() )
+        {
+            DataElementGroup match = dataElementService.getDataElementGroupByCode( code );
+
+            if ( match != null && (id == null || match.getId() != id) )
+            {
+                message = i18n.getString( "code_in_use" );
+
+                return ERROR;
+            }
+        }
+        
+        // ---------------------------------------------------------------------
+        // Validation success
+        // ---------------------------------------------------------------------
 
         message = i18n.getString( "everything_is_ok" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementGroupForm.vm	2012-10-17 11:58:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementGroupForm.vm	2013-03-01 04:09:26 +0000
@@ -11,7 +11,9 @@
         });
 
         checkValueIsExist("name", "validateDataElementGroup.action");
-
+		checkValueIsExist( "shortName", "validateDataElementGroup.action" );
+	    checkValueIsExist( "code", "validateDataElementGroup.action" );
+		
 		jQuery("#availableDataElementsList").dhisAjaxSelect({
 			source: "../dhis-web-commons-ajax-json/getDataElements.action",
 			iterator: "dataElements",
@@ -40,6 +42,14 @@
 		<td style="width: 120px;"><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
         <td><input type="text" id="name" name="name" /></td>
     </tr>
+	<tr>
+		<td><label for="shortName">$i18n.getString( "short_name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+		<td><input type="text" id="shortName" name="shortName" /></td>
+	</tr>
+	<tr>
+		<td><label for="code">$i18n.getString( "code" )</label></td>
+		<td><input type="text" id="code" name="code" /></td>
+	</tr>
 </table>
 
 #tblDynamicAttributes( { "attributes": $attributes } )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm	2013-02-22 04:05:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm	2013-03-01 04:09:26 +0000
@@ -80,6 +80,8 @@
 					<a href="javascript:hideDetails()" title="$i18n.getString( 'hide_details' )"><img src="../images/hide.png" alt="$i18n.getString( 'hide_details' )"/></a>
 				</div>
 				<p><label>$i18n.getString( "name" ):</label><br/><span id="nameField"></span></p>
+				<p><label>$i18n.getString( "short_name" ):</label><br/><span id="shortNameField"></span></p>
+				<p><label>$i18n.getString( "code" ):</label><br/><span id="codeField"></span></p>
 				<p><label>$i18n.getString( "number_of_members" ):</label><br/><span id="memberCountField"></span></p>
 			</div>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js	2011-09-27 07:36:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js	2013-03-01 04:09:26 +0000
@@ -20,6 +20,8 @@
 		{ id: dataElementGroupId }, function ( json ) {		
 	
 		setInnerHTML( 'nameField', json.dataElementGroup.name );
+		setInnerHTML( 'shortNameField', json.dataElementGroup.shortName );
+		setInnerHTML( 'codeField', json.dataElementGroup.code );
 		setInnerHTML( 'memberCountField', json.dataElementGroup.memberCount );
 
 		showDetails();

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementGroupForm.vm	2012-10-17 11:58:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementGroupForm.vm	2013-03-01 04:09:26 +0000
@@ -14,6 +14,14 @@
         checkValueIsExist( "name", "validateDataElementGroup.action", {
             id : getFieldValue( 'id' )
         } );
+		
+		checkValueIsExist( "shortName", "validateDataElementGroup.action", {
+            id : getFieldValue( 'id' )
+        } );
+		
+		checkValueIsExist( "code", "validateDataElementGroup.action", {
+            id : getFieldValue( 'id' )
+        } );
 
 		jQuery("#availableDataElementsList").dhisAjaxSelect({
 			source: "../dhis-web-commons-ajax-json/getDataElements.action",
@@ -45,9 +53,17 @@
 
 	<tr>
 		<td style="width: 120px;"><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-		<td><input type="text" id="name" name="name" value="$encoder.htmlEncode( $dataElementGroup.name )">
+		<td><input type="text" id="name" name="name" value="$encoder.htmlEncode( $!dataElementGroup.name )">
 		</td>
 	</tr>
+	<tr>
+		<td><label for="shortName">$i18n.getString( "short_name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+		<td><input type="text" id="shortName" name="shortName" value="$!encoder.htmlEncode( $dataElementGroup.shortName )"></td>
+	</tr>
+	<tr>
+		<td><label for="code">$i18n.getString( "code" )</label></td>
+		<td><input type="text" id="code" name="code" value="$!encoder.htmlEncode( $dataElementGroup.code )"></td>
+	</tr>
 </table>
 
 #tblDynamicAttributes( { "attributes": $attributes, "attributeValues": $attributeValues } )