← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1711: Edit category option names.

 

------------------------------------------------------------
revno: 1711
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-03-30 11:36:31 +0700
message:
  Edit category option names.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/UpdateDataElementCategoryOptionAction.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/org/hisp/dhis/dd/i18n_module.properties
  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
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.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/UpdateDataElementCategoryOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/UpdateDataElementCategoryOptionAction.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/UpdateDataElementCategoryOptionAction.java	2010-03-30 04:36:31 +0000
@@ -0,0 +1,86 @@
+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.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * @version $Id$
+ */
+public class UpdateDataElementCategoryOptionAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    private DataElementCategoryService dataElementCategoryService;
+
+    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+    {
+        this.dataElementCategoryService = dataElementCategoryService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private String name;
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        DataElementCategoryOption categoryOption = dataElementCategoryService
+            .getDataElementCategoryOption( id );
+        categoryOption.setName( name );
+        
+        dataElementCategoryService.updateDataElementCategoryOption( categoryOption );
+
+        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	2010-02-26 03:26:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml	2010-03-30 04:36:31 +0000
@@ -812,6 +812,15 @@
 		</property>
 	</bean>
 
+	<bean
+		id="org.hisp.dhis.dd.action.category.UpdateDataElementCategoryOptionAction"
+		class="org.hisp.dhis.dd.action.category.UpdateDataElementCategoryOptionAction"
+		scope="prototype">
+		<property name="dataElementCategoryService">
+			<ref bean="org.hisp.dhis.dataelement.DataElementCategoryService" />
+		</property>
+	</bean>
+	
 	<!-- CategoryCombo -->
 
 	<bean

=== 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	2010-02-25 08:57:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2010-03-30 04:36:31 +0000
@@ -1,6 +1,5 @@
 aggregate										= Aggregate
 patient											= Patient
-no_option_assigned								= Use of category with an empty option is not allowed!
 number_of_category_options						= Number of category options
 number_of_categories							= Number of categories
 table_layout_for								= Table layout for
@@ -389,4 +388,7 @@
 switch_view										= Switch View
 available_groups								= Available Groups
 assign_groups_for_dataelement					= Assign Groups for Data Element
-select_dataelement								= Please select data element
\ No newline at end of file
+select_dataelement								= Please select data element
+selected_name									= Selected name
+edit_category_option							= Edit category option
+option_rename_successfully						= Category option renamed successfully.
\ No newline at end of file

=== 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	2010-03-23 17:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2010-03-30 04:36:31 +0000
@@ -120,8 +120,10 @@
 
 		<action name="dataElementGroupEditor"
 			class="org.hisp.dhis.dd.action.SwitchGroupEditorViewAction">
-			<result name="view1" type="chain">dataElementGroupEditorView1</result>
-			<result name="view2" type="chain">dataElementGroupEditorView2</result>
+			<result name="view1" type="chain">dataElementGroupEditorView1
+			</result>
+			<result name="view2" type="chain">dataElementGroupEditorView2
+			</result>
 		</action>
 
 		<action name="dataElementGroupEditorView1"
@@ -131,7 +133,7 @@
 			<param name="menu">/dhis-web-maintenance-datadictionary/menu.vm</param>
 			<param name="javascripts">javascript/dataElementGroupEditorView1.js</param>
 		</action>
-		
+
 		<action name="dataElementGroupEditorView2"
 			class="org.hisp.dhis.dd.action.dataelement.GetDataElementListAction">
 			<result name="success" type="velocity">/main.vm</result>
@@ -139,14 +141,14 @@
 			<param name="menu">/dhis-web-maintenance-datadictionary/menu.vm</param>
 			<param name="javascripts">javascript/dataElementGroupEditorView2.js</param>
 		</action>
-		
+
 		<action name="getAssignedDataElementGroups"
 			class="org.hisp.dhis.dd.action.dataelementgroup.GetAssignedGroupsByDataElementAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-maintenance-datadictionary/responseDataElementGroups.vm
 			</result>
 		</action>
-		
+
 		<action name="asignGroupsForDataElement"
 			class="org.hisp.dhis.dd.action.dataelementgroup.AssignGroupsForDataElementAction">
 			<result name="success" type="velocity-xml">
@@ -158,7 +160,7 @@
 			class="org.hisp.dhis.dd.action.dataelementgroup.GetDataElementGroupAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-maintenance-datadictionary/responseDataElementGroupSuccess.vm
-			</result>			
+			</result>
 		</action>
 
 		<action name="addDataElementGroupEditor"
@@ -191,8 +193,8 @@
 			<param name="requiredAuthorities">F_DATAELEMENTGROUP_UPDATE</param>
 		</action>
 
-		<!-- DataElementGroup -->		
-		
+		<!-- DataElementGroup -->
+
 		<action name="dataElementGroup"
 			class="org.hisp.dhis.dd.action.dataelementgroup.GetDataElementGroupListAction">
 			<result name="success" type="velocity">/main.vm</result>
@@ -335,11 +337,13 @@
 		</action>
 
 		<!-- Indicator Group Editor -->
-		
+
 		<action name="indicatorGroupEditor"
 			class="org.hisp.dhis.dd.action.SwitchGroupEditorViewAction">
-			<result name="view1" type="chain">indicatorGroupEditorView1</result>
-			<result name="view2" type="chain">indicatorGroupEditorView2</result>
+			<result name="view1" type="chain">indicatorGroupEditorView1
+			</result>
+			<result name="view2" type="chain">indicatorGroupEditorView2
+			</result>
 		</action>
 
 		<action name="indicatorGroupEditorView1"
@@ -350,7 +354,7 @@
 			<param name="javascripts">javascript/indicatorGroupEditorView1.js</param>
 			<param name="stylesheets">style/indicatorGroupEditor.css</param>
 		</action>
-		
+
 		<action name="indicatorGroupEditorView2"
 			class="org.hisp.dhis.dd.action.indicator.GetIndicatorListAction">
 			<result name="success" type="velocity">/main.vm</result>
@@ -359,22 +363,22 @@
 			<param name="javascripts">javascript/indicatorGroupEditorView2.js</param>
 			<param name="stylesheets">style/indicatorGroupEditor.css</param>
 		</action>
-		
+
 		<action name="getAssignedIndicatorGroups"
 			class="org.hisp.dhis.dd.action.indicatorgroup.GetAssignedIndicatorGroupsAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-maintenance-datadictionary/responseIndicatorGroups.vm
 			</result>
 		</action>
-		
+
 		<action name="asignGroupsForIndicator"
 			class="org.hisp.dhis.dd.action.indicatorgroup.AssignGroupsForIndicatorAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-maintenance-datadictionary/responseSuccess.vm
 			</result>
 		</action>
-		
-		
+
+
 
 		<action name="getIndicatorGroupEditor"
 			class="org.hisp.dhis.dd.action.indicatorgroup.GetIndicatorGroupAction">
@@ -1017,6 +1021,13 @@
 			<param name="requiredAuthorities">F_DATAELEMENT_DELETE</param>
 		</action>
 
+		<action name="updateDataElementCategoryOption"
+			class="org.hisp.dhis.dd.action.category.UpdateDataElementCategoryOptionAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+			<param name="requiredAuthorities">F_DATAELEMENT_UPDATE</param>
+		</action>
+
 		<!-- CategoryCombo -->
 
 		<action name="showAddDataElementCategoryComboForm"

=== 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	2010-02-17 13:38:15 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js	2010-03-30 04:36:31 +0000
@@ -136,10 +136,36 @@
 		{
 			setMessage( xmlObject.firstChild.nodeValue );
 		}
-		else 
+		else if(mode == "update"){
+			updateCategoryOptionName();
+		}
+		else
 		{
 			addCategoryOptionToCategory( categoryName );
 		}
 	}, "xml");
 }
 
+
+// ----------------------------------------------------------------------
+// Rename Category Option
+// ----------------------------------------------------------------------
+
+function updateCategoryOptionName(){
+	validateAddCategoryOption();
+	var request = new Request();
+    request.setResponseTypeXML( 'xmlObject' );
+    request.setCallbackSuccess( updateCategoryOptionNameReceived );
+	var params = "id=" + byId('categoryOptions').value;
+		params += '&name=' + byId('categoryOptionName').value;
+	request.sendAsPost(params);
+	request.send('updateDataElementCategoryOption.action');
+}
+
+function updateCategoryOptionNameReceived(xmlObject){
+	var categoryOptions = byId('categoryOptions');
+		categoryOptions[categoryOptions.selectedIndex].text = byId('categoryOptionName').value;
+	setMessage( i18n_option_rename_successfully );
+	
+}
+

=== 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	2010-03-18 09:45:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm	2010-03-30 04:36:31 +0000
@@ -86,4 +86,5 @@
     var i18n_specify_category_option_name = '$encoder.jsEscape( $i18n.getString( "specify_category_option_name" ) , "'")';
     var i18n_category_option_name_already_exists = '$encoder.jsEscape( $i18n.getString( "category_option_name_already_exists" ) , "'")';
     var i18n_must_include_category_option = '$encoder.jsEscape( $i18n.getString( "must_include_category_option" ) , "'")';
+	var mode = 'add';
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm	2010-03-18 09:45:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm	2010-03-30 04:36:31 +0000
@@ -47,10 +47,21 @@
       <th colspan="2">$i18n.getString( "category_options" )</th>
       <td></td>
     </tr>
+	<tr>
+	  <td><label>$i18n.getString( "selected_name" )</label></td>
+	  <td><input type="text" id="categoryOptionName" style="width:25em"></td>
+	  <td></td>
+	</tr>
+	 <tr>
+      <td></td>
+      <td colspan="2">
+      	<input type="button" value="$i18n.getString( "edit_category_option" )" onclick="validateAddCategoryOption();" style="width:200px">
+      </td>
+    </tr>
     <tr>
       <td></td>
       <td>
-        <select multiple size="10" id="categoryOptions" name="categoryOptions" style="width:300px">
+        <select multiple size="10" id="categoryOptions" name="categoryOptions" style="width:300px" onchange='showName();'>
         #foreach( $categoryOption in $dataElementCategory.categoryOptions )
         	<option value="$categoryOption.id">$encoder.htmlEncode( $categoryOption.name )</option>
         #end
@@ -79,4 +90,11 @@
 <script type="text/javascript">
     var i18n_specify_category_option_name = '$encoder.jsEscape( $i18n.getString( "specify_category_option_name" ) , "'")';
     var i18n_category_option_name_already_exists = '$encoder.jsEscape( $i18n.getString( "category_option_name_already_exists" ) , "'")';
+	var i18n_option_rename_successfully = '$encoder.jsEscape( $i18n.getString( "option_rename_successfully" ) , "'")';
+	var mode = 'update';
+	
+	function showName(){
+		var categoryOptions = byId('categoryOptions');
+		byId('categoryOptionName').value=categoryOptions[categoryOptions.selectedIndex].text;
+	}
 </script>