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

Commit

Permalink
Fixes disabling of selectable / multi select / actions
Browse files Browse the repository at this point in the history
Fixes #1534
  • Loading branch information
BenjaminNeilDavis committed Sep 25, 2015
1 parent 41f1eeb commit bb5b523
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 26 deletions.
2 changes: 2 additions & 0 deletions js/repeater-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@
if (sortable) {
$both.addClass('sortable');
$div.on('click.fu.repeaterList', function () {
if(self.isDisabled) { return; }
self.list_sortProperty = (typeof sortable === 'string') ? sortable : columns[index].property;
if ($div.hasClass('sorted')) {
if ($span.hasClass(chevUp)) {
Expand Down Expand Up @@ -655,6 +656,7 @@
$row.data('item_data', rows[index]);

$row.on('click.fu.repeaterList', function () {
if(self.isDisabled) { return; }
var $item = $(this);
var index = $(this).index();
index = index + 1;
Expand Down
11 changes: 11 additions & 0 deletions js/repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
this.infiniteScrollingEnabled = false;
this.infiniteScrollingEnd = null;
this.infiniteScrollingOptions = {};
this.isDisabled = false;
this.lastPageInput = 0;
this.options = $.extend({}, $.fn.repeater.defaults, options);
this.pageIncrement = 0;// store direction navigated
Expand Down Expand Up @@ -218,6 +219,7 @@
var disable = 'disable';
var disabled = 'disabled';

this.isDisabled = true;
this.$search.search(disable);
this.$filters.selectlist(disable);
this.$views.find('label').attr(disabled, disabled);
Expand All @@ -227,6 +229,14 @@
this.$prevBtn.attr(disabled, disabled);
this.$nextBtn.attr(disabled, disabled);

if(this.options.list_actions) {
this.$element.find('.actions-column-wrapper button').attr(disabled, disabled);
}
if(this.options.list_selectable === 'multi') {
this.$element.find('.checkbox-custom').checkbox(disable);
}


this.$element.addClass('disabled');
this.$element.trigger('disabled.fu.repeater');
},
Expand All @@ -236,6 +246,7 @@
var enable = 'enable';
var pageEnd = 'page-end';

this.isDisabled = false;
this.$search.search(enable);
this.$filters.selectlist(enable);
this.$views.find('label').removeAttr(disabled);
Expand Down
5 changes: 5 additions & 0 deletions less/repeater.less
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
line-height: 34px;
margin-right: 10px;
}
&.disabled {
*:hover {
cursor: not-allowed !important;
}
}

/*
* reinforce spacing around control buttons
Expand Down
58 changes: 32 additions & 26 deletions test/repeater-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,40 @@ define(function(require){
var count = 0;
var $first;

$repeater.on('rendered.fu.repeater', function(e, data){
setTimeout(function(){
$repeater.repeater('enable');
var options = data.options;
count++;
switch(count){
case 1:
$first = $repeater.find('.repeater-list thead .repeater-list-heading:first');
$first.click();
break;
case 2:
equal(($first.hasClass('sorted') && $first.find('span').hasClass('glyphicon-chevron-up')), true, 'asc sorted header has appropriate class and icon');
equal(options.sortDirection, 'asc', 'dataSource passed appropriate sortDirection value');
equal(options.sortProperty, 'commonName', 'dataSource passed appropriate sortProperty value');
$first.click();
break;
case 3:
equal(($first.hasClass('sorted') && $first.find('span').hasClass('glyphicon-chevron-down')), true, 'desc sorted header has appropriate class and icon');
equal(options.sortDirection, 'desc', 'dataSource passed appropriate sortDirection value');
equal(options.sortProperty, 'commonName', 'dataSource passed appropriate sortProperty value');
$first.click();
break;
case 4:
equal($first.hasClass('sorted'), false, 'previously sorted header reverted to non-sorted');
equal(options.sortDirection, undefined, 'dataSource passed appropriate sortDirection value');
equal(options.sortProperty, undefined, 'dataSource passed appropriate sortProperty value');
$repeater.off('loaded.fu.repeater');
start();
break;
}
}, 0);
});
$repeater.on('loaded.fu.repeater', function(e, options){
count++;

switch(count){
case 1:
$first = $repeater.find('.repeater-list thead .repeater-list-heading:first');
$first.click();
break;
case 2:
equal(($first.hasClass('sorted') && $first.find('span').hasClass('glyphicon-chevron-up')), true, 'asc sorted header has appropriate class and icon');
equal(options.sortDirection, 'asc', 'dataSource passed appropriate sortDirection value');
equal(options.sortProperty, 'commonName', 'dataSource passed appropriate sortProperty value');
$first.click();
break;
case 3:
equal(($first.hasClass('sorted') && $first.find('span').hasClass('glyphicon-chevron-down')), true, 'desc sorted header has appropriate class and icon');
equal(options.sortDirection, 'desc', 'dataSource passed appropriate sortDirection value');
equal(options.sortProperty, 'commonName', 'dataSource passed appropriate sortProperty value');
$first.click();
break;
case 4:
equal($first.hasClass('sorted'), false, 'previously sorted header reverted to non-sorted');
equal(options.sortDirection, undefined, 'dataSource passed appropriate sortDirection value');
equal(options.sortProperty, undefined, 'dataSource passed appropriate sortProperty value');
$repeater.off('loaded.fu.repeater');
start();
break;
}
});

$repeater.repeater({
Expand Down

0 comments on commit bb5b523

Please sign in to comment.