1
|
(function ($) {
|
2
|
|
3
|
if (typeof $.fn.prop != 'function') {
|
4
|
jQuery.fn.extend({
|
5
|
prop: jQuery.fn.attr
|
6
|
});
|
7
|
}
|
8
|
|
9
|
Drupal.behaviors.vbo = {
|
10
|
attach: function(context) {
|
11
|
$('.vbo-views-form', context).each(function() {
|
12
|
Drupal.vbo.initTableBehaviors(this);
|
13
|
Drupal.vbo.initGenericBehaviors(this);
|
14
|
Drupal.vbo.toggleButtonsState(this);
|
15
|
});
|
16
|
}
|
17
|
}
|
18
|
|
19
|
Drupal.vbo = Drupal.vbo || {};
|
20
|
Drupal.vbo.initTableBehaviors = function(form) {
|
21
|
|
22
|
|
23
|
var selectAllMarkup = $('.vbo-table-select-all-markup', form);
|
24
|
if (selectAllMarkup.length) {
|
25
|
$('.views-table > tbody', form).prepend('<tr class="views-table-row-select-all even">></tr>');
|
26
|
var colspan = $('table th', form).length;
|
27
|
$('.views-table-row-select-all', form).html('<td colspan="' + colspan + '">' + selectAllMarkup.html() + '</td>');
|
28
|
|
29
|
$('.vbo-table-select-all-pages', form).click(function() {
|
30
|
Drupal.vbo.tableSelectAllPages(form);
|
31
|
return false;
|
32
|
});
|
33
|
$('.vbo-table-select-this-page', form).click(function() {
|
34
|
Drupal.vbo.tableSelectThisPage(form);
|
35
|
return false;
|
36
|
});
|
37
|
}
|
38
|
|
39
|
$('.vbo-table-select-all', form).show();
|
40
|
|
41
|
$('input.vbo-table-select-all', form).click(function() {
|
42
|
var table = $(this).closest('table:not(.sticky-header)')[0];
|
43
|
$('.vbo-select:not(:disabled)', table).prop('checked', this.checked);
|
44
|
Drupal.vbo.toggleButtonsState(form);
|
45
|
|
46
|
|
47
|
if (this.checked) {
|
48
|
$('.views-table-row-select-all', table).show();
|
49
|
}
|
50
|
else {
|
51
|
$('.views-table-row-select-all', table).hide();
|
52
|
|
53
|
Drupal.vbo.tableSelectThisPage(form);
|
54
|
}
|
55
|
});
|
56
|
|
57
|
|
58
|
if (Drupal.settings.vbo.row_clickable) {
|
59
|
$('.views-table tbody tr', form).click(function(event) {
|
60
|
var tagName = event.target.tagName.toLowerCase();
|
61
|
if (tagName != 'input' && tagName != 'a' && tagName != 'label') {
|
62
|
$('.vbo-select:not(:disabled)', this).each(function() {
|
63
|
|
64
|
|
65
|
this.checked = $(this).is(':radio') ? true : !this.checked;
|
66
|
$(this).trigger('change');
|
67
|
});
|
68
|
}
|
69
|
});
|
70
|
}
|
71
|
}
|
72
|
|
73
|
Drupal.vbo.tableSelectAllPages = function(form) {
|
74
|
$('.vbo-table-this-page', form).hide();
|
75
|
$('.vbo-table-all-pages', form).show();
|
76
|
|
77
|
$('.select-all-rows', form).val('1');
|
78
|
}
|
79
|
Drupal.vbo.tableSelectThisPage = function(form) {
|
80
|
$('.vbo-table-all-pages', form).hide();
|
81
|
$('.vbo-table-this-page', form).show();
|
82
|
|
83
|
$('.select-all-rows', form).val('0');
|
84
|
}
|
85
|
|
86
|
Drupal.vbo.initGenericBehaviors = function(form) {
|
87
|
|
88
|
$('.vbo-select-all-markup', form).show();
|
89
|
|
90
|
$('.vbo-select-this-page', form).click(function() {
|
91
|
$('.vbo-select', form).prop('checked', this.checked);
|
92
|
Drupal.vbo.toggleButtonsState(form);
|
93
|
$('.vbo-select-all-pages', form).prop('checked', false);
|
94
|
|
95
|
|
96
|
$('.vbo-table-select-all', form).prop('checked', this.checked);
|
97
|
});
|
98
|
$('.vbo-select-all-pages', form).click(function() {
|
99
|
$('.vbo-select', form).prop('checked', this.checked);
|
100
|
Drupal.vbo.toggleButtonsState(form);
|
101
|
$('.vbo-select-this-page', form).prop('checked', false);
|
102
|
|
103
|
|
104
|
$('.vbo-table-select-all', form).prop('checked', this.checked);
|
105
|
|
106
|
|
107
|
$('.select-all-rows', form).val(this.checked);
|
108
|
});
|
109
|
|
110
|
|
111
|
|
112
|
$('select[name="operation"]', form).change(function () {
|
113
|
Drupal.vbo.toggleButtonsState(form);
|
114
|
});
|
115
|
|
116
|
|
117
|
$('.vbo-select', form).change(function() {
|
118
|
|
119
|
if (!this.checked) {
|
120
|
$('.vbo-select-this-page', form).prop('checked', false);
|
121
|
$('.vbo-select-all-pages', form).prop('checked', false);
|
122
|
|
123
|
$('.select-all-rows', form).val('0')
|
124
|
|
125
|
var table = $(this).closest('table')[0];
|
126
|
if (table) {
|
127
|
|
128
|
$('.vbo-table-select-all', table).prop('checked', false);
|
129
|
|
130
|
|
131
|
if ($('.vbo-table-select-this-page', table).length) {
|
132
|
$('.views-table-row-select-all', table).hide();
|
133
|
|
134
|
Drupal.vbo.tableSelectThisPage(form);
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
|
139
|
Drupal.vbo.toggleButtonsState(form);
|
140
|
});
|
141
|
}
|
142
|
|
143
|
Drupal.vbo.toggleButtonsState = function(form) {
|
144
|
|
145
|
var selectbox = $('select[name="operation"]', form);
|
146
|
var checkedCheckboxes = $('.vbo-select:checked', form);
|
147
|
|
148
|
|
149
|
var buttons = $('[id^="edit-select"] [type="submit"]:not(.vbo-prevent-toggle)', form);
|
150
|
|
151
|
if (selectbox.length) {
|
152
|
var has_selection = checkedCheckboxes.length && selectbox.val() !== '0';
|
153
|
buttons.prop('disabled', !has_selection);
|
154
|
}
|
155
|
else {
|
156
|
buttons.prop('disabled', !checkedCheckboxes.length);
|
157
|
}
|
158
|
};
|
159
|
|
160
|
})(jQuery);
|