home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (user.permissions.js)

This example Drupal source code file (user.permissions.js) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, checkbox, checked, context, disabled, each, function, hide, insertafter, jquery, php, this, type

The user.permissions.js Drupal example source code

// $Id: user.permissions.js,v 1.2 2010/04/19 21:17:16 webchick Exp $
(function ($) {

 * Shows checked and disabled checkboxes for inherited permissions.
Drupal.behaviors.permissions = {
  attach: function (context) {
    $('table#permissions:not(.permissions-processed)').each(function () {
      // Create dummy checkboxes. We use dummy checkboxes instead of reusing
      // the existing checkboxes here because new checkboxes don't alter the
      // submitted form. If we'd automatically check existing checkboxes, the
      // permission table would be polluted with redundant entries. This
      // is deliberate, but desirable when we automatically check them.
      $(':checkbox', this).not('[name^="2["]').not('[name^="1["]').each(function () {
        $('<input type="checkbox" class="dummy-checkbox" disabled="disabled" checked="checked" />')
          .attr('title', Drupal.t("This permission is inherited from the authenticated user role."))

      // Helper function toggles all dummy checkboxes based on the checkboxes'
      // state. If the "authenticated user" checkbox is checked, the checked
      // and disabled checkboxes are shown, the real checkboxes otherwise.
      var toggle = function () {
          .find('.real-checkbox')[this.checked ? 'hide' : 'show']().end()
          .find('.dummy-checkbox')[this.checked ? 'show' : 'hide']();

      // Initialize the authenticated user checkbox.
      $(':checkbox[name^="2["]', this)
        .each(function () { toggle.call(this); });


Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal user.permissions.js source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.