diff --git a/ui/src/main/resources/FileManagerCode/LiveTable.xml b/ui/src/main/resources/FileManagerCode/LiveTable.xml index 4d9b725..8b46e15 100644 --- a/ui/src/main/resources/FileManagerCode/LiveTable.xml +++ b/ui/src/main/resources/FileManagerCode/LiveTable.xml @@ -65,7 +65,9 @@ </th> </tr> <tr class="xwiki-livetable-display-filters"> - <td ng-if="selection" class="xwiki-livetable-display-header-filter"></td> + <td class="xwiki-livetable-display-header-filter"> + <input type="checkbox" ng-model="checkedAll" ng-indeterminate="indeterminate" /> + </td> <td ng-repeat="column in columns" class="xwiki-livetable-display-header-filter"> <div ng-if="column.filterable" ng-include="liveTableFilterTemplate"></div> </td> @@ -280,6 +282,32 @@ } }; + scope.$watch('checkedAll', function(newValue, oldValue) { + angular.forEach(scope.rows.list, function(rowItem) { + scope.selection[rowItem.id] = newValue; + }); + }, true); + + // synchronize the master checkbox and the rest of the checkboxes. + scope.$watch('[rows.list,selection]', function() { + var checkedCount = 0; + angular.forEach(scope.rows.list, function(rowItem) { + if(scope.selection[rowItem.id] == true){ + checkedCount++; + } + }); + if(checkedCount == 0){ + scope.indeterminate = false; + scope.checkedAll = false; + }else if(checkedCount == scope.rows.list.length){ + scope.indeterminate = false; + scope.checkedAll = true; + }else { + scope.indeterminate = true; + } + }, true); + + // The live table filters should not trigger an update immediately, but after a delay. We achieve this by // deferring the update when the filters are changed and by cancelling the pending update whenever a new change // is detected. @@ -320,6 +348,17 @@ } } }); + + liveTable.directive('ngIndeterminate', function() { + return { + restrict: 'A', + link: function(scope, element, attributes) { + scope.$watch(attributes['ngIndeterminate'], function (value) { + element.prop('indeterminate', !!value); + }); + } + }; + }); });