← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1389: Delete dataelementgroup function now using ajax to avoid reloading the whole page after a delete....

 

------------------------------------------------------------
revno: 1389
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-02-03 17:07:25 +0100
message:
  Delete dataelementgroup function now using ajax to avoid reloading the whole page after a delete. This is really required on web installations.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js
  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


--
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-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2010-02-03 11:08:38 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2010-02-03 16:07:25 +0000
@@ -593,3 +593,34 @@
     $( "div#loaderDiv" ).hide();
     $( "div#contentDiv" ).show();
 }
+
+/**
+ * Deletes and removes an item from a table. The table row to be removed must have
+ * an identifier on the form "tr[itemId]".
+ * 
+ * @param itemId the item identifier.
+ * @param itemName the item name.
+ * @param message the confirmation message.
+ * @param action the server action url for deleting the item.
+ */
+function removeItem( itemId, itemName, message, action )
+{                
+    var result = window.confirm( i18n_confirm_delete + "\n\n" + itemName );
+    
+    if ( result )
+    {       
+        $.ajax({ 
+            "url": action,
+            "data": { "id": itemId },
+            "success": function()
+            {
+                $( "tr#tr" + itemId ).remove();
+                
+                $( "table.listTable tbody tr" ).removeClass( "listRow listAlternateRow" );
+                $( "table.listTable tbody tr:odd" ).addClass( "listAlternateRow" );
+                $( "table.listTable tbody tr:even" ).addClass( "listRow" );
+                
+            }
+        });
+    }
+}

=== 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	2010-02-03 14:17:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/dataElementGroup.vm	2010-02-03 16:07:25 +0000
@@ -20,20 +20,14 @@
 					<th colspan="4">$i18n.getString( "operations" )</th>
 				</tr>
 				<tbody id="list">
-				#set( $mark = false )
 				#foreach( $dataElementGroup in $dataElementGroups )
-				<tr>
-					<td#alternate( $mark )>$encoder.htmlEncode( $dataElementGroup.name )</td>
-					<td style="text-align:center"#alternate( $mark )><a href="showUpdateDataElementGroupForm.action?id=$dataElementGroup.id" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( "edit" )"></a></td>
-					<td style="text-align:center"#alternate( $mark )><a href="javascript:translate( 'DataElementGroup', '$dataElementGroup.id' )"><img src="../images/i18n.png" alt="$i18n.getString( "translation_translate" )"></a></td>
-					<td style="text-align:center"#alternate( $mark )><a href="javascript:removeDataElementGroup( $dataElementGroup.id, '$encoder.jsEncode( $dataElementGroup.name )' )" title="$i18n.getString( "remove" )"><img src="../images/delete.png" alt="$i18n.getString( "remove" )"></a></td>
-					<td style="text-align:center"#alternate( $mark )><a href="javascript:showDataElementGroupDetails( $dataElementGroup.id )" title="$i18n.getString( "show_details" )"><img src="../images/information.png" alt="$i18n.getString( "show_details" )"></a></td>
+				<tr id="tr${dataElementGroup.id}">
+					<td>$encoder.htmlEncode( $dataElementGroup.name )</td>
+					<td style="text-align:center"><a href="showUpdateDataElementGroupForm.action?id=$dataElementGroup.id" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( "edit" )"></a></td>
+					<td style="text-align:center"><a href="javascript:translate( 'DataElementGroup', '$dataElementGroup.id' )"><img src="../images/i18n.png" alt="$i18n.getString( "translation_translate" )"></a></td>
+					<td style="text-align:center"><a href="javascript:removeDataElementGroup( $dataElementGroup.id, '$encoder.jsEncode( $dataElementGroup.name )' )" title="$i18n.getString( "remove" )"><img src="../images/delete.png" alt="$i18n.getString( "remove" )"></a></td>
+					<td style="text-align:center"><a href="javascript:showDataElementGroupDetails( $dataElementGroup.id )" title="$i18n.getString( "show_details" )"><img src="../images/information.png" alt="$i18n.getString( "show_details" )"></a></td>
 				</tr>
-					#if( $mark )
-						#set( $mark = false )
-					#else
-						#set( $mark = true )
-					#end
 				#end
 				</tbody>
 			</table>

=== 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	2010-01-22 03:15:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/dataElementGroup.js	2010-02-03 16:07:25 +0000
@@ -22,14 +22,19 @@
 // Remove data element group
 // -----------------------------------------------------------------------------
 
+/**
+ * DOM modifications at page load.
+ */
+$( document ).ready( function(){
+
+$( "table.listTable tbody tr:odd" ).addClass( "listAlternateRow" );
+$( "table.listTable tbody tr:even" ).addClass( "listRow" );
+
+});
+
 function removeDataElementGroup( dataElementGroupId, dataElementGroupName )
 {
-    var result = window.confirm( i18n_confirm_delete + '\n\n' + dataElementGroupName );
-    
-    if ( result )
-    {
-        window.location.href = 'removeDataElementGroup.action?id=' + dataElementGroupId;
-    }
+	removeItem( dataElementGroupId, dataElementGroupName, i18n_confirm_delete, "removeDataElementGroup.action" );
 }
 
 // -----------------------------------------------------------------------------