diff --git a/src/pagination/pagination.js b/src/pagination/pagination.js index 6f0e69eead..7a5da1b67b 100644 --- a/src/pagination/pagination.js +++ b/src/pagination/pagination.js @@ -1,5 +1,4 @@ angular.module('ui.bootstrap.pagination', []) - .controller('PaginationController', ['$scope', '$attrs', '$parse', function ($scope, $attrs, $parse) { var self = this, ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl @@ -47,7 +46,8 @@ angular.module('ui.bootstrap.pagination', []) }; $scope.selectPage = function(page, evt) { - if ( $scope.page !== page && page > 0 && page <= $scope.totalPages) { + var clickAllowed = !$scope.ngDisabled || !evt; + if (clickAllowed && $scope.page !== page && page > 0 && page <= $scope.totalPages) { if (evt && evt.target) { evt.target.blur(); } @@ -86,7 +86,8 @@ angular.module('ui.bootstrap.pagination', []) firstText: '@', previousText: '@', nextText: '@', - lastText: '@' + lastText: '@', + ngDisabled:'=' }, require: ['pagination', '?ngModel'], controller: 'PaginationController', diff --git a/src/pagination/test/pagination.spec.js b/src/pagination/test/pagination.spec.js index 19a9618c28..968df358bf 100644 --- a/src/pagination/test/pagination.spec.js +++ b/src/pagination/test/pagination.spec.js @@ -7,6 +7,7 @@ describe('pagination directive', function () { $rootScope = _$rootScope_; $rootScope.total = 47; // 5 pages $rootScope.currentPage = 3; + $rootScope.disabled = false; $document = _$document_; element = $compile('')($rootScope); $rootScope.$digest(); @@ -33,6 +34,12 @@ describe('pagination directive', function () { $rootScope.$digest(); } + function setDisabled(value) + { + $rootScope.disabled = value; + $rootScope.$digest(); + } + it('has a "pagination" css class', function() { expect(element.hasClass('pagination')).toBe(true); }); @@ -673,4 +680,29 @@ describe('pagination directive', function () { }); }); + describe('disabled with ngDisable', function () { + beforeEach(function() { + element = $compile('')($rootScope); + $rootScope.currentPage = 3; + $rootScope.$digest(); + }); + + it('should not respond to clicking', function() { + setDisabled(true); + clickPaginationEl(2); + expect($rootScope.currentPage).toBe(3); + setDisabled(false); + clickPaginationEl(2); + expect($rootScope.currentPage).toBe(2); + }); + + it('should change the class of all buttons except selected one', function () { + setDisabled(false); + expect(getPaginationEl(3).hasClass('active')).toBe(true); + expect(getPaginationEl(4).hasClass('active')).toBe(false); + setDisabled(true); + expect(getPaginationEl(3).hasClass('disabled')).toBe(false); + expect(getPaginationEl(4).hasClass('disabled')).toBe(true); + }); + }); }); diff --git a/template/pagination/pagination.html b/template/pagination/pagination.html index acd101a995..d207e74b8d 100644 --- a/template/pagination/pagination.html +++ b/template/pagination/pagination.html @@ -1,7 +1,7 @@ \ No newline at end of file +
  • {{getText('first')}}
  • +
  • {{getText('previous')}}
  • +
  • {{page.text}}
  • +
  • {{getText('next')}}
  • +
  • {{getText('last')}}
  • +