UserFlags.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template lang="html">
  2. <div id="user-flags">
  3. <h2
  4. class="mdi mdi-folder-outline"
  5. ><span>{{ $t("materio.My folders") }} ({{collsLength}})</span></h2>
  6. <ul>
  7. <li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
  8. <h5
  9. :flagcollid="coll.id"
  10. @click.prevent="onOpenFlagColl(coll.id)"
  11. >{{ coll.name }} <span class="length">({{ coll.items.length }})</span></h5>
  12. <div class="actions">
  13. <span
  14. class="delete-btn mdi"
  15. :class="flagDeletingClassObj"
  16. :flagcollid="coll.id"
  17. @click.prevent="onDeleteFlagColl"
  18. />
  19. </div>
  20. </li>
  21. <li v-if="collsLength<15" class="create-flag">
  22. <input
  23. :placeholder="$t('materio.new folder')"
  24. v-model="new_folder_name"
  25. @keyup.enter.prevent.stop="onCreateFlagColl"
  26. />
  27. <span
  28. class="add-btn mdi"
  29. :class="addFlagBtnClassObj"
  30. @click.prevent.stop="onCreateFlagColl"
  31. />
  32. </li>
  33. </ul>
  34. <v-dialog @closed="dialogEvent('closed')"/>
  35. </div>
  36. </template>
  37. <script>
  38. import { mapState, mapActions } from 'vuex'
  39. export default {
  40. name: "userFlags",
  41. data: () => ({
  42. new_folder_name: "",
  43. is_creating_folder: false,
  44. is_deleting_folder: false
  45. }),
  46. computed: {
  47. ...mapState({
  48. flagcolls: state => state.User.flagcolls
  49. }),
  50. collsLength() {
  51. return Object.keys(this.flagcolls).length
  52. },
  53. addFlagBtnClassObj() {
  54. return {
  55. 'mdi-plus-circle-outline': !this.is_creating_folder,
  56. 'mdi-loading': this.is_creating_folder,
  57. active: this.new_folder_name.length > 4 && this.checkFlagNameUniqness() && !this.is_creating_folder,
  58. loading: this.is_creating_folder
  59. }
  60. },
  61. flagDeletingClassObj() {
  62. return {
  63. 'mdi-trash-can-outline': !this.is_deleting_folder,
  64. 'mdi-loading': this.is_deleting_folder,
  65. 'loading': this.is_deleting_folder
  66. }
  67. }
  68. },
  69. methods: {
  70. ...mapActions({
  71. createFlagColl: 'User/createFlagColl',
  72. deleteFlagColl: 'User/deleteFlagColl',
  73. openFlagColl: 'User/openFlagColl',
  74. openCloseHamMenu: 'Common/openCloseHamMenu'
  75. }),
  76. checkFlagNameUniqness () {
  77. let uniq = true
  78. const flagcolls_ids = Object.keys(this.flagcolls);
  79. flagcolls_ids.forEach((id) => {
  80. if(this.flagcolls[id].name === this.new_folder_name){
  81. uniq = false
  82. }
  83. })
  84. return uniq
  85. },
  86. onCreateFlagColl () {
  87. console.log("UserFlags onCreateFlagColl", this.new_folder_name)
  88. if (this.new_folder_name.length > 4 && this.checkFlagNameUniqness()){
  89. // create new flagcoll
  90. this.is_creating_folder = true;
  91. this.createFlagColl(this.new_folder_name)
  92. .then(data => {
  93. console.log("onCreateFlagColl then", data)
  94. this.new_folder_name = "";
  95. this.is_creating_folder = false;
  96. })
  97. }
  98. },
  99. onDeleteFlagColl (e) {
  100. const flagcollid = e.target.getAttribute('flagcollid');
  101. console.log("UserFlags onDeleteFlagColl", flagcollid)
  102. this.is_deleting_folder = flagcollid;
  103. // TODO: confirm suppression
  104. this.confirmDeleteFlagColl(flagcollid)
  105. },
  106. confirmDeleteFlagColl (flagcollid){
  107. // console.log('confirmDeleteFlagCOll', flagcollid, this.flagcolls)
  108. // const index = this.flagcolls.findIndex(i => i.id === flagcollid)
  109. let coll = this.flagcolls[flagcollid]
  110. // console.log("coll to delete", coll)
  111. this.$modal.show('dialog',
  112. { // component props
  113. title: this.$t("materio.Folder delete"),
  114. text: this.$t(`materio.Please confirm the definitive deletion of {name} ?`, { name: coll.name }),
  115. buttons: [
  116. {
  117. title: this.$t('default.Cancel'),
  118. default: true,
  119. handler: () => {
  120. // this.is_deleting_folder = false;
  121. this.$modal.hide('dialog')
  122. }
  123. },
  124. {
  125. title: this.$t('default.Delete'),
  126. handler: () => {
  127. // console.log('deletion confirmed', flagcollid)
  128. this.deleteFlagColl(flagcollid)
  129. .then(() => {
  130. // console.log("onDeleteFlagColl then", data)
  131. // this.is_deleting_folder = false;
  132. this.$modal.hide('dialog')
  133. })
  134. }
  135. }
  136. ]
  137. }
  138. )
  139. },
  140. dialogEvent (eventName) {
  141. console.log("dialog event", eventName)
  142. switch(eventName){
  143. case 'closed':
  144. this.is_deleting_folder = false
  145. }
  146. },
  147. onOpenFlagColl (flagcollid) {
  148. // const flagcollid = e.target.getAttribute('flagcollid');
  149. console.log("UserFlags onOpenFlagColl", flagcollid)
  150. this.openCloseHamMenu(false)
  151. this.openFlagColl(flagcollid)
  152. .then(() => {
  153. // console.log("onDeleteFlagColl then", data)
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. </style>