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.

158 lines
3.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <div class="v-data-footer">
  3. <v-edit-dialog
  4. large
  5. persistent
  6. @save="changePageNumber"
  7. >
  8. <span>{{ value }} of {{ length }}</span>
  9. <template v-slot:input>
  10. <div class="mt-4 title">
  11. Move Page
  12. </div>
  13. </template>
  14. <template v-slot:input>
  15. <v-text-field
  16. v-model="newPage"
  17. :rules="rules"
  18. :label="$t('generic.edit')"
  19. single-line
  20. counter
  21. autofocus
  22. />
  23. </template>
  24. </v-edit-dialog>
  25. <v-tooltip bottom>
  26. <template v-slot:activator="{ on }">
  27. <v-btn
  28. v-shortkey.once="['shift', 'arrowleft']"
  29. :disabled="value===1"
  30. text
  31. fab
  32. small
  33. v-on="on"
  34. @shortkey="firstPage"
  35. @click="firstPage"
  36. >
  37. <v-icon>mdi-page-first</v-icon>
  38. </v-btn>
  39. </template>
  40. <span>
  41. <v-icon>mdi-page-first</v-icon>
  42. </span>
  43. </v-tooltip>
  44. <v-tooltip bottom>
  45. <template v-slot:activator="{ on }">
  46. <v-btn
  47. v-shortkey.once="['arrowleft']"
  48. :disabled="value===1"
  49. text
  50. fab
  51. small
  52. v-on="on"
  53. @shortkey="prevPage"
  54. @click="prevPage"
  55. >
  56. <v-icon>mdi-chevron-left</v-icon>
  57. </v-btn>
  58. </template>
  59. <span></span>
  60. </v-tooltip>
  61. <v-tooltip bottom>
  62. <template v-slot:activator="{ on }">
  63. <v-btn
  64. v-shortkey.once="['arrowright']"
  65. :disabled="value===length || length===0"
  66. text
  67. fab
  68. small
  69. v-on="on"
  70. @shortkey="nextPage"
  71. @click="nextPage"
  72. >
  73. <v-icon>mdi-chevron-right</v-icon>
  74. </v-btn>
  75. </template>
  76. <span></span>
  77. </v-tooltip>
  78. <v-tooltip bottom>
  79. <template v-slot:activator="{ on }">
  80. <v-btn
  81. v-shortkey.once="['shift', 'arrowright']"
  82. :disabled="value===length || length===0"
  83. text
  84. fab
  85. small
  86. v-on="on"
  87. @shortkey="lastPage"
  88. @click="lastPage"
  89. >
  90. <v-icon>mdi-page-last</v-icon>
  91. </v-btn>
  92. </template>
  93. <span>
  94. <v-icon>mdi-page-last</v-icon>
  95. </span>
  96. </v-tooltip>
  97. </div>
  98. </template>
  99. <script>
  100. export default {
  101. props: {
  102. value: {
  103. type: Number,
  104. default: 1,
  105. required: true
  106. },
  107. length: {
  108. type: Number,
  109. default: 1,
  110. required: true
  111. }
  112. },
  113. data() {
  114. return {
  115. editedPage: null,
  116. rules: [
  117. v => (v && parseInt(v, 10) > 0 && parseInt(v, 10) <= this.length) || 'Invalid page number!'
  118. ]
  119. }
  120. },
  121. computed: {
  122. newPage: {
  123. get() {
  124. return this.value
  125. },
  126. set(newValue) {
  127. const value = parseInt(newValue, 10)
  128. this.editedPage = value
  129. }
  130. }
  131. },
  132. methods: {
  133. changePageNumber() {
  134. if (!this.editedPage || this.editedPage < 0 || this.editedPage > this.length) {
  135. return
  136. }
  137. this.$emit('input', this.editedPage)
  138. },
  139. prevPage() {
  140. const page = Math.max(this.value - 1, 1)
  141. this.$emit('input', page)
  142. },
  143. nextPage() {
  144. const page = Math.min(this.value + 1, this.length)
  145. this.$emit('input', page)
  146. },
  147. firstPage() {
  148. this.$emit('input', 1)
  149. },
  150. lastPage() {
  151. this.$emit('input', this.length)
  152. }
  153. }
  154. }
  155. </script>