Card.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <article class="card search-card">
  3. <header
  4. @click.prevent="openModalCard"
  5. >
  6. <h1 v-if="hasDBAccess">{{ item.title }}</h1>
  7. <h4>{{ item.short_description }}</h4>
  8. <span v-if="hasDBAccess" class="ref">{{ item.reference }}</span>
  9. </header>
  10. <nav class="tools" v-if="hasDBAccess">
  11. <section class="tool flags">
  12. <span class="btn mdi mdi-folder-outline"/>
  13. <div class="tool-content">
  14. <ul>
  15. <li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
  16. <span
  17. class="flag mdi"
  18. :class="[
  19. flagIsLoading(coll.id) ? 'mdi-loading mdi-spin' : flagIsActive(coll.id) ? 'mdi-close-circle isActive' : 'mdi-plus'
  20. ]"
  21. :collid="coll.id"
  22. @click.prevent="onFlagActionCard"
  23. >
  24. {{ coll.name }}
  25. </span>
  26. </li>
  27. <li v-if="collsLength<15" class="create-flag">
  28. <input
  29. placeholder="new folder"
  30. v-model="new_folder_name"
  31. @keyup.enter.prevent.stop="onCreateFlagColl"
  32. />
  33. <span
  34. class="add-btn mdi"
  35. :class="addFlagBtnClassObj"
  36. @click.prevent.stop="onCreateFlagColl"
  37. />
  38. </li>
  39. </ul>
  40. </div>
  41. </section>
  42. <section class="tool samples" v-if="item.samples && item.samples.length">
  43. <span class="btn mdi mdi-map-marker-star-outline"/>
  44. <div class="tool-content">
  45. <span class="label">{{ $t("materio.Samples") }}</span>
  46. <ul>
  47. <li
  48. v-for="sample in item.samples"
  49. :key="sample.showroom.id"
  50. >
  51. <span class="showroom">{{ sample.showroom.name }}</span>: {{ sample.location }}
  52. </li>
  53. </ul>
  54. </div>
  55. </section>
  56. <section v-if="item.note" class="tool note">
  57. <span class="btn mdi mdi-note"/>
  58. </section>
  59. <section class="tool print">
  60. <a :href="item.path+'/printable/print'" target="_blank">
  61. <span class="btn mdi mdi-printer"/>
  62. </a>
  63. </section>
  64. </nav>
  65. <section class="images" v-switcher>
  66. <figure
  67. v-for="(img, index) in item.images"
  68. :key="img.url"
  69. class="lazy"
  70. v-lazy="index"
  71. >
  72. <img
  73. :data-src="img.style_cardmedium_url"
  74. :title="img.title"
  75. />
  76. <img
  77. class="blank"
  78. :src="blanksrc"
  79. @click.prevent="openModalCard"
  80. />
  81. </figure>
  82. </section>
  83. <!-- <CoolLightBox
  84. v-if="isloggedin"
  85. :items="item.images"
  86. :index="lightbox_index"
  87. srcName="style_hd_url"
  88. :loop="true"
  89. @close="lightbox_index = null">
  90. </CoolLightBox> -->
  91. </article>
  92. </template>
  93. <script>
  94. import { mapState, mapActions } from 'vuex'
  95. import cardMixins from 'vuejs/components/cardMixins'
  96. import ModalCard from 'vuejs/components/Content/ModalCard'
  97. import MemberWarning from 'vuejs/components/Content/MemberWarning'
  98. export default {
  99. name: "Card",
  100. props: ['item'],
  101. mixins: [cardMixins],
  102. components: {
  103. ModalCard,
  104. MemberWarning
  105. },
  106. data() {
  107. return {
  108. blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
  109. loadingFlag: false,
  110. new_folder_name: "",
  111. is_creating_folder: false
  112. // lightbox_index: null
  113. }
  114. },
  115. computed: {
  116. ...mapState({
  117. flagcolls: state => state.User.flagcolls,
  118. isloggedin: state => state.User.isloggedin,
  119. hasDBAccess: state => state.User.hasDBAccess
  120. }),
  121. collsLength() {
  122. return Object.keys(this.flagcolls).length
  123. },
  124. addFlagBtnClassObj() {
  125. return {
  126. 'mdi-plus-circle-outline': !this.is_creating_folder,
  127. 'mdi-loading': this.is_creating_folder,
  128. active: this.new_folder_name.length > 4 && !this.is_creating_folder,
  129. loading: this.is_creating_folder
  130. }
  131. }
  132. },
  133. beforeMount () {
  134. // console.log(this.item.id, this.samples)
  135. },
  136. methods: {
  137. ...mapActions({
  138. // refreshItem: 'Search/refreshItem',
  139. createFlagColl: 'User/createFlagColl',
  140. flagUnflag: 'User/flagUnflag'
  141. }),
  142. onCreateFlagColl () {
  143. console.log("Card onCreateFlagColl", this.new_folder_name)
  144. this.is_creating_folder = true;
  145. this.createFlagColl(this.new_folder_name)
  146. .then(data => {
  147. console.log("Card onCreateFlagColl then", data)
  148. this.new_folder_name = "";
  149. this.is_creating_folder = false;
  150. let collid = data.id
  151. this.loadingFlag = collid;
  152. this.flagUnflag({ action: 'flag', id: this.item.id, collid: collid})
  153. .then(data => {
  154. console.log("onFlagActionCard then", data)
  155. this.loadingFlag = false;
  156. })
  157. })
  158. },
  159. flagIsActive(collid) {
  160. // console.log("Card flagIsActive",
  161. // this.item.id,
  162. // this.flagcolls[collid].items,
  163. // this.flagcolls[collid].items.indexOf(this.item.id)
  164. // );
  165. // console.log(this.flagcolls[collid].items_uuids)
  166. // return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  167. return this.flagcolls[collid].items.indexOf(this.item.id) !== -1;
  168. },
  169. flagIsLoading(collid) {
  170. // console.log(this.item.uuid)
  171. // console.log(this.flagcolls[collid].items_uuids)
  172. return collid === this.loadingFlag;
  173. },
  174. onFlagActionCard (e) {
  175. console.log("Card onFlagActionCard", e, this.item)
  176. if (!this.loadingFlag) {
  177. let collid = e.target.getAttribute('collid');
  178. let isActive = this.flagIsActive(collid);
  179. let action = isActive ? 'unflag' : 'flag';
  180. // console.log('collid', collid)
  181. // console.log("this.item", this.item)
  182. this.loadingFlag = collid;
  183. this.flagUnflag({ action: action, id: this.item.id, collid: collid})
  184. .then(data => {
  185. console.log("onFlagActionCard then", data)
  186. this.loadingFlag = false;
  187. })
  188. }
  189. },
  190. // onClickImg (e, index) {
  191. // this.lightbox_index = index
  192. // },
  193. openModalCard (e) {
  194. console.log('openModalCard', this.hasDBAccess)
  195. if (this.hasDBAccess) {
  196. this.$modal.show(
  197. ModalCard,
  198. {
  199. item: this.item,
  200. // not really an event
  201. // more a callback function passed as prop to the component
  202. addNoteId:(id) => {
  203. // no needs to refresh the entire item via searchresults
  204. // plus if we are in article, there is not searchresults
  205. // this.refreshItem({id: this.item.id})
  206. // instead create the note id directly
  207. this.item.note = {id: id}
  208. }
  209. },
  210. {
  211. name: `modal-${this.item.id}`,
  212. draggable: false,
  213. classes: "vm--modale-card",
  214. // this does not work
  215. // adaptative: true,
  216. // maxWidth: 850,
  217. // maxHeight: 610,
  218. width: '95%',
  219. height: '95%'
  220. }
  221. )
  222. } else {
  223. this.$modal.show(
  224. MemberWarning,
  225. {},
  226. {
  227. // name: `modal-${this.item.id}`,
  228. draggable: false,
  229. // classes: "vm--modale-card",
  230. // this does not work
  231. // adaptative: true,
  232. // maxWidth: 850,
  233. // maxHeight: 610,
  234. width: '400px',
  235. height: '250px'
  236. }
  237. )
  238. }
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. </style>