logintoboggan-exempting_lt_preauth_role_from_user_permissions_js-1365764-52.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. diff --git a/logintoboggan.module b/logintoboggan.module
  2. index 55b93fe..4e4e0fc 100644
  3. --- a/logintoboggan.module
  4. +++ b/logintoboggan.module
  5. @@ -306,26 +306,6 @@ function logintoboggan_form_user_pass_reset_alter(&$form, &$form_state) {
  6. }
  7. /**
  8. - * Implement hook_form_user_admin_permissions_alter().
  9. - *
  10. - * @ingroup logintoboggan_core
  11. - */
  12. -function logintoboggan_form_user_admin_permissions_alter(&$form, &$form_state) {
  13. - // If the pre-auth role isn't the auth user, then add it as a setting.
  14. - $id = logintoboggan_validating_id();
  15. - if ($id != DRUPAL_AUTHENTICATED_RID) {
  16. - $form['#attached']['js'][] = array(
  17. - 'data' => array(
  18. - 'LoginToboggan' => array(
  19. - 'preAuthID' => $id,
  20. - ),
  21. - ),
  22. - 'type' => 'setting',
  23. - );
  24. - }
  25. -}
  26. -
  27. -/**
  28. * Implement hook_form_alter().
  29. *
  30. * @ingroup logintoboggan_core
  31. @@ -410,7 +390,10 @@ function logintoboggan_js_alter(&$javascript) {
  32. // prevent the pre-auth role's checkboxes from being automatically disabled
  33. // when the auth user's checkboxes are checked.
  34. if ($id != DRUPAL_AUTHENTICATED_RID) {
  35. - $javascript['modules/user/user.permissions.js']['data'] = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.permissions.js';
  36. + $javascript['settings']['data'][] = array('LoginToboggan' => array('preAuthID' => $id));
  37. + $file = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.permissions.js';
  38. + $javascript[$file] = drupal_js_defaults($file);
  39. + $javascript[$file]['weight'] = 999;
  40. }
  41. }
  42. }
  43. diff --git a/logintoboggan.permissions.js b/logintoboggan.permissions.js
  44. index 1d406cc..492b64c 100644
  45. --- a/logintoboggan.permissions.js
  46. +++ b/logintoboggan.permissions.js
  47. @@ -1,77 +1,25 @@
  48. /**
  49. - * This is a custom implementation of user.permissions.js, which is necessary
  50. - * because LoginToboggan needs its pre-auth role to not be explicitly tied to
  51. - * the auth role. The change is minor -- simply exclude the pre-auth role from
  52. - * all the auto-checking as the anon and auth user roles are.
  53. + * LoginToboggan needs its pre-auth role to not be explicitly tied to
  54. + * the auth role.
  55. */
  56. -
  57. (function ($) {
  58. /**
  59. * Shows checked and disabled checkboxes for inherited permissions.
  60. */
  61. -Drupal.behaviors.permissions = {
  62. - attach: function (context) {
  63. - var self = this;
  64. - $('table#permissions').once('permissions', function () {
  65. - // On a site with many roles and permissions, this behavior initially has
  66. - // to perform thousands of DOM manipulations to inject checkboxes and hide
  67. - // them. By detaching the table from the DOM, all operations can be
  68. - // performed without triggering internal layout and re-rendering processes
  69. - // in the browser.
  70. - var $table = $(this);
  71. - if ($table.prev().length) {
  72. - var $ancestor = $table.prev(), method = 'after';
  73. - }
  74. - else {
  75. - var $ancestor = $table.parent(), method = 'append';
  76. - }
  77. - $table.detach();
  78. -
  79. - // Create dummy checkboxes. We use dummy checkboxes instead of reusing
  80. - // the existing checkboxes here because new checkboxes don't alter the
  81. - // submitted form. If we'd automatically check existing checkboxes, the
  82. - // permission table would be polluted with redundant entries. This
  83. - // is deliberate, but desirable when we automatically check them.
  84. - var $dummy = $('<input type="checkbox" class="dummy-checkbox" disabled="disabled" checked="checked" />')
  85. - .attr('title', Drupal.t("This permission is inherited from the authenticated user role."))
  86. - .hide();
  87. -
  88. - $('input[type=checkbox]', this).not('.rid-2, .rid-1, .rid-' + Drupal.settings.LoginToboggan.preAuthID).addClass('real-checkbox').each(function () {
  89. - $dummy.clone().insertAfter(this);
  90. +Drupal.behaviors.LoginTobogganPermissions = {
  91. + attach: function (context, settings) {
  92. + // Revert changes made by modules/user/user.permissions.js
  93. + $('table#permissions', context).once('tobogganPermissions', function () {
  94. + $('input[type=checkbox]', this).filter('.rid-' + settings.LoginToboggan.preAuthID).removeClass('real-checkbox').each(function () {
  95. + $(this).next().filter('.dummy-checkbox').remove();
  96. + $('input.rid-' + settings.LoginToboggan.preAuthID).each(function () {
  97. + this.style.display = '';
  98. + });
  99. });
  100. -
  101. - // Initialize the authenticated user checkbox.
  102. - $('input[type=checkbox].rid-2', this)
  103. - .bind('click.permissions', self.toggle)
  104. - // .triggerHandler() cannot be used here, as it only affects the first
  105. - // element.
  106. - .each(self.toggle);
  107. -
  108. - // Re-insert the table into the DOM.
  109. - $ancestor[method]($table);
  110. });
  111. },
  112. -
  113. - /**
  114. - * Toggles all dummy checkboxes based on the checkboxes' state.
  115. - *
  116. - * If the "authenticated user" checkbox is checked, the checked and disabled
  117. - * checkboxes are shown, the real checkboxes otherwise.
  118. - */
  119. - toggle: function () {
  120. - var authCheckbox = this, $row = $(this).closest('tr');
  121. - // jQuery performs too many layout calculations for .hide() and .show(),
  122. - // leading to a major page rendering lag on sites with many roles and
  123. - // permissions. Therefore, we toggle visibility directly.
  124. - $row.find('.real-checkbox').each(function () {
  125. - this.style.display = (authCheckbox.checked ? 'none' : '');
  126. - });
  127. - $row.find('.dummy-checkbox').each(function () {
  128. - this.style.display = (authCheckbox.checked ? '' : 'none');
  129. - });
  130. - }
  131. };
  132. })(jQuery);