backup_migrate.js 5.3 KB

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