diff --git a/app/modules/main/directives/helpers/mdtSelectAllRowsHandlerDirective.js b/app/modules/main/directives/helpers/mdtSelectAllRowsHandlerDirective.js index 6ccd775..15c965e 100644 --- a/app/modules/main/directives/helpers/mdtSelectAllRowsHandlerDirective.js +++ b/app/modules/main/directives/helpers/mdtSelectAllRowsHandlerDirective.js @@ -1,7 +1,7 @@ (function(){ 'use strict'; - function mdtSelectAllRowsHandlerDirective(){ + function mdtSelectAllRowsHandlerDirective($timeout){ return { restrict: 'A', scope: false, @@ -10,6 +10,20 @@ $scope.selectAllRows = false; $scope.$watch('selectAllRows', function(val){ + if($scope.initTable){ + $timeout(function(){ + $scope.initTable = false; + }, attrs.hideDelay); + }else{ + _.each(ctrl.dataStorage.storage, function(data){ + if(data.optionList.selected === false){ + val = true; + $('th md-checkbox').addClass('md-checked'); + return false; + } + }); + } + ctrl.dataStorage.setAllRowsSelected(val, $scope.isPaginationEnabled()); }); } diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index 64c0857..58f9156 100644 --- a/app/modules/main/directives/mdtTableDirective.js +++ b/app/modules/main/directives/mdtTableDirective.js @@ -145,6 +145,10 @@ controller: function mdtTable($scope){ var vm = this; + //set init scope to true for those that + //are using locationchanges + $scope.initTable = true; + $scope.rippleEffectCallback = function(){ return $scope.rippleEffect ? $scope.rippleEffect : false; }; diff --git a/app/modules/main/features/SelectableRowsFeature.js b/app/modules/main/features/SelectableRowsFeature.js index a50c564..c9a539e 100644 --- a/app/modules/main/features/SelectableRowsFeature.js +++ b/app/modules/main/features/SelectableRowsFeature.js @@ -1,17 +1,20 @@ (function(){ 'use strict'; - function SelectableRowsFeatureFactory($timeout){ + function SelectableRowsFeatureFactory($timeout, CheckBoxMgmtProvider){ function SelectableRowsFeature(params){ this.$scope = params.$scope; this.ctrl = params.ctrl; + SelectableRowsFeature.$inject = ["CheckBoxMgmtProvider"]; this.$scope.onCheckboxChange = _.bind(this.onCheckboxChange, this); } SelectableRowsFeature.prototype.onCheckboxChange = function(){ var that = this; + + CheckBoxMgmtProvider.getCheckOption(that.ctrl.dataStorage); // we need to push it to the event loop to make it happen last // (e.g.: all the elements can be selected before we call the callback) $timeout(function(){ @@ -31,4 +34,4 @@ angular .module('mdDataTable') .service('SelectableRowsFeature', SelectableRowsFeatureFactory); -}()); \ No newline at end of file +}()); diff --git a/app/modules/main/providers/CheckBoxMgmtProvider.js b/app/modules/main/providers/CheckBoxMgmtProvider.js new file mode 100644 index 0000000..29468e9 --- /dev/null +++ b/app/modules/main/providers/CheckBoxMgmtProvider.js @@ -0,0 +1,35 @@ +(function(){ + 'use strict'; + + /** + * @name CheckBoxMgmtProvider + * @used as CheckBox management service + */ + function CheckBoxMgmtProvider(){ + var service = this; + + service.getCheckOption = getCheckOption; + function getCheckOption(storageData){ + var foundFalse = false; + _.each(storageData, function(data){ + if(foundFalse){ + return false; + } + _.each(data, function(subData){ + if(subData.optionList.selected === false){ + // find a way not to use css directly here + $('th md-checkbox').removeClass('md-checked'); + foundFalse = true; + return false; + }else{ + $('th md-checkbox').addClass('md-checked'); + } + }) + }); + } + } + + angular + .module('mdDataTable') + .service('CheckBoxMgmtProvider', CheckBoxMgmtProvider); +})();