Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Add option to disable pagination from outside. #3956

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/pagination/pagination.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,11 +42,12 @@ angular.module('ui.bootstrap.pagination', [])
};

this.render = function() {
$scope.page = parseInt(ngModelCtrl.$viewValue, 10) || 1;
$scope.page = parseInt(ngModelCtrl.$viewValue, 10) || 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo this change.

};

$scope.selectPage = function(page, evt) {
if ( $scope.page !== page && page > 0 && page <= $scope.totalPages) {
var disabled_click = $scope.paginationDisabled && evt !== undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a camelcased variable - disabled_click is bad JS code style.

In addition, $scope.paginationDisabled && evt is a simpler to read check since checking for definedness is all the statement seems to be doing.

if (!disabled_click && $scope.page !== page && page > 0 && page <= $scope.totalPages) {
if (evt && evt.target) {
evt.target.blur();
}
Expand Down Expand Up @@ -75,7 +75,8 @@ angular.module('ui.bootstrap.pagination', [])
previousText: 'Previous',
nextText: 'Next',
lastText: 'Last',
rotate: true
rotate: true,
paginationDisabled:false
})

.directive('pagination', ['$parse', 'paginationConfig', function($parse, paginationConfig) {
Expand All @@ -86,7 +87,8 @@ angular.module('ui.bootstrap.pagination', [])
firstText: '@',
previousText: '@',
nextText: '@',
lastText: '@'
lastText: '@',
paginationDisabled:'='
},
require: ['pagination', '?ngModel'],
controller: 'PaginationController',
Expand Down
12 changes: 6 additions & 6 deletions template/pagination/pagination.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul class="pagination">
<li ng-if="boundaryLinks" ng-class="{disabled: noPrevious()}"><a href ng-click="selectPage(1, $event)">{{getText('first')}}</a></li>
<li ng-if="directionLinks" ng-class="{disabled: noPrevious()}"><a href ng-click="selectPage(page - 1, $event)">{{getText('previous')}}</a></li>
<li ng-repeat="page in pages track by $index" ng-class="{active: page.active}"><a href ng-click="selectPage(page.number, $event)">{{page.text}}</a></li>
<li ng-if="directionLinks" ng-class="{disabled: noNext()}"><a href ng-click="selectPage(page + 1, $event)">{{getText('next')}}</a></li>
<li ng-if="boundaryLinks" ng-class="{disabled: noNext()}"><a href ng-click="selectPage(totalPages, $event)">{{getText('last')}}</a></li>
</ul>
<li ng-if="boundaryLinks" ng-class="{disabled: noPrevious()||paginationDisabled}"><a href ng-click="selectPage(1, $event)">{{getText('first')}}</a></li>
<li ng-if="directionLinks" ng-class="{disabled: noPrevious()||paginationDisabled}"><a href ng-click="selectPage(page - 1, $event)">{{getText('previous')}}</a></li>
<li ng-repeat="page in pages track by $index" ng-class="{active: page.active,disabled: paginationDisabled&&!page.active}"><a href ng-click="selectPage(page.number, $event)">{{page.text}}</a></li>
<li ng-if="directionLinks" ng-class="{disabled: noNext()||paginationDisabled}"><a href ng-click="selectPage(page + 1, $event)">{{getText('next')}}</a></li>
<li ng-if="boundaryLinks" ng-class="{disabled: noNext()||paginationDisabled}"><a href ng-click="selectPage(totalPages, $event)">{{getText('last')}}</a></li>
</ul>