Guest User

Untitled

a guest
Jan 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. paginate: function(){
  2.  
  3. let self = {
  4. currentPage: this.oldCourtDispatches.current_page,
  5. totalPages: this.oldCourtDispatches.last_page,
  6. pageArray: [],
  7. nextPage: (this.oldCourtDispatches.current_page == this.oldCourtDispatches.last_page ? '': this.oldCourtDispatches.current_page+1),
  8. prevPage: (this.oldCourtDispatches.current_page == 1 ? '' : this.oldCourtDispatches.current_page-1),
  9. buttonStart: '',
  10. buttonEnd: '',
  11. type: 'total',
  12. steps: 2,
  13. totalButtons: 4,
  14. }
  15.  
  16. if(self.type === 'steps'){
  17.  
  18. let steps = 2
  19.  
  20. self.buttonStart = (parseInt(self.currentPage)-steps > 1 ? parseInt(self.currentPage-steps) : 1 )
  21.  
  22. self.buttonEnd = (parseInt(self.totalPages)-parseInt(self.currentPage)-steps > 0 ? parseInt(self.currentPage) + steps : self.totalPages )
  23.  
  24. }
  25.  
  26. if(self.type === 'total'){
  27.  
  28. let steps = Math.ceil(self.totalButtons/2)
  29.  
  30. self.buttonStart = (parseInt(self.currentPage)-steps > 1 ? parseInt(self.currentPage-steps) : 1 )
  31.  
  32. self.buttonEnd = (parseInt(self.totalPages)-parseInt(self.currentPage)-steps > 0 ? parseInt(self.currentPage) + steps : self.totalPages )
  33.  
  34. if(self.buttonStart < steps){
  35. let remainder = steps - self.currentPage
  36. self.buttonEnd = self.buttonEnd + remainder +1
  37. }
  38.  
  39. if(self.totalPages - self.currentPage < steps){
  40.  
  41. let remainder = steps - (self.totalPages - self.currentPage)
  42.  
  43. self.buttonStart = (parseInt(self.buttonStart)- remainder > 1 ? parseInt(self.buttonStart)- remainder : 1 )
  44.  
  45. }
  46.  
  47. }
  48.  
  49. for(let i=self.buttonStart; i < parseInt(self.buttonEnd+1); i++){
  50. self.pageArray.push(i)
  51. }
  52.  
  53.  
  54. return self
  55. }
Add Comment
Please, Sign In to add comment