flag-admin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function ($) {
  2. /**
  3. * Behavior to disable the "unflag" option if "flag" is not available.
  4. */
  5. Drupal.behaviors.flagRoles = {};
  6. Drupal.behaviors.flagRoles.attach = function(context) {
  7. $('#flag-roles input.flag-access', context).change(function() {
  8. var unflagCheckbox = $(this).parents('tr:first').find('input.unflag-access').get(0);
  9. if (this.checked) {
  10. // If "flag" is available, restore the state of the "unflag" checkbox.
  11. unflagCheckbox.disabled = false;
  12. if (typeof(unflagCheckbox.previousFlagState) != 'undefined') {
  13. unflagCheckbox.checked = unflagCheckbox.previousFlagState;
  14. }
  15. else {
  16. unflagCheckbox.checked = true;
  17. }
  18. }
  19. else {
  20. // Remember if the "unflag" option was checked or unchecked, then disable.
  21. unflagCheckbox.previousFlagState = unflagCheckbox.checked;
  22. unflagCheckbox.disabled = true;
  23. unflagCheckbox.checked = false;
  24. }
  25. });
  26. $('#flag-roles input.unflag-access', context).change(function() {
  27. if ($(this).parents('table:first').find('input.unflag-access:enabled:not(:checked)').size() == 0) {
  28. $('div.form-item-unflag-denied-text').slideUp();
  29. }
  30. else {
  31. $('div.form-item-unflag-denied-text').slideDown();
  32. }
  33. });
  34. // Hide the link options by default if needed.
  35. if ($('#flag-roles input.unflag-access:enabled:not(:checked)').size() == 0) {
  36. $('div.form-item-unflag-denied-text').css('display', 'none');
  37. }
  38. };
  39. /**
  40. * Vertical tabs integration.
  41. */
  42. Drupal.behaviors.flagSummary = {};
  43. Drupal.behaviors.flagSummary.attach = function (context) {
  44. $('fieldset.flag-fieldset', context).drupalSetSummary(function(context) {
  45. var flags = [];
  46. $('input:checkbox:checked', context).each(function() {
  47. flags.push(this.title);
  48. });
  49. if (flags.length) {
  50. return flags.join(', ');
  51. }
  52. else {
  53. return Drupal.t('No flags');
  54. }
  55. });
  56. };
  57. })(jQuery);