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.

GroupListItem.vue 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!--
  2. - @copyright Copyright (c) 2021 Martin Jänel <spammemore@posteo.de>
  3. -
  4. - @author Martin Jänel <spammemore@posteo.de>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -
  21. -->
  22. <template>
  23. <NcAppNavigationItem :key="id"
  24. :exact="true"
  25. :title="title"
  26. :to="{ name: 'group', params: { selectedGroup: encodeURIComponent(id) } }"
  27. icon="icon-group"
  28. :loading="loadingRenameGroup"
  29. :menu-open="openGroupMenu"
  30. @update:menuOpen="handleGroupMenuOpen">
  31. <template #counter>
  32. <NcCounterBubble v-if="count">
  33. {{ count }}
  34. </NcCounterBubble>
  35. </template>
  36. <template #actions>
  37. <NcActionInput v-if="id !== 'admin' && id !== 'disabled' && settings.isAdmin"
  38. ref="displayNameInput"
  39. icon="icon-edit"
  40. type="text"
  41. :value="title"
  42. @submit="renameGroup(id)">
  43. {{ t('settings', 'Rename group') }}
  44. </NcActionInput>
  45. <NcActionButton v-if="id !== 'admin' && id !== 'disabled' && settings.isAdmin"
  46. icon="icon-delete"
  47. @click="removeGroup(id)">
  48. {{ t('settings', 'Remove group') }}
  49. </NcActionButton>
  50. </template>
  51. </NcAppNavigationItem>
  52. </template>
  53. <script>
  54. import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
  55. import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
  56. import NcCounterBubble from '@nextcloud/vue/dist/Components/NcCounterBubble.js'
  57. import NcAppNavigationItem from '@nextcloud/vue/dist/Components/NcAppNavigationItem.js'
  58. export default {
  59. name: 'GroupListItem',
  60. components: {
  61. NcActionInput,
  62. NcActionButton,
  63. NcCounterBubble,
  64. NcAppNavigationItem,
  65. },
  66. props: {
  67. id: {
  68. type: String,
  69. required: true,
  70. },
  71. title: {
  72. type: String,
  73. required: true,
  74. },
  75. count: {
  76. type: Number,
  77. required: false,
  78. },
  79. },
  80. data() {
  81. return {
  82. loadingRenameGroup: false,
  83. openGroupMenu: false,
  84. }
  85. },
  86. computed: {
  87. settings() {
  88. return this.$store.getters.getServerData
  89. },
  90. },
  91. methods: {
  92. handleGroupMenuOpen() {
  93. this.openGroupMenu = true
  94. },
  95. async renameGroup(gid) {
  96. // check if group id is valid
  97. if (gid.trim() === '') {
  98. return
  99. }
  100. const displayName = this.$refs.displayNameInput.$el.querySelector('input[type="text"]').value
  101. // check if group name is valid
  102. if (displayName.trim() === '') {
  103. return
  104. }
  105. try {
  106. this.openGroupMenu = false
  107. this.loadingRenameGroup = true
  108. await this.$store.dispatch('renameGroup', {
  109. groupid: gid.trim(),
  110. displayName: displayName.trim(),
  111. })
  112. this.loadingRenameGroup = false
  113. } catch {
  114. this.openGroupMenu = true
  115. this.loadingRenameGroup = false
  116. }
  117. },
  118. removeGroup(groupid) {
  119. // TODO migrate to a vue js confirm dialog component
  120. OC.dialogs.confirm(
  121. t('settings', 'You are about to remove the group {group}. The users will NOT be deleted.', { group: groupid }),
  122. t('settings', 'Please confirm the group removal '),
  123. (success) => {
  124. if (success) {
  125. this.$store.dispatch('removeGroup', groupid)
  126. }
  127. },
  128. )
  129. },
  130. },
  131. }
  132. </script>