Author: david
Date: Fri Oct 23 07:13:47 2009
New Revision: 3808

Log:
Commit Jesús' mulit-row delete patch for child levels.  Fixes issue #826.

Modified:
   trunk/web/js/multiRow.js

Modified: trunk/web/js/multiRow.js
==============================================================================
--- trunk/web/js/multiRow.js    Fri Oct 23 00:02:42 2009        (r3807)
+++ trunk/web/js/multiRow.js    Fri Oct 23 07:13:47 2009        (r3808)
@@ -47,12 +47,62 @@
   table.find('tbody tr:last div.animateNicely').show('normal');
 }
 
+function removeRow(sender)
+{
+  var table = $(sender).parents('table:first');
+  var rows = table.find('tbody tr');
+  var row = $(sender).parents('tr:first');
+
+  if (1 < rows.length)
+  {
+    if (!row.children('div.animateNicely').length)
+    {
+      row.find('td').each(function(i) {
+        if (0 == $(this).find('div.animateNicely').length)
+        {
+          $(this).wrapInner('<div class="animateNicely"></div>');
+        }
+      });
+    }
+
+    row.find('div').hide('normal', function() {
+      row.remove();
+    });
+
+    var rowNumber = parseInt(row.find("select, 
input").filter(":first").attr("name").match(/\d/).shift());
+
+    rowNumber--;
+
+    row.nextAll().each(function() {
+      rowNumber++;
+      $(this).find('input, select').each(function() {
+        var newName = $(this).attr('name').replace(/\[\d\]/, '[' + rowNumber + 
']');
+        $(this).attr('name', newName);
+      });
+    });
+  }
+  else
+  {
+    row.find('input, select').each(function() {
+      $(this).val('');
+
+      if ($(this).is('select'))
+      {
+        $(this)[0].selectedIndex = 0;
+      }
+    });
+  }
+}
+
 /**
  * On page load, "multiRow" tables are prepared to add as many rows as users 
want
  */
 Drupal.behaviors.multiRow = {
   attach: function (context)
   {
+    $('table.multiRow thead tr:first').append('<th>&nbsp;</th>');
+    $('table.multiRow tbody tr:first').append('<td><button name="delete" 
class="delete-small" onclick="removeRow(this); return false;" /></td>');
+
     // Add tfoot for adding new rows button
     $('table.multiRow').each(function () {
       var tfoot  = '<tfoot>';

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to