Add support for shift key selection in checkable items

Fixes #1389
This commit is contained in:
Joseph Schorr 2016-04-20 15:25:20 -04:00
parent 7239c465bf
commit da4c658bde
3 changed files with 40 additions and 4 deletions

View file

@ -12,6 +12,8 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
this.itemKey_ = itemKey;
this.listeners_ = [];
this.page_ = null;
this.lastChanged_ = null;
this.ApiService = ApiService
};
@ -23,7 +25,28 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
return !!this.allCheckedMap_[item[this.itemKey_]];
};
CheckStateController.prototype.toggleItem = function(item) {
CheckStateController.prototype.toggleItem = function(item, opt_shift) {
if (opt_shift && this.lastChanged_) {
var itemIndex = $.inArray(item, this.items);
var lastIndex = $.inArray(this.lastChanged_, this.items);
if (itemIndex >= 0 && lastIndex >= 0) {
var startIndex = Math.min(itemIndex, lastIndex);
var endIndex = Math.max(itemIndex, lastIndex);
var shouldCheck = this.isChecked(this.lastChanged_);
for (var i = startIndex; i <= endIndex; ++i) {
if (shouldCheck) {
this.checkItem(this.items[i]);
} else {
this.uncheckItem(this.items[i]);
}
}
return;
}
}
if (this.isChecked(item)) {
this.uncheckItem(item);
} else {
@ -32,6 +55,7 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
};
CheckStateController.prototype.toggleItems = function() {
this.lastChanged_= null;
this.updateMap_(this.checked, false);
if (this.checked.length) {
@ -83,12 +107,22 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
};
CheckStateController.prototype.checkItem = function(item) {
if (this.isChecked(item)) {
return;
}
this.lastChanged_ = item;
this.checked.push(item);
this.allCheckedMap_[item[this.itemKey_]] = true;
this.callListeners_();
};
CheckStateController.prototype.uncheckItem = function(item) {
if (!this.isChecked(item)) {
return;
}
this.lastChanged_ = item;
this.checked = $.grep(this.checked, function(cItem) {
return cItem != item;
});