-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeatures.js
104 lines (98 loc) · 3.71 KB
/
features.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
Drupal.behaviors.features = function() {
// Features management form package tabs
$("ul#features-form-links li a:not(.features-processed)").each(function() {
$(this).addClass('features.processed').click(function() {
$(".features-package-active").removeClass('features-package-active');
var panel = $(this).attr('href').split('#')[1];
$("div.package-" + panel).addClass('features-package-active');
$(this).addClass('features-package-active');
return false;
});
});
// Features management form
$('table.features:not(.processed)').addClass('processed').each(function() {
// Check the overridden status of each feature
Drupal.features.checkStatus();
// Add some nicer row hilighting when checkboxes change values
$('input', this).bind('change', function() {
if (!$(this).attr('checked')) {
$(this).parents('tr').removeClass('enabled').addClass('disabled');
}
else {
$(this).parents('tr').addClass('enabled').removeClass('disabled');
}
});
});
// Export form component selector
$('form.features-export-form select.features-select-components:not(.processed)').each(function() {
$(this)
.addClass('processed')
.change(function() {
var target = $(this).val();
$('div.features-select').hide();
$('div.features-select-' + target).show();
return false;
});
});
// Export form machine-readable JS
$('.feature-name:not(.processed)').each(function() {
$('.feature-name')
.addClass('processed')
.after(' <small class="feature-module-name-suffix"> </small>');
if ($('.feature-module-name').val() === $('.feature-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('.feature-module-name').val() === '') {
$('.feature-module-name').parents('.form-item').hide();
$('.feature-name').bind('keyup change', function() {
var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_');
if (machine !== '_' && machine !== '') {
$('.feature-module-name').val(machine);
$('.feature-module-name-suffix').empty().append(' Machine name: ' + machine + ' [').append($('<a href="#">'+ Drupal.t('Edit') +'</a>').click(function() {
$('.feature-module-name').parents('.form-item').show();
$('.feature-module-name-suffix').hide();
$('.feature-name').unbind('keyup');
return false;
})).append(']');
}
else {
$('.feature-module-name').val(machine);
$('.feature-module-name-suffix').text('');
}
});
$('.feature-name').keyup();
}
});
};
Drupal.features = {
'checkStatus': function() {
if ($('table.features').is('.loading')) {
return;
}
$('table.features tbody tr:not(.processed):first').addClass('processed').each(function() {
var uri = $(this).find('a.admin-check').attr('href'), elem = $(this);
if (uri) {
$('table.features').addClass('loading');
$.get(uri, [], function(data) {
$(elem).find('.admin-loading').hide();
switch (data.storage) {
case 3:
$(elem).find('.admin-rebuilding').show();
break;
case 2:
$(elem).find('.admin-needs-review').show();
break;
case 1:
$(elem).find('.admin-overridden').show();
break;
default:
$(elem).find('.admin-default').show();
break;
}
$('table.features').removeClass('loading');
Drupal.features.checkStatus();
}, 'json');
}
else {
Drupal.features.checkStatus();
}
});
}
};