1
|
(function ($) {
|
2
|
Drupal.behaviors.vbo = {
|
3
|
attach: function(context) {
|
4
|
$('.vbo-views-form', context).each(function() {
|
5
|
Drupal.vbo.initTableBehaviors(this);
|
6
|
Drupal.vbo.initGenericBehaviors(this);
|
7
|
});
|
8
|
}
|
9
|
}
|
10
|
|
11
|
Drupal.vbo = Drupal.vbo || {};
|
12
|
Drupal.vbo.initTableBehaviors = function(form) {
|
13
|
|
14
|
|
15
|
var selectAllMarkup = $('.vbo-table-select-all-markup', form);
|
16
|
if (selectAllMarkup.length) {
|
17
|
$('.views-table > tbody', form).prepend('<tr class="views-table-row-select-all even">></tr>');
|
18
|
var colspan = $('table th', form).length;
|
19
|
$('.views-table-row-select-all', form).html('<td colspan="' + colspan + '">' + selectAllMarkup.html() + '</td>');
|
20
|
|
21
|
$('.vbo-table-select-all-pages', form).click(function() {
|
22
|
Drupal.vbo.tableSelectAllPages(form);
|
23
|
return false;
|
24
|
});
|
25
|
$('.vbo-table-select-this-page', form).click(function() {
|
26
|
Drupal.vbo.tableSelectThisPage(form);
|
27
|
return false;
|
28
|
});
|
29
|
}
|
30
|
|
31
|
$('.vbo-table-select-all', form).show();
|
32
|
|
33
|
$('.vbo-table-select-all', form).click(function() {
|
34
|
var table = $(this).closest('table')[0];
|
35
|
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', table).attr('checked', this.checked);
|
36
|
|
37
|
|
38
|
if (this.checked) {
|
39
|
$('.views-table-row-select-all', table).show();
|
40
|
}
|
41
|
else {
|
42
|
$('.views-table-row-select-all', table).hide();
|
43
|
|
44
|
Drupal.vbo.tableSelectThisPage(form);
|
45
|
}
|
46
|
});
|
47
|
|
48
|
|
49
|
$('.views-table tbody tr', form).click(function(event) {
|
50
|
if (event.target.tagName.toLowerCase() != 'input' && event.target.tagName.toLowerCase() != 'a') {
|
51
|
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', this).each(function() {
|
52
|
var checked = this.checked;
|
53
|
|
54
|
|
55
|
|
56
|
|
57
|
|
58
|
this.checked = !checked;
|
59
|
$(this).trigger('click');
|
60
|
this.checked = !checked;
|
61
|
});
|
62
|
}
|
63
|
});
|
64
|
}
|
65
|
|
66
|
Drupal.vbo.tableSelectAllPages = function(form) {
|
67
|
$('.vbo-table-this-page', form).hide();
|
68
|
$('.vbo-table-all-pages', form).show();
|
69
|
|
70
|
$('.select-all-rows', form).val('1');
|
71
|
}
|
72
|
Drupal.vbo.tableSelectThisPage = function(form) {
|
73
|
$('.vbo-table-all-pages', form).hide();
|
74
|
$('.vbo-table-this-page', form).show();
|
75
|
|
76
|
$('.select-all-rows', form).val('0');
|
77
|
}
|
78
|
|
79
|
Drupal.vbo.initGenericBehaviors = function(form) {
|
80
|
|
81
|
$('.vbo-select-all-markup', form).show();
|
82
|
|
83
|
$('.vbo-select-this-page', form).click(function() {
|
84
|
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked);
|
85
|
$('.vbo-select-all-pages', form).attr('checked', false);
|
86
|
|
87
|
|
88
|
$('.vbo-table-select-all', form).attr('checked', this.checked);
|
89
|
});
|
90
|
$('.vbo-select-all-pages', form).click(function() {
|
91
|
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked);
|
92
|
$('.vbo-select-this-page', form).attr('checked', false);
|
93
|
|
94
|
|
95
|
$('.vbo-table-select-all', form).attr('checked', this.checked);
|
96
|
|
97
|
|
98
|
$('.select-all-rows', form).val(this.checked);
|
99
|
});
|
100
|
|
101
|
$('.vbo-select', form).click(function() {
|
102
|
|
103
|
if (!this.checked) {
|
104
|
$('.vbo-select-this-page', form).attr('checked', false);
|
105
|
$('.vbo-select-all-pages', form).attr('checked', false);
|
106
|
|
107
|
$('.select-all-rows', form).val('0')
|
108
|
|
109
|
var table = $(this).closest('table')[0];
|
110
|
if (table) {
|
111
|
|
112
|
$('.vbo-table-select-all', table).attr('checked', false);
|
113
|
|
114
|
|
115
|
if ($('.vbo-table-select-this-page', table).length) {
|
116
|
$('.views-table-row-select-all', table).hide();
|
117
|
|
118
|
Drupal.vbo.tableSelectThisPage(form);
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
});
|
123
|
}
|
124
|
|
125
|
})(jQuery);
|