BUGFIX: different behavior when multiple selected and just one row selected

pull/2595/head
Nicolai Moraru 10 years ago
parent 33322e3f37
commit 17490cb46b
  1. 24
      frontend/app/work_packages/directives/work-packages-table-directive.js

@ -75,7 +75,7 @@ module.exports = function(I18n, WorkPackagesTableService, $window, $timeout, fla
function getBackgrounds() { function getBackgrounds() {
return element.find('.work-packages-table--header-background,' + return element.find('.work-packages-table--header-background,' +
'.work-packages-table--footer-background'); '.work-packages-table--footer-background');
} }
function getHeadersFooters() { function getHeadersFooters() {
@ -89,7 +89,7 @@ module.exports = function(I18n, WorkPackagesTableService, $window, $timeout, fla
function setTableContainerWidths() { function setTableContainerWidths() {
// adjust overall containers // adjust overall containers
var tableWidth = getTable().width(), var tableWidth = getTable().width(),
scrollBarWidth = 16; scrollBarWidth = 16;
// account for a possible scrollbar // account for a possible scrollbar
if (tableWidth > document.documentElement.clientWidth - scrollBarWidth) { if (tableWidth > document.documentElement.clientWidth - scrollBarWidth) {
@ -167,7 +167,7 @@ module.exports = function(I18n, WorkPackagesTableService, $window, $timeout, fla
}).indexOf(groupBy); }).indexOf(groupBy);
scope.groupByColumn = groupableColumns[groupByColumnIndex]; scope.groupByColumn = groupableColumns[groupByColumnIndex];
} }
}); });
scope.$watch(function() { scope.$watch(function() {
@ -179,10 +179,10 @@ module.exports = function(I18n, WorkPackagesTableService, $window, $timeout, fla
// Thanks to http://stackoverflow.com/a/880518 // Thanks to http://stackoverflow.com/a/880518
function clearSelection() { function clearSelection() {
if(document.selection && document.selection.empty) { if(document.selection && document.selection.empty) {
document.selection.empty(); document.selection.empty();
} else if(window.getSelection) { } else if(window.getSelection) {
var sel = window.getSelection(); var sel = window.getSelection();
sel.removeAllRanges(); sel.removeAllRanges();
} }
} }
@ -191,10 +191,18 @@ module.exports = function(I18n, WorkPackagesTableService, $window, $timeout, fla
WorkPackagesTableService.setRowSelection(row, selected); WorkPackagesTableService.setRowSelection(row, selected);
} }
function mulipleRowsChecked(){
var counter = 0;
for(var i = 0, l = scope.rows.length; i<l; i++)
if(scope.rows[i].checked){
if(++counter === 2) return true;
}
return false
}
scope.selectWorkPackage = function(row, $event) { scope.selectWorkPackage = function(row, $event) {
if ($event.target.type != 'checkbox') { if ($event.target.type != 'checkbox') {
var currentRowCheckState = row.checked; var currentRowCheckState = row.checked;
var index = scope.rows.indexOf(row);
if (!($event.ctrlKey || $event.shiftKey)) { if (!($event.ctrlKey || $event.shiftKey)) {
scope.setCheckedStateForAllRows(false); scope.setCheckedStateForAllRows(false);
@ -204,7 +212,7 @@ module.exports = function(I18n, WorkPackagesTableService, $window, $timeout, fla
clearSelection(); clearSelection();
activeSelectionBorderIndex = WorkPackagesTableService.selectRowRange(scope.rows, row, activeSelectionBorderIndex); activeSelectionBorderIndex = WorkPackagesTableService.selectRowRange(scope.rows, row, activeSelectionBorderIndex);
} else { } else {
setRowSelectionState(row, !currentRowCheckState); setRowSelectionState(row, mulipleRowsChecked() ? true : !currentRowCheckState);
scope.activationCallback({ id: row.object.id, force: false }); scope.activationCallback({ id: row.object.id, force: false });
} }

Loading…
Cancel
Save