UserFlags.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template lang="html">
  2. <div id="user-flags">
  3. <h2
  4. class="mdi mdi-folder-outline"
  5. >{{ $t("materio.My folders") }} ({{collsLength}})</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"
  11. >{{ coll.name }} ({{ coll.items.length }})</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="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/>
  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.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. }),
  75. onCreateFlagColl () {
  76. console.log("UserFlags onCreateFlagColl", this.new_folder_name)
  77. this.is_creating_folder = true;
  78. this.createFlagColl(this.new_folder_name)
  79. .then(data => {
  80. console.log("onCreateFlagColl then", data);
  81. this.new_folder_name = "";
  82. this.is_creating_folder = false;
  83. })
  84. },
  85. onDeleteFlagColl (e) {
  86. const flagcollid = e.target.getAttribute('flagcollid');
  87. console.log("UserFlags onDeleteFlagColl", flagcollid);
  88. this.is_deleting_folder = flagcollid;
  89. // TODO: confirm suppression
  90. this.confirmDeleteFlagColl(flagcollid)
  91. },
  92. confirmDeleteFlagColl (flagcollid){
  93. console.log('confirmDeleteFlagCOll', flagcollid, this.flagcolls);
  94. // const index = this.flagcolls.findIndex(i => i.id === flagcollid)
  95. let coll = this.flagcolls[flagcollid]
  96. // console.log("coll to delete", coll);
  97. this.$modal.show('dialog', {
  98. title: "Folder delete",
  99. text: `Please confirm the definitive deletion of ${coll.name} ?`,
  100. buttons: [
  101. {
  102. title: 'Cancel',
  103. default: true,
  104. handler: () => {
  105. this.$modal.hide('dialog')
  106. }
  107. },
  108. {
  109. title: 'Delete',
  110. handler: () => {
  111. console.log('deletion confirmed', flagcollid);
  112. this.deleteFlagColl(flagcollid)
  113. .then(() => {
  114. // console.log("onDeleteFlagColl then", data);
  115. this.is_deleting_folder = false;
  116. this.$modal.hide('dialog')
  117. })
  118. }
  119. }
  120. ]
  121. })
  122. },
  123. onOpenFlagColl (e) {
  124. const flagcollid = e.target.getAttribute('flagcollid');
  125. console.log("UserFlags onOpenFlagColl", flagcollid);
  126. this.openFlagColl(flagcollid)
  127. .then(() => {
  128. // console.log("onDeleteFlagColl then", data);
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. </style>