diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-11-30 09:02:51 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-11-30 09:02:51 +0000 |
commit | bad47cbf856eb6197efff9b5d23c124d147a0441 (patch) | |
tree | 103deabb1727537fffa1a0d8d9460cade1b6a4cc /modules/profile/profile.js | |
parent | 9d23c24d8e1decc840a5793affd52b581a6d6515 (diff) | |
download | brdo-bad47cbf856eb6197efff9b5d23c124d147a0441.tar.gz brdo-bad47cbf856eb6197efff9b5d23c124d147a0441.tar.bz2 |
#193998 by Rob Loach and quicksketch: profile fields drag and drop
Diffstat (limited to 'modules/profile/profile.js')
-rw-r--r-- | modules/profile/profile.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/modules/profile/profile.js b/modules/profile/profile.js new file mode 100644 index 000000000..dadc60a01 --- /dev/null +++ b/modules/profile/profile.js @@ -0,0 +1,54 @@ +// $Id$ + +/** + * Add functionality to the profile drag and drop table. + * + * This behavior is dependent on the tableDrag behavior, since it uses the + * objects initialized in that behavior to update the row. It shows and hides + * a warning message when removing the last field from a profile category. + */ +Drupal.behaviors.profileDrag = function(context) { + var table = $('#profile-fields'); + var tableDrag = Drupal.tableDrag['profile-fields']; // Get the profile tableDrag object. + + // Add a handler for when a row is swapped, update empty categories. + tableDrag.row.prototype.onSwap = function(swappedRow) { + var rowObject = this; + $('tr.category-message', table).each(function() { + // If the dragged row is in this category, but above the message row, swap it down one space. + if ($(this).prev('tr').get(0) == rowObject.element) { + // Prevent a recursion problem when using the keyboard to move rows up. + if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) { + rowObject.swap('after', this); + } + } + // This category has become empty + if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) { + $(this).removeClass('category-populated').addClass('category-empty'); + } + // This category has become populated. + else if ($(this).is('.category-empty')) { + $(this).removeClass('category-empty').addClass('category-populated'); + } + }); + }; + + // Add a handler so when a row is dropped, update fields dropped into new categories. + tableDrag.onDrop = function() { + dragObject = this; + if ($(dragObject.rowObject.element).prev('tr').is('.category-message')) { + var categoryRow = $(dragObject.rowObject.element).prev('tr').get(0); + var categoryNum = categoryRow.className.replace(/([^ ]+[ ]+)*category-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); + var categoryField = $('select.profile-category', dragObject.rowObject.element); + var weightField = $('select.profile-weight', dragObject.rowObject.element); + var oldcategoryNum = weightField[0].className.replace(/([^ ]+[ ]+)*profile-weight-([^ ]+)([ ]+[^ ]+)*/, '$2'); + + if (!categoryField.is('.profile-category-'+ categoryNum)) { + categoryField.removeClass('profile-category-' + oldcategoryNum).addClass('profile-category-' + categoryNum); + weightField.removeClass('profile-weight-' + oldcategoryNum).addClass('profile-weight-' + categoryNum); + + categoryField.val(categoryField[0].options[categoryNum].value); + } + } + }; +}; |