features_override_form.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. (function ($) {
  2. Drupal.behaviors.features_override_form = {
  3. attach: function(context, settings) {
  4. $('#edit-sources-features-overrides:not(.features-override-processed)', context)
  5. .prepend(Drupal.t('Advanced usage only. Allows you to select individual changes only to export.'))
  6. .addClass('features-override-processed');
  7. $('input[type=checkbox][name^="sources[features_override_items]"]:not(.features-override-form-processed)', context).each(function (i) {
  8. var $parent_checkbox = $(this);
  9. $parent_checkbox.addClass('features-override-form-processed');
  10. var $parent_label = $parent_checkbox.parent().find('label');
  11. // Create a link that links to the exact differences from the label.
  12. if (Drupal.settings.features_override_links['main'][this.value]) {
  13. $parent_label.append('<a href="' + Drupal.settings.features_override_links['main'][this.value] + '" target="_blank" class="features_override_button">' + Drupal.t('view') + '</a>');
  14. }
  15. var $child_checkboxes = $('input[type=checkbox][name^="sources[features_overrides]"][value^=' + this.value + ']').each(function (i) {
  16. if (Drupal.settings.features_override_links['sub'][this.value]) {
  17. $($(this).parent()).find('label').append('<a href="' + Drupal.settings.features_override_links['sub'][this.value] + '" target="_blank" class="features_override_button">' + Drupal.t('view') + '</a>');
  18. }
  19. }).parents('div.form-type-checkbox');
  20. $child_checkboxes.wrapAll('<div class="features-override-children-wrapper" id="' + this.id + '-wrapper"></div>');
  21. var $wrapper = $child_checkboxes.parent();
  22. // Prepend a label saying what these overrides are for.
  23. $wrapper.before('<h4>' + Drupal.t('Individual overrides for: ') + $parent_label.html() + '</h4>');
  24. var fotext = Drupal.t('Full overrides already exported for this item to this feature.')
  25. + ' '
  26. + '<a href="#" id="' + this.id + '-refine" class="features_override_button">' + Drupal.t('refine') + '</a>';
  27. $wrapper.after('<div class="features-override-children-warning" id="' + this.id + '-warning">' + fotext + '</div>');
  28. // Unchecks the items component to allow indivudal refinment if desired.
  29. $('#' + this.id + '-refine').bind('click', {id : this.id}, function(event) {
  30. $('#' + event.data.id).removeAttr('checked').trigger('change');
  31. return false;
  32. });
  33. // Disable child checkboxes when parent is selected
  34. $parent_checkbox.change(function() {
  35. features_override_switch_child_info(this.id, this.checked);
  36. });
  37. features_override_switch_child_info(this.id, this.checked);
  38. });
  39. }
  40. }
  41. function features_override_switch_child_info(id, is_checked) {
  42. if (is_checked) {
  43. // Jquery bug that hide() doesn't always work when parent hidden.
  44. $('#' + id + '-wrapper').css('display', 'none');
  45. $('#' + id + '-warning').css('display', 'block');
  46. }
  47. else {
  48. $('#' + id + '-wrapper').show();
  49. $('#' + id + '-warning').css('display', 'none');
  50. }
  51. }
  52. })(jQuery);