duplicate.form.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @file
  3. * JavaScript enhancements for "Merge Duplicate Terms" form.
  4. */
  5. (function ($) {
  6. /**
  7. * Behavior that elaborates Tableselect of duplicate terms.
  8. */
  9. Drupal.behaviors.termMergeDuplicateTableselect = {
  10. attach: function(context) {
  11. // We want to disable checkbox of a duplicate term if it is currently
  12. // selected as a trunk term in that group of duplicate terms, i.e. you
  13. // cannot (and should not) merge a term into itself.
  14. $('.term-merge-duplicate-trunk', context).closest(':has(.form-checkbox)').once('term-merge-duplicate-trunk', function() {
  15. var container = $(this);
  16. container.find('.term-merge-duplicate-trunk').change(function() {
  17. // Removing disabled from all disabled checkboxes.
  18. container.parents('table').find('.form-checkbox:disabled').removeAttr('disabled');
  19. if ($(this).is(':checked')) {
  20. container.find('.form-checkbox').attr('disabled', true);
  21. }
  22. });
  23. });
  24. }
  25. };
  26. /**
  27. * Behavior that kicks off general switch button on Duplicate terms form.
  28. */
  29. Drupal.behaviors.termMergeDuplicateGeneralSwitch = {
  30. attach: function (context) {
  31. $('.term-merge-duplicate-general-switch', context).once('term-merge-duplicate-general-switch', function() {
  32. var container = $(this).parents('form');
  33. $(this).change(function() {
  34. var term_branches = container.find('table:not(.sticky-header) .select-all .form-checkbox');
  35. if ($(this).is(':checked')) {
  36. term_branches.attr('checked', true).trigger({
  37. type: 'click',
  38. target: this
  39. });
  40. // For some reason the checkboxes get unchecked, we check them back.
  41. term_branches.attr('checked', true);
  42. // We also want to trigger "change" on those radio buttons, see
  43. // Drupal.behaviors.termMergeDuplicateTableselect for more info.
  44. container.find('table').find('.term-merge-duplicate-trunk:first').attr('checked', true).trigger('change');
  45. }
  46. else {
  47. term_branches.removeAttr('checked').trigger({
  48. type: 'click',
  49. target: this
  50. });
  51. // For some reason the checkboxes get checked, we uncheck them back.
  52. term_branches.removeAttr('checked');
  53. // We also want to trigger "change" on those radio buttons, see
  54. // Drupal.behaviors.termMergeDuplicateTableselect for more info.
  55. container.find('table').find('.term-merge-duplicate-trunk').removeAttr('checked').trigger('change');
  56. }
  57. });
  58. });
  59. }
  60. };
  61. })(jQuery);