Fixed several bugs with adding permissions where checkboxes weren't checked properly or were disappearing when paging was involved.

This commit is contained in:
Michael Abashian 2016-06-09 17:45:02 -04:00
parent 6fb82c0dbd
commit 086fffe98c
3 changed files with 32 additions and 6 deletions

View File

@ -41,11 +41,11 @@
</div>
<div class="AddPermissions-list" ng-show="usersSelected">
<add-permissions-list type="users">
<add-permissions-list all-selected="allSelected" type="users">
</add-permissions-list>
</div>
<div class="AddPermissions-list" ng-show="teamsSelected">
<add-permissions-list type="teams">
<add-permissions-list all-selected="allSelected" type="teams">
</add-permissions-list>
</div>

View File

@ -13,6 +13,7 @@ export default
return {
restrict: 'E',
scope: {
allSelected: '='
},
template: "<div class='addPermissionsList-inner'></div>",
link: function(scope, element, attrs, ctrl) {
@ -50,6 +51,23 @@ export default
PaginateInit({ scope: scope,
list: list, url: url, pageSize: 5 });
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.removePostRefresh = scope.$on('PostRefresh', function () {
if(scope.allSelected && scope.allSelected.length > 0) {
// We need to check to see if any of the selected items are now in our list!
for(var i=0; i<scope.allSelected.length; i++) {
for(var j=0; j<scope[set].length; j++) {
if(scope.allSelected[i].id === scope[set][j].id && scope.allSelected[i].type === scope[set][j].type) {
// If so, let's go ahead and mark it as selected so that select-list-item knows to check the box
scope[set][j].isSelected = true;
}
}
}
}
});
scope.search(list.iterator);
});
}

View File

@ -33,8 +33,11 @@ export default
template: '<input type="checkbox" data-multi-select-list-item ng-model="isSelected" ng-change="userInteractionSelect()">',
link: function(scope, element, attrs, multiSelectList) {
scope.isSelected = false;
scope.decoratedItem = multiSelectList.registerItem(scope.item);
var initializeItem = function() {
scope.decoratedItem = multiSelectList.registerItem(scope.item);
scope.isSelected = scope.item.isSelected ? true : false;
scope.decoratedItem.isSelected = scope.item.isSelected ? true : false;
};
scope.$watch('isSelected', function(value) {
if (value === true) {
@ -44,8 +47,11 @@ export default
}
});
scope.$watch('decoratedItem.isSelected', function(value) {
scope.isSelected = value;
scope.$watch('item', function() {
// This is necessary for page changes where $scope.item gets updated via ng-repeat
// but this link function never gets triggered (and scope.decoratedItem) never
// gets updated.
initializeItem();
});
scope.$on('$destroy', function() {
@ -56,6 +62,8 @@ export default
scope.$emit("selectedOrDeselected", scope.decoratedItem);
};
initializeItem();
}
};
}];