← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 960: Used a validation for checking the DataElementCategoryOption's name which has been existed/contai...

 

------------------------------------------------------------
revno: 960
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-11-03 15:29:16 +0700
message:
  Used a validation for checking the DataElementCategoryOption's name which has been existed/contained in an another DataElementCategory object
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.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.
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java	2009-11-03 08:29:16 +0000
@@ -0,0 +1,107 @@
+package org.hisp.dhis.dd.action.category;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.i18n.I18n;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Abyot Asalefew
+ * @version $Id$
+ */
+public class ValidateDataElementCategoryOptionAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DataElementCategoryService dataElementCategoryService;
+
+    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+    {
+        this.dataElementCategoryService = dataElementCategoryService;
+    }
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private String name;
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        if ( (name == null) || (name.trim().equals( "" )) )
+        {
+            message = i18n.getString( "specify_name" );
+
+            return INPUT;
+        }
+        else
+        {
+            if (dataElementCategoryService.getDataElementCategoryOptionByName( name ) != null)
+            {
+                message = i18n.getString( "name_in_use" );
+                
+                return INPUT;
+            }
+        }
+        message = "ok";
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml	2009-10-30 07:06:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml	2009-11-03 08:29:16 +0000
@@ -18,6 +18,9 @@
 		<property name="dataDictionaryService">
 			<ref bean="org.hisp.dhis.datadictionary.DataDictionaryService" />
 		</property>
+		<property name="translationUserSettingSupport">
+		  <ref bean="translationUserSettingSupport"/>
+		</property>
 	</bean>
 
 	<bean
@@ -839,4 +842,15 @@
 
 	<bean id="org.hisp.dhis.dd.action.NoAction" class="org.hisp.dhis.dd.action.NoAction" />
 
+	
+	<!-- Validate CategoryOption -->
+	
+	<bean id="org.hisp.dhis.dd.action.category.ValidateDataElementCategoryOptionAction" 
+		class="org.hisp.dhis.dd.action.category.ValidateDataElementCategoryOptionAction"
+		scope="prototype">
+		<property name="dataElementCategoryService">
+			<ref bean="org.hisp.dhis.dataelement.DataElementCategoryService" />
+		</property>
+	</bean>
+	
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2009-11-02 18:13:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2009-11-03 08:29:16 +0000
@@ -991,7 +991,17 @@
 				<param name="bufferSize">10240</param>
 			</result>
 		</action>
-
+		
+		<!-- Validate CategoryOption -->
+		
+		<action name="validateDataElementCategoryOption"
+			class="org.hisp.dhis.dd.action.category.ValidateDataElementCategoryOptionAction">
+			<result name="success" type="velocity-xml">
+				/dhis-web-maintenance-datadictionary/responseSuccess.vm</result>
+			<result name="input" type="velocity-xml">
+				/dhis-web-maintenance-datadictionary/responseInput.vm</result>
+		</action>
+	
 	</package>
 
 </struts>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js	2009-10-20 12:49:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js	2009-11-03 08:29:16 +0000
@@ -53,24 +53,18 @@
     }
 }
 
-function addCategoryOptionToCategory()
+function addCategoryOptionToCategory( categoryName )
 {
-	var categoryName = document.getElementById( 'categoryOptionName' ).value;
-	
-	if ( categoryName == "" )
-	{
-		setMessage( i18n_specify_category_option_name );
-	}
-	else if ( listContainsById( 'categoryOptionNames', categoryName ) )
+	if ( listContainsById( 'categoryOptionNames', categoryName ) )
 	{
 		setMessage( i18n_category_option_name_already_exists );
 	}
 	else
 	{
-	   addOption( 'categoryOptionNames', categoryName, categoryName );
+		addOption( 'categoryOptionNames', categoryName, categoryName );
+		document.getElementById( 'categoryOptionName' ).value = "";
+	}
 	
-	   document.getElementById( 'categoryOptionName' ).value = "";
-	}
 }
 
 // ----------------------------------------------------------------------
@@ -145,3 +139,26 @@
         setMessage( message );
     }
 }
+
+
+function validateCategoryOptionJQuery() {
+
+	var categoryName = $("#categoryOptionName").val();
+	
+	$.post("validateDataElementCategoryOption.action", {
+		name:categoryName
+	}, function ( xmlObject ) {
+	
+		xmlObject = xmlObject.getElementsByTagName("message")[0];
+		var type = xmlObject.getAttribute("type");
+		
+		if ( type == "input" ) {
+		
+			setMessage(xmlObject.firstChild.nodeValue);
+		}
+		else {
+			addCategoryOptionToCategory( categoryName );
+		}
+	}, "xml");
+}
+

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm	2009-10-20 12:49:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm	2009-11-03 08:29:16 +0000
@@ -27,7 +27,7 @@
     <tr>
       <td></td>
       <td colspan="2">
-      	<input type="button" value="$i18n.getString( "add_category_option" )" onclick="addCategoryOptionToCategory()" style="width:200px">
+      	<input type="button" value="$i18n.getString( "add_category_option" )" onclick="validateCategoryOptionJQuery()" style="width:200px">
       </td>
     </tr>
     <tr>