From ed63f0c5cc26b9c2a38e12b0769d85205396eea0 Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Wed, 10 Jun 2015 16:31:25 -0400 Subject: [PATCH 1/4] Fixes #1311 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. Overwritting css class for actions dropdown menu to show glyphicons Fix to index view. Column sizing on Bad selector in multi-select-enabled if columnsyncing was not turned on Adding a check to see if there are actions selected or not. If none selected bluk actions is disabled. Center actions column and not using hard coded padding values Updating the selecting of rows / clicking on rows. Had to make a few changes to deal with the new additions within multi select. Added support for just selected instead of multi-selected. --- index.js | 1 + js/repeater-list.js | 129 +++++++++++++++++++++++-------------- less/repeater-list.less | 87 ++++++++++++++++--------- test/repeater-list-test.js | 25 ++++--- 4 files changed, 150 insertions(+), 92 deletions(-) diff --git a/index.js b/index.js index 2eed628f8..1bfa2dc71 100644 --- a/index.js +++ b/index.js @@ -750,6 +750,7 @@ define(function (require) { repeaterActions.repeater({ list_noItemsHTML: 'foo', list_highlightSortedColumn: true, + list_selectable: 'multi', list_actions: { width: 37, items: [ diff --git a/js/repeater-list.js b/js/repeater-list.js index a1d13fbc4..faba158db 100755 --- a/js/repeater-list.js +++ b/js/repeater-list.js @@ -264,6 +264,8 @@ // Dont show actions dropdown in header if not multi select if (this.viewOptions.list_selectable === 'multi') { $actionsColumn.find('thead tr').html('
' + selectlist + '
'); + //disable the header dropdown until an item is selected + $actionsColumn.find('thead .btn').attr('disabled', 'disabled'); } else { var label = this.viewOptions.list_actions.label || 'a'; @@ -291,28 +293,49 @@ 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 () {}); } }; @@ -322,35 +345,46 @@ $actionsTableHeading.outerHeight($table.find('thead th .repeater-list-heading').outerHeight()); }; - $.fn.repeater.Constructor.prototype.list_multiSelectInitialize = function () { + $.fn.repeater.Constructor.prototype.list_frozenOptionsInitialize = function () { var self = this; + var isFrozen = this.viewOptions.list_frozenColumns; + var isActions = this.viewOptions.list_actions; + var isMulti = this.viewOptions.list_selectable === 'multi'; + + var $checkboxes = this.$element.find('.frozen-column-wrapper .checkbox-inline'); + + var $everyTable = this.$element.find('.repeater-list table'); + - var $checkboxes = self.$element.find('.frozen-column-wrapper .checkbox-inline'); //Make sure if row is hovered that it is shown in frozen column as well this.$element.find('tr.selectable').on('mouseover mouseleave', function(e) { var index = $(this).index(); index = index + 1; if (e.type === 'mouseover'){ - self.$element.find('.repeater-list-wrapper > table tbody tr:nth-child('+ index +'), ' + - '.frozen-column-wrapper tbody tr:nth-child('+ index +')').addClass('hovered'); + $everyTable.find('tbody tr:nth-child('+ index +')').addClass('hovered'); } else { - self.$element.find('.repeater-list-wrapper > table tbody tr:nth-child('+ index +'), ' + - '.frozen-column-wrapper tbody tr:nth-child('+ index +')').removeClass('hovered'); + $everyTable.find('tbody tr:nth-child('+ index +')').removeClass('hovered'); } }); $checkboxes.checkbox(); + this.$element.find('.table-frozen tbody .checkbox-inline').on('change', function(e) { + e.preventDefault(); + var row = $(this).attr('data-row'); + row = parseInt(row) + 1; + self.$element.find('.repeater-list-wrapper > table tbody tr:nth-child('+ row +')').click(); + }); + this.$element.find('.frozen-thead-wrapper thead .checkbox-inline').on('change', function () { - var $checkboxes = self.$element.find('.frozen-column-wrapper .checkbox-inline'); if ($(this).checkbox('isChecked')){ - $checkboxes.checkbox('check'); + self.$element.find('.repeater-list-wrapper > table tbody tr:not(.selected)').click(); self.$element.trigger('selected.fu.repeaterList', $checkboxes); } else { - $checkboxes.checkbox('uncheck'); + self.$element.find('.repeater-list-wrapper > table tbody tr.selected').click(); self.$element.trigger('deselected.fu.repeaterList', $checkboxes); } }); @@ -456,10 +490,7 @@ if (this.viewOptions.list_frozenColumns || this.viewOptions.list_actions || this.viewOptions.list_selectable === 'multi') { this.list_positionColumns(); - } - - if (this.viewOptions.list_selectable === 'multi') { - this.list_multiSelectInitialize(); + this.list_frozenOptionsInitialize(); } if (this.viewOptions.list_columnSyncing) { @@ -498,16 +529,10 @@ $row.append($col); if (this.viewOptions.list_selectable === 'multi' && columns[columnIndex].property === '@_CHECKBOX_@') { - var checkBoxMarkup = '