backup_migrate.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @file
  3. * Custom JS for the Backup and Migrate module.
  4. */
  5. (function ($) {
  6. 'use strict';
  7. Drupal.behaviors.backupMigrate = {
  8. attach: function (context, settings) {
  9. if (Drupal.settings.backup_migrate !== undefined) {
  10. if (Drupal.settings.backup_migrate.dependents !== undefined) {
  11. var key;
  12. for (key in Drupal.settings.backup_migrate.dependents) {
  13. info = Drupal.settings.backup_migrate.dependents[key];
  14. var dependent = $('#edit-' + info['dependent']);
  15. for (key in info['dependencies']) {
  16. $('[name="' + key + '"]').each(function () {
  17. var dependentval = info['dependencies'][key];
  18. var dependency = $(this);
  19. (function (dependent, dependency) {
  20. var checkval = function (inval) {
  21. // Do loose comparisons to support things like "true", "1",
  22. // etc.
  23. if (dependency.attr('type') === 'radio') {
  24. var val = $('[name="' + dependency.attr('name') + '"]:checked').val();
  25. return val == inval;
  26. }
  27. else if (dependency.attr('type') === 'checkbox') {
  28. return dependency.is(':checked') && inval == dependency.val();
  29. }
  30. else {
  31. return dependency.val() == inval;
  32. }
  33. return false;
  34. };
  35. if (!checkval(dependentval)) {
  36. // Hide doesn't work inside collapsed fieldsets.
  37. dependent.css('display', 'none');
  38. }
  39. dependency.bind('load change click keypress focus', function () {
  40. if (checkval(dependentval)) {
  41. dependent.slideDown();
  42. }
  43. else {
  44. dependent.slideUp();
  45. }
  46. }).load();
  47. })(dependent, dependency);
  48. });
  49. }
  50. }
  51. for (key in Drupal.settings.backup_migrate.destination_selectors) {
  52. var info = Drupal.settings.backup_migrate.destination_selectors[key];
  53. (function (info) {
  54. var selector = $('#' + info['destination_selector']);
  55. var copy = $('#' + info['copy'])
  56. var copy_selector = $('#' + info['copy_destination_selector']);
  57. var copy_selector_options = {};
  58. // Store a copy of the secondary selector options.
  59. copy_selector.find('optgroup').each(function () {
  60. var label = $(this).attr('label');
  61. copy_selector_options[label] = [];
  62. $(this).find('option').each(function () {
  63. copy_selector_options[label].push(this);
  64. });
  65. $(this).remove();
  66. })
  67. // Assign an action to the main selector to modify the secondary
  68. // selector.
  69. selector.each(function () {
  70. $(this).bind('load change click keypress focus', function () {
  71. var group = $(this).find('option[value=' + $(this).val() + ']').parents('optgroup').attr('label');
  72. if (group) {
  73. copy.parent().find('.backup-migrate-destination-copy-label').text(info['labels'][group]);
  74. copy_selector.empty();
  75. for (var key in copy_selector_options) {
  76. if (key != group) {
  77. copy_selector.append(copy_selector_options[key]);
  78. }
  79. }
  80. }
  81. }).load();
  82. });
  83. })(info);
  84. }
  85. // Add the convert to checkboxes functionality to all multiselects.
  86. $('#backup-migrate-ui-manual-backup-form select[multiple], #backup-migrate-crud-edit-form select[multiple]').each(function () {
  87. var self = this;
  88. $(self).after(
  89. $('<div class="description backup-migrate-checkbox-link"></div>').append(
  90. $('<a>' + Drupal.settings.backup_migrate.checkboxLinkText + '</a>').click(function () {
  91. var $select = $(self);
  92. var $checkboxes = $('<div></div>').addClass('backup-migrate-tables-checkboxes');
  93. $('option', $select).each(function (i) {
  94. $checkboxes.append(
  95. $('<div class="form-item"></div>').append(
  96. $('<label class="option backup-migrate-table-select">' + this.value + '</label>').prepend(
  97. $('<input type="checkbox" class="backup-migrate-tables-checkbox" name="' + $select.attr('name') + '"' + (this.selected ? 'checked="checked"' : '') + ' value="' + this.value + '"/>')
  98. .bind('click change load', function () {
  99. if (this.checked) {
  100. $(this).parent().addClass('checked');
  101. }
  102. else {
  103. $(this).parent().removeClass('checked');
  104. }
  105. }).load()
  106. )
  107. )
  108. );
  109. });
  110. $select.parent().find('.backup-migrate-checkbox-link').remove();
  111. $select.before($checkboxes);
  112. $select.hide();
  113. })
  114. )
  115. );
  116. });
  117. }
  118. }
  119. }
  120. }
  121. })(jQuery);