forked from Coded/SIPRP
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							128 lines
						
					
					
						
							4.1 KiB
						
					
					
				
			
		
		
	
	
							128 lines
						
					
					
						
							4.1 KiB
						
					
					
				| evoapp.directive('pagingToolbar', function ($filter) {
 | |
| 
 | |
|     return {
 | |
|       restrict: 'AE',
 | |
|       template:          
 | |
|           
 | |
|         '<footer class="">' + 
 | |
|             '<div class="row">' + 
 | |
| 
 | |
|                 '<div class="col-sm-6 text-left text-center-xs">' + 
 | |
|                     '<small ng-hide="store.items.length == 0" class="text-muted inline m-t-sm m-b-sm" ng-bind="showingInfo()"></small>' + 
 | |
|                     '<small ng-show="store.items.length == 0" class="text-muted inline m-t-sm m-b-sm">Sem dados para mostrar</small>' + 
 | |
|                 '</div>' + 
 | |
| 
 | |
|                 '<div ng-show="showPager" class="col-sm-6 text-right text-center-xs">' + 
 | |
|                     '<div class="btn-group">' +
 | |
|                         '<button ng-disabled="store.start == 0" ng-click="move(\'back\')" class="btn btn-default btn-sm">' +
 | |
|                             '<i class="glyphicon glyphicon-chevron-left"></i>' +
 | |
|                         '</button>' +
 | |
|                         '<button type="button" class="btn btn-default btn-sm" ng-bind="pageInfo()"></button>' + 
 | |
|                         '<button ng-click="get()" type="button" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-refresh"></i></button>' + 
 | |
|                         '<button ng-disabled="currentPage == numberOfPages()" ng-click="move(\'forward\')" class="btn btn-default btn-sm">' +
 | |
|                             '<i class="glyphicon glyphicon-chevron-right"></i>' +
 | |
|                         '</button>' +
 | |
|                     '</div>' + 
 | |
|                 '</div>' + 
 | |
| 
 | |
|             '</div>' + 
 | |
|         '</footer>',
 | |
| 
 | |
|       scope: {
 | |
|         store: '='
 | |
|       },
 | |
| 
 | |
|       link: function (scope, elem, attrs) {
 | |
| 
 | |
|         scope.currentPage = 1;
 | |
| 
 | |
|         scope.showPager = attrs.showPager ? attrs.showPager : true;
 | |
| 
 | |
|         scope.numberOfPages = function(){
 | |
| 
 | |
|             var numberOfPages = 0;   
 | |
|             
 | |
|             scope.store.total = scope.store.items.length > 0 ? 1 : 0;
 | |
| 
 | |
|             if(scope.store.total > 0)
 | |
|             {
 | |
|                 numberOfPages = Math.ceil(scope.store.total/scope.store.limit);  
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 numberOfPages = 0;
 | |
|             }
 | |
| 
 | |
|             return numberOfPages;                
 | |
|         };
 | |
| 
 | |
|         scope.move = function(direction) {
 | |
| 
 | |
|             if(direction == 'forward')
 | |
|             {        
 | |
|                 scope.store.start = scope.store.start + scope.store.limit;
 | |
| 
 | |
|                 scope.currentPage = scope.currentPage + 1;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 scope.store.start = scope.store.start - scope.store.limit;
 | |
| 
 | |
|                 scope.currentPage = scope.currentPage - 1;
 | |
|             }
 | |
|         };
 | |
| 
 | |
|         scope.$watch('store.start', function(newValue, oldValue){
 | |
| 
 | |
|             if(newValue != oldValue && newValue != undefined)
 | |
|             {
 | |
|                 scope.get();
 | |
|             }            
 | |
|         });
 | |
| 
 | |
|         scope.$watch('store.total', function(newValue, oldValue){
 | |
|             
 | |
|             if(!isNaN(newValue))
 | |
|             {
 | |
|                 var total = parseInt(newValue);
 | |
| 
 | |
|                 if(total == 0)
 | |
|                 {
 | |
|                     scope.currentPage = 0;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     scope.currentPage = scope.currentPage == 0 ? 1 : scope.currentPage;
 | |
|                 }
 | |
|             }
 | |
|         });
 | |
| 
 | |
|         scope.get = function(){
 | |
| 
 | |
|             scope.store.get(function(response, status, headers, config, items){
 | |
| 
 | |
|                 scope.currentPage = scope.store.start == 0 ? (items.length > 0 ? 1 : 0) : scope.currentPage;  
 | |
|             });
 | |
|         };
 | |
| 
 | |
|         scope.showingInfo = function(){
 | |
| 
 | |
|             var from = (scope.store.items.length == 0 ? 0 : (scope.store.start + 1)),
 | |
|                 to = (scope.store.start + scope.store.items.length);
 | |
| 
 | |
|             return ('A mostrar ' + from + ' - ' + to + ' de ' + scope.store.total);
 | |
|         };
 | |
| 
 | |
|         scope.pageInfo = function(){
 | |
| 
 | |
|             var info = 'Página ' + 
 | |
|                 scope.currentPage + ' de ' + 
 | |
|                 scope.numberOfPages();
 | |
| 
 | |
|             return info;
 | |
|         };
 | |
| 
 | |
| 
 | |
|       }
 | |
|     }
 | |
| }); |