logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

selectable_list.js (1406B)


  1. import List from '../list/list.vue'
  2. import Checkbox from '../checkbox/checkbox.vue'
  3. const SelectableList = {
  4. components: {
  5. List,
  6. Checkbox
  7. },
  8. props: {
  9. items: {
  10. type: Array,
  11. default: () => []
  12. },
  13. getKey: {
  14. type: Function,
  15. default: item => item.id
  16. }
  17. },
  18. data () {
  19. return {
  20. selected: []
  21. }
  22. },
  23. computed: {
  24. allKeys () {
  25. return this.items.map(this.getKey)
  26. },
  27. filteredSelected () {
  28. return this.allKeys.filter(key => this.selected.indexOf(key) !== -1)
  29. },
  30. allSelected () {
  31. return this.filteredSelected.length === this.items.length
  32. },
  33. noneSelected () {
  34. return this.filteredSelected.length === 0
  35. },
  36. someSelected () {
  37. return !this.allSelected && !this.noneSelected
  38. }
  39. },
  40. methods: {
  41. isSelected (item) {
  42. return this.filteredSelected.indexOf(this.getKey(item)) !== -1
  43. },
  44. toggle (checked, item) {
  45. const key = this.getKey(item)
  46. const oldChecked = this.isSelected(key)
  47. if (checked !== oldChecked) {
  48. if (checked) {
  49. this.selected.push(key)
  50. } else {
  51. this.selected.splice(this.selected.indexOf(key), 1)
  52. }
  53. }
  54. },
  55. toggleAll (value) {
  56. if (value) {
  57. this.selected = this.allKeys.slice(0)
  58. } else {
  59. this.selected = []
  60. }
  61. }
  62. }
  63. }
  64. export default SelectableList