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

Drupal example source code file (rules_admin.js)

This example Drupal source code file (rules_admin.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

append, change, context, else, function, href, if, machine, nextall, php, rules-argument-label, rules-argument-name, td, var

The rules_admin.js Drupal example source code

Drupal.behaviors.RulesAdminSetAddArg = function (context) {
  $('.rules-argument-data-type:not(.RulesAdminSetAddArg-processed)', context).addClass('RulesAdminSetAddArg-processed').each(function () {
    $('select', this).bind("change", function() {
    
      if ($(this).parents("td").nextAll(".rules-argument-name").find('input').val() == '')
        $(this).parents("td").nextAll(".rules-argument-name").find('input').val( $(this).val() );

      if ($(this).parents("td").nextAll(".rules-argument-label").find('input').val() == '')
        $(this).parents("td").nextAll(".rules-argument-label").find('input').val(
             $("option:selected", this).text()
         );

    });
  });
};

Drupal.behaviors.RulesAdminMachineName = function (context) {
  // Add rule form machine-readable JS
  $('#edit-label').addClass('processed').after(' <small class="rules-name-suffix"> </small>');
  $('#edit-name').parents('.form-item').hide();

  // Add a click function to our rules name suffix.
  $('.rules-name-suffix').click(function() {
        $('#edit-name').parents('.form-item').show();
        $('.rules-name-suffix').hide();
        $('#edit-label').unbind('keyup');
        return false;
  });

  $('#edit-label').keyup(function() {
    var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]/g, '_').replace(/_+/g, '_').replace(/^[^a-z]/, 'a');
    if (machine !== '') {
      $('#edit-name').val(machine);
      $('.rules-name-suffix').html(' ' + Drupal.t('Machine name:') + ' ' + machine + ' [').append($('<a href="#">'+ Drupal.t('Edit') +'</a>')).append(']');
    }
    else {
      $('#edit-name').val(machine);
      $('.rules-name-suffix').text('');
    }
  });
  // If we already have a machine name filled in, then just use that.
  if($('#edit-name').val() !== '') {
    $('.rules-name-suffix').html(' ' + Drupal.t('Machine name:') + ' ' + $('#edit-name').val() + ' [').append($('<a href="#">'+ Drupal.t('Edit') +'</a>')).append(']');
  }
  // If there's nothing in the field, then we can just trigger the event.
  else {
    $('#edit-label').keyup();
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal rules_admin.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.