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