From 7fe57fca44a6046ef968e40541789b9648785426 Mon Sep 17 00:00:00 2001 From: Lyes BANDOU Date: Fri, 3 Oct 2014 11:20:28 +0100 Subject: [PATCH 1/2] FILEMAN-44: Add a checkbox on top of others to check them all --- .../resources/FileManagerCode/LiveTable.xml | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/ui/src/main/resources/FileManagerCode/LiveTable.xml b/ui/src/main/resources/FileManagerCode/LiveTable.xml index 4d9b725..9ec1848 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" id="cbxall" ng-model="checkedAll" /> + </td> <td ng-repeat="column in columns" class="xwiki-livetable-display-header-filter"> <div ng-if="column.filterable" ng-include="liveTableFilterTemplate"></div> </td> @@ -266,6 +268,9 @@ // Update the live table whenever the parameters are modified. scope.$watch('params', function(newValue, oldValue) { + if(newValue.offset != oldValue.offset){ + scope.selection = {}; + } storeParams(scope.id, newValue); scope.rows = scope.source.get(newValue); }, true); @@ -280,6 +285,33 @@ } }; + 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('selection', function(newValue, oldValue) { + var checkedCount = 0; + angular.forEach(scope.selection, function(key, value) { + if(key == true){ + checkedCount++; + } + }); + var cbxall = document.getElementById("cbxall"); + if(checkedCount == 0){ + cbxall.indeterminate = false; + scope.checkedAll = false; + }else if(checkedCount == scope.rows.list.length){ + cbxall.indeterminate = false; + scope.checkedAll = true; + }else { + cbxall.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. From 5370fb6d16c4c1accff7b7af34e0afd68864ba79 Mon Sep 17 00:00:00 2001 From: Lyes BANDOU Date: Tue, 7 Oct 2014 11:50:11 +0100 Subject: [PATCH 2/2] FILEMAN-44: Add a checkbox on top of others to check them all * Improve checkboxes synchronization. * Create ngIndeterminate directive. --- .../resources/FileManagerCode/LiveTable.xml | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ui/src/main/resources/FileManagerCode/LiveTable.xml b/ui/src/main/resources/FileManagerCode/LiveTable.xml index 9ec1848..8b46e15 100644 --- a/ui/src/main/resources/FileManagerCode/LiveTable.xml +++ b/ui/src/main/resources/FileManagerCode/LiveTable.xml @@ -66,7 +66,7 @@ </tr> <tr class="xwiki-livetable-display-filters"> <td class="xwiki-livetable-display-header-filter"> - <input type="checkbox" id="cbxall" ng-model="checkedAll" /> + <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> @@ -268,9 +268,6 @@ // Update the live table whenever the parameters are modified. scope.$watch('params', function(newValue, oldValue) { - if(newValue.offset != oldValue.offset){ - scope.selection = {}; - } storeParams(scope.id, newValue); scope.rows = scope.source.get(newValue); }, true); @@ -292,22 +289,21 @@ }, true); // synchronize the master checkbox and the rest of the checkboxes. - scope.$watch('selection', function(newValue, oldValue) { + scope.$watch('[rows.list,selection]', function() { var checkedCount = 0; - angular.forEach(scope.selection, function(key, value) { - if(key == true){ + angular.forEach(scope.rows.list, function(rowItem) { + if(scope.selection[rowItem.id] == true){ checkedCount++; } }); - var cbxall = document.getElementById("cbxall"); if(checkedCount == 0){ - cbxall.indeterminate = false; + scope.indeterminate = false; scope.checkedAll = false; }else if(checkedCount == scope.rows.list.length){ - cbxall.indeterminate = false; + scope.indeterminate = false; scope.checkedAll = true; }else { - cbxall.indeterminate = true; + scope.indeterminate = true; } }, true); @@ -352,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); + }); + } + }; + }); });