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

Commit

Permalink
Fixes #1311
Browse files Browse the repository at this point in the history
Handling the addition of "bulk actions". Now when multiple items are selected returns all items with each items properties and the item itself.

Updating test for change in returned action obj

Make repeater actions have pointer cursor
Fixes #1411

Had to make a few changes to deal with the new additions within multi select. Added support for just selected instead of multi-selected.
  • Loading branch information
BenjaminNeilDavis committed Jul 28, 2015
1 parent e6972bd commit 733bb8e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 28 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,9 @@ define(function (require) {
dataSource: function (options, callback) {
list(options, callback);
},
list_selectable: 'multi'
list_selectable: 'multi',
list_columnSizing:false,
list_columnSyncing: false
},
'thumbnail': {
dataSource: function (options, callback) {
Expand Down Expand Up @@ -750,6 +752,7 @@ define(function (require) {
repeaterActions.repeater({
list_noItemsHTML: '<span>foo</span>',
list_highlightSortedColumn: true,
list_selectable: 'multi',
list_actions: {
width: 37,
items: [
Expand Down
46 changes: 33 additions & 13 deletions js/repeater-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,28 +291,48 @@
this.$element.find('.repeater-list table.table-actions tr').each(function (i, elem) {
$(this).height($table.find('tr:eq(' + i + ')').height());
});

this.$element.find('.table-actions .action-item').on('click', function() {
//row level actions click
this.$element.find('.table-actions tbody .action-item').on('click', function() {
var actionName = $(this).data('action');
var row = $(this).data('row');
self.list_getActionItems(actionName,row);
var selected = {
actionName: actionName,
rows: [row]
};
self.list_getActionItems(selected);
});
// bulk actions click
this.$element.find('.table-actions thead .action-item').on('click', function() {
var actionName = $(this).data('action');
var selected = {
actionName: actionName,
rows: []
};
self.$element.find('.repeater-list-wrapper > table .selected').each(function() {
var index = $(this).index();
index = index + 1;
selected.rows.push(index);
});
self.list_getActionItems(selected);
});

};

$.fn.repeater.Constructor.prototype.list_getActionItems = function (actionName, row) {

var clickedRow = this.$canvas.find('.repeater-list-wrapper > table tbody tr:nth-child('+ row +')');

$.fn.repeater.Constructor.prototype.list_getActionItems = function (selected) {
var i;
var selectedObj = [];
var actionObj = $.grep(this.viewOptions.list_actions.items, function(actions){
return actions.name === actionName;
return actions.name === selected.actionName;
})[0];

if (actionObj.clickAction) {
actionObj.clickAction({
for (i = 0; i < selected.rows.length; i++) {
var clickedRow = this.$canvas.find('.repeater-list-wrapper > table tbody tr:nth-child('+ selected.rows[i] +')');
selectedObj.push({
item: clickedRow,
rowData: clickedRow.data('item_data')
}, function () {});
});
}

if (actionObj.clickAction) {
actionObj.clickAction(selectedObj, function () {});
}
};

Expand Down
11 changes: 10 additions & 1 deletion less/repeater-list.less
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@
.repeater-list-heading {
padding: 8px 0 7px;
border-left: 1px solid @gray98;
margin-left: -1px;
margin-left: -9px;
width: 100%;
.btn-group {
padding-left: 8px;
}
}
}
}
Expand Down Expand Up @@ -389,6 +392,12 @@
}
}
}

&.multi-select-enabled.actions-enabled {
.repeater-list .actions-column-wrapper table.table-actions tr th .repeater-list-heading {
border-left: 1px solid @gray87
}
}
}

.repeater-loader {
Expand Down
25 changes: 12 additions & 13 deletions test/repeater-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ define(function(require){
this.$markup = $(html);
this.$markup.find('.repeater-views').append('' +
'<label class="btn btn-default active">' +
'<input name="repeaterViews" type="radio" value="list">' +
'<span class="glyphicon glyphicon-list"></span>' +
'<input name="repeaterViews" type="radio" value="list">' +
'<span class="glyphicon glyphicon-list"></span>' +
'</label>');
}
});
Expand Down Expand Up @@ -157,7 +157,7 @@ define(function(require){

$repeater.on('loaded.fu.repeater', function(e, options){
count++;

switch(count){
case 1:
$first = $repeater.find('.repeater-list thead .repeater-list-heading:first');
Expand Down Expand Up @@ -198,7 +198,7 @@ define(function(require){

$repeater.on('loaded.fu.repeater', function(){
count++;

switch(count){
case 1:
$repeater.find('.repeater-list thead th:nth-child(1) .repeater-list-heading').click();
Expand Down Expand Up @@ -296,7 +296,7 @@ define(function(require){

$firstRow.click();
$lastRow.click();

setTimeout(function(){
start();
$repeater.repeater('list_clearSelectedItems');
Expand All @@ -321,7 +321,7 @@ define(function(require){

$firstRow.click();
$lastRow.click();

setTimeout(function(){
start();
selected = $repeater.repeater('list_getSelectedItems');
Expand All @@ -345,15 +345,15 @@ define(function(require){

setTimeout(function(){
start();

$repeater.repeater('list_setSelectedItems', [{ index: 0 }]);
equal($repeater.repeater('list_getSelectedItems').length, 1, 'correct number of items selected');
equal($items.find('tr:first').hasClass('selected'), true, 'correct row selected by index');

$repeater.repeater('list_setSelectedItems', [{ property: 'commonName', value: 'pig' }]);
equal($repeater.repeater('list_getSelectedItems').length, 1, 'correct number of items selected');
equal($items.find('tr:nth-child(5)').hasClass('selected'), true, 'correct row selected by property/value');

$repeater.repeater('list_setSelectedItems', [{ index: 0 }, { property: 'commonName', value: 'dog' }], true);
equal($repeater.repeater('list_getSelectedItems').length, 4, 'correct number of items selected when using force');
}, 0);
Expand Down Expand Up @@ -413,16 +413,15 @@ define(function(require){
ok($actionsTable.find('tbody tr:first-child .btn-group').hasClass('open'), 'Actions dropdown opens on click');

$actionItem.click();

}, 0);

});

function testClickAction(helpers) {
equal((typeof helpers === 'object' && helpers.item.length > 0), true, 'Items in row were returned after action click');
equal((typeof helpers === 'object' && helpers.length > 0), true, 'Items in row were returned after action click');
var count = 0;
for (var k in helpers.rowData) {
if (helpers.rowData.hasOwnProperty(k)) {
for (var k in helpers[0].rowData) {
if (helpers[0].rowData.hasOwnProperty(k)) {
++count;
}
}
Expand Down

0 comments on commit 733bb8e

Please sign in to comment.