backup_migrate.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. (function ($) {
  2. Drupal.backup_migrate = {
  3. callbackURL : "",
  4. autoAttach : function() {
  5. if (Drupal.settings.backup_migrate !== undefined) {
  6. if ($("#edit-save-settings").length && !$("#edit-save-settings").attr("checked")) {
  7. // Disable input and hide its description.
  8. // Set display none instead of using hide(), because hide() doesn't work when parent is hidden.
  9. $('div.backup-migrate-save-options').css('display', 'none');
  10. }
  11. $("#edit-save-settings").bind("click", function() {
  12. if (!$("#edit-save-settings").attr("checked")) {
  13. $("div.backup-migrate-save-options").slideUp('slow');
  14. }
  15. else {
  16. // Save unchecked; enable input.
  17. $("div.backup-migrate-save-options").slideDown('slow');
  18. }
  19. });
  20. $('#backup-migrate-ui-manual-backup-form select[multiple], #backup-migrate-crud-edit-form select[multiple]').each(function() {
  21. $(this).after(
  22. $('<div class="description backup-migrate-checkbox-link"></div>').append(
  23. $('<a href="javascript:null(0);"></a>').text(Drupal.settings.backup_migrate.checkboxLinkText).click(function() {
  24. Drupal.backup_migrate.selectToCheckboxes($(this).parents('.form-item').find('select'));
  25. })
  26. )
  27. );
  28. }
  29. );
  30. }
  31. },
  32. selectToCheckboxes : function($select) {
  33. var field_id = $select.attr('id');
  34. var $checkboxes = $('<div></div>').addClass('backup-migrate-tables-checkboxes');
  35. $('option', $select).each(function(i) {
  36. var self = this;
  37. $box = $('<input type="checkbox" class="backup-migrate-tables-checkbox">').bind('change click', function() {
  38. $select.find('option[value="'+self.value+'"]').attr('selected', this.checked);
  39. if (this.checked) {
  40. $(this).parent().addClass('checked');
  41. }
  42. else {
  43. $(this).parent().removeClass('checked');
  44. }
  45. }).attr('checked', this.selected ? 'checked' : '');
  46. $checkboxes.append($('<div class="form-item"></div>').append($('<label class="option backup-migrate-table-select">'+this.value+'</label>').prepend($box)));
  47. });
  48. $select.parent().find('.backup-migrate-checkbox-link').remove();
  49. $select.before($checkboxes);
  50. $select.hide();
  51. }
  52. }
  53. $(document).ready(Drupal.backup_migrate.autoAttach);
  54. })(jQuery);