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
/* =========================================================
* rewritten by Amr Bedair <amr.bedair@gmail.com>
* @since booster v4.0.0-beta-2
*
* ========================================================= */
(function($){
var checkedItems = [];
/**
* Init events for Bulk Actions
* @param id string the ID of the grid view container
*/
$.fn.yiiGridView.initBulkActions = function (id) {
$(document).on("click change", "#"+id+" input[type=checkbox]", function() {
var grid = $('#'+id);
if ($("#"+id+' tbody input[type=checkbox]:checked').length) {
$(".bulk-actions-btn", grid).removeClass("disabled");
$("div.bulk-actions-blocker", grid).hide();
} else {
$(".bulk-actions-btn", grid).addClass("disabled");
$("div.bulk-actions-blocker", grid).show();
}
});
};
/**
* Updating checkboxes after grid ajax updating
* @param id string the ID of the grid view container
*/
$.fn.yiiGridView.afterUpdateGrid = function (id) {
if ($("#"+id+' tbody input[type=checkbox]:checked').length) {
var grid = $('#'+id);
$(".bulk-actions-btn", grid).removeClass("disabled");
$("div.bulk-actions-blocker", grid).hide();
$.each($("#"+id+' tbody input[type=checkbox]:checked'), function(index, item) {
var row = $("input[value="+item+"]", grid);
if (!row.is(':checked'))
row.attr("checked", "checked");
});
}
};
/**
* Returns array of checked items ids
* @returns {Array}
*/
$.fn.yiiGridView.getCheckedRowsIds = function (id) {
return $("#"+id+' tbody input[type=checkbox]:checked').map(function() { return $(this).val(); }).get();
}
})(jQuery);