Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
adds indeterminate state to repeaters checkall checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason.Gekeler committed Apr 20, 2016
1 parent d826662 commit ddda5d0
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions js/repeater-list.js
Expand Up @@ -421,7 +421,10 @@

$checkboxes.checkbox();

this.$element.find('.table-frozen tbody .checkbox-inline').on('change', function(e) {
// Row checkboxes
var $rowCheckboxes = this.$element.find('.table-frozen tbody .checkbox-inline');
var $checkAll = this.$element.find('.frozen-thead-wrapper thead .checkbox-inline input');
$rowCheckboxes.on('change', function(e) {
e.preventDefault();

if (!self.list_revertingCheckbox) {
Expand All @@ -431,11 +434,26 @@
var row = $(this).attr('data-row');
row = parseInt(row) + 1;
self.$element.find('.repeater-list-wrapper > table tbody tr:nth-child('+ row +')').click();

var numSelected = self.$element.find('.table-frozen tbody .checkbox-inline.checked').length;
if(numSelected === 0){
$checkAll.prop('checked', false);
$checkAll.prop('indeterminate', false);
}
else if (numSelected === $rowCheckboxes.length){
$checkAll.prop('checked', true);
$checkAll.prop('indeterminate', false);
}
else {
$checkAll.prop('checked', false);
$checkAll.prop('indeterminate', true);
}
}
}
});

this.$element.find('.frozen-thead-wrapper thead .checkbox input').on('change', function (e) {
// "Check All" checkbox
$checkAll.on('change', function (e) {
if (!self.list_revertingCheckbox) {
if (self.isDisabled) {
revertCheckbox($(e.currentTarget));
Expand Down Expand Up @@ -662,7 +680,7 @@
var chevUp = 'glyphicon-chevron-up';
var $div = $('<div class="repeater-list-heading"><span class="glyphicon rlc"></span></div>');
var checkAllID = (this.$element.attr('id')+'_' || '') + 'checkall';
var checkBoxMarkup = '<div class="repeater-list-heading header-checkbox"><div class="checkbox"><input type="checkbox" id="' + checkAllID + '">'+
var checkBoxMarkup = '<div class="repeater-list-heading header-checkbox"><div class="checkbox checkbox-inline"><input type="checkbox" id="' + checkAllID + '">'+
'<label for="' + checkAllID + '"></label></div></div>';
var $header = $('<th></th>');
var self = this;
Expand Down Expand Up @@ -774,7 +792,7 @@
if ($item.is('.selected')) {
$item.removeClass('selected');
if (isMulti){
$checkBox.checkbox('uncheck');
$checkBox.click();
$frozenRow.removeClass('selected');
if (isActions) {
$actionsRow.removeClass('selected');
Expand All @@ -797,7 +815,7 @@
$frozenRow.addClass('selected');
}
else {
$checkBox.checkbox('check');
$checkBox.click();
$item.addClass('selected');
$frozenRow.addClass('selected');
if (isActions) {
Expand Down

0 comments on commit ddda5d0

Please sign in to comment.