← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4717: Cleaned up category javascript

 

------------------------------------------------------------
revno: 4717
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-09-27 14:16:53 +0200
message:
  Cleaned up category javascript
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js
modified:
  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/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
=== 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	2011-09-27 08:14:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2011-09-27 12:16:53 +0000
@@ -564,6 +564,7 @@
     <action name="showAddDataElementCategoryForm" class="org.hisp.dhis.dd.action.concept.GetConceptListAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm</param>
+	  <param name="javascripts">javascript/category.js</param>
       <param name="requiredAuthorities">F_DATAELEMENT_ADD</param>
     </action>
 
@@ -603,7 +604,8 @@
 
     <action name="showUpdateDataElementCategoryForm" class="org.hisp.dhis.dd.action.category.GetDataElementCategoryAction">
       <result name="success" type="velocity">/main.vm</result>
-      <param name="page">/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm</param>
+      <param name="page">/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm</param>	  
+	  <param name="javascripts">javascript/category.js</param>
       <param name="requiredAuthorities">F_DATAELEMENT_UPDATE</param>
     </action>
 

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js	2011-09-27 12:16:53 +0000
@@ -0,0 +1,92 @@
+
+function removeDataElementCategory( categoryId, categoryName )
+{
+	removeItem( categoryId, categoryName, i18n_confirm_delete, 'removeDataElementCategory.action' );
+}
+	
+function addCategoryOption()
+{
+	var value = getFieldValue( 'categoryOptionName' );
+	if( value.length == 0 ) 
+	{
+		markInvalid( 'categoryOptionName', i18n_specify_category_option_name );
+	} 
+	else if ( listContainsById( 'categoryOptionNames', value ) ) 
+	{
+		markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
+	} 
+	else 
+	{
+		jQuery.postJSON( 'validateDataElementCategoryOption.action', { name:value }, function( json ) 
+		{
+			if ( json.response == 'success' )
+			{					
+				addOption( 'categoryOptionNames', value, value );
+				setFieldValue( 'categoryOptionName', '' );
+			}
+			else
+			{
+				markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
+			}
+		} );
+	}
+}
+
+function updateCategoryOption()
+{
+	try
+	{
+		var name = getFieldValue( 'categoryOptionName' );
+		var id = getFieldValue( 'categoryOptions' );
+		
+		if ( name.length == 0 )
+		{
+			markInvalid( 'categoryOptionName', i18n_specify_category_option_name );
+		}		
+		else if ( listContainsById( 'categoryOptions', name, true ) )
+		{
+			markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
+		}
+		else
+		{
+			jQuery.postJSON( 'validateDataElementCategoryOption.action', { name:name, id:id }, function( json )
+			{
+				if( json.response == 'success' )
+				{
+					updateCategoryOptionName();
+				}
+				else
+				{
+					markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
+				}
+			} );
+		}
+	}
+	catch ( e )
+	{
+		markInvalid( 'categoryOptionName', i18n_specify_category_option_name );
+	}
+}
+
+function getSelectedCategoryOption()
+{
+	var categoryOptions = byId('categoryOptions');
+	byId('categoryOptionName').value=categoryOptions[categoryOptions.selectedIndex].text;
+}
+
+function updateCategoryOptionName()
+{
+	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;
+	showSuccessMessage( 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	2011-07-08 03:19:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm	2011-09-27 12:16:53 +0000
@@ -11,31 +11,6 @@
     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" ) , "'")';
-	
-	function removeDataElementCategory( categoryId, categoryName )
-	{
-		removeItem( categoryId, categoryName, i18n_confirm_delete, 'removeDataElementCategory.action' );
-	}
-		
-	function addCategoryOption()
-	{
-		var value = getFieldValue( 'categoryOptionName' );
-		if( value.length == 0 ) {
-			markInvalid( 'categoryOptionName', i18n_specify_category_option_name );
-		} else if( listContainsById( 'categoryOptionNames', value ) ) {
-			markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
-		} else {
-			jQuery.postJSON( 'validateDataElementCategoryOption.action', 
-			{name: value }, function(json) {
-				if( json.response == 'success' ){					
-					addOption( 'categoryOptionNames', value, value );
-					setFieldValue( 'categoryOptionName', '' );
-				}else{
-					markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
-				}
-			});
-		}
-	}
 </script>
 
 <h3>$i18n.getString( "create_new_data_element_category" )</h3>

=== 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	2011-07-08 08:52:50 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm	2011-09-27 12:16:53 +0000
@@ -11,50 +11,6 @@
     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 updateCategoryOption()
-	{
-		try{
-			var name = getFieldValue( 'categoryOptionName' );
-			var id = getFieldValue( 'categoryOptions' );
-			
-			if( name.length == 0 ) markInvalid( 'categoryOptionName', i18n_specify_category_option_name );		
-			else if( listContainsById( 'categoryOptions', name, true) ) markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
-			else
-			{
-				jQuery.postJSON( 'validateDataElementCategoryOption.action', 
-				{name: name, id: id }, function(json){
-					if( json.response == 'success' ){
-						updateCategoryOptionName();
-					}else{
-						markInvalid( 'categoryOptionName', i18n_category_option_name_already_exists );
-					}
-				});
-			}
-		} catch(e) { markInvalid( 'categoryOptionName', i18n_specify_category_option_name ); }
-	}
-
-	function getSelectedCategoryOption(){
-		var categoryOptions = byId('categoryOptions');
-		byId('categoryOptionName').value=categoryOptions[categoryOptions.selectedIndex].text;
-	}
-	
-	function updateCategoryOptionName(){
-		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;
-		showSuccessMessage( i18n_option_rename_successfully );
-	}
 </script>
 
 <h3>$i18n.getString( "edit_data_element_category" )</h3>