summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/user/user.permissions.js
blob: e6d4ea4691a5f7988f0209574b9df9f8dca10e28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/

(function ($, Drupal) {
  Drupal.behaviors.permissions = {
    attach: function attach(context) {
      var _this = this;

      once('permissions', 'table#permissions').forEach(function (table) {
        var $table = $(table);
        var $ancestor;
        var method;

        if ($table.prev().length) {
          $ancestor = $table.prev();
          method = 'after';
        } else {
          $ancestor = $table.parent();
          method = 'append';
        }

        $table.detach();
        var $dummy = $(Drupal.theme('checkbox')).removeClass('form-checkbox').addClass('dummy-checkbox js-dummy-checkbox').attr('disabled', 'disabled').attr('checked', 'checked').attr('title', Drupal.t('This permission is inherited from the authenticated user role.')).hide();
        $table.find('input[type="checkbox"]').not('.js-rid-anonymous, .js-rid-authenticated').addClass('real-checkbox js-real-checkbox').after($dummy);
        $table.find('input[type=checkbox].js-rid-authenticated').on('click.permissions', _this.toggle).each(_this.toggle);
        $ancestor[method]($table);
      });
    },
    toggle: function toggle() {
      var authCheckbox = this;
      var $row = $(this).closest('tr');
      $row.find('.js-real-checkbox').each(function () {
        this.style.display = authCheckbox.checked ? 'none' : '';
      });
      $row.find('.js-dummy-checkbox').each(function () {
        this.style.display = authCheckbox.checked ? '' : 'none';
      });
    }
  };
})(jQuery, Drupal);