Card.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <article class="card search-card">
  3. <header
  4. @click.prevent="openModalCard"
  5. >
  6. <h1 v-if="isloggedin">{{ item.title }}</h1>
  7. <h4>{{ item.short_description }}</h4>
  8. <span v-if="isloggedin" class="ref">{{ item.reference }}</span>
  9. </header>
  10. <nav class="tools" v-if="isloggedin">
  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-beaker-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. }),
  120. collsLength() {
  121. return Object.keys(this.flagcolls).length
  122. },
  123. addFlagBtnClassObj() {
  124. return {
  125. 'mdi-plus-circle-outline': !this.is_creating_folder,
  126. 'mdi-loading': this.is_creating_folder,
  127. active: this.new_folder_name.length > 4 && !this.is_creating_folder,
  128. loading: this.is_creating_folder
  129. }
  130. }
  131. },
  132. beforeMount () {
  133. console.log(this.item.id, this.samples)
  134. },
  135. methods: {
  136. ...mapActions({
  137. // refreshItem: 'Search/refreshItem',
  138. createFlagColl: 'User/createFlagColl',
  139. flagUnflag: 'User/flagUnflag'
  140. }),
  141. onCreateFlagColl () {
  142. console.log("Card onCreateFlagColl", this.new_folder_name)
  143. this.is_creating_folder = true;
  144. this.createFlagColl(this.new_folder_name)
  145. .then(data => {
  146. console.log("Card onCreateFlagColl then", data)
  147. this.new_folder_name = "";
  148. this.is_creating_folder = false;
  149. let collid = data.id
  150. this.loadingFlag = collid;
  151. this.flagUnflag({ action: 'flag', id: this.item.id, collid: collid})
  152. .then(data => {
  153. console.log("onFlagActionCard then", data)
  154. this.loadingFlag = false;
  155. })
  156. })
  157. },
  158. flagIsActive(collid) {
  159. // console.log("Card flagIsActive",
  160. // this.item.id,
  161. // this.flagcolls[collid].items,
  162. // this.flagcolls[collid].items.indexOf(this.item.id)
  163. // );
  164. // console.log(this.flagcolls[collid].items_uuids)
  165. // return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  166. return this.flagcolls[collid].items.indexOf(this.item.id) !== -1;
  167. },
  168. flagIsLoading(collid) {
  169. // console.log(this.item.uuid)
  170. // console.log(this.flagcolls[collid].items_uuids)
  171. return collid === this.loadingFlag;
  172. },
  173. onFlagActionCard (e) {
  174. console.log("Card onFlagActionCard", e, this.item)
  175. if (!this.loadingFlag) {
  176. let collid = e.target.getAttribute('collid');
  177. let isActive = this.flagIsActive(collid);
  178. let action = isActive ? 'unflag' : 'flag';
  179. // console.log('collid', collid)
  180. // console.log("this.item", this.item)
  181. this.loadingFlag = collid;
  182. this.flagUnflag({ action: action, id: this.item.id, collid: collid})
  183. .then(data => {
  184. console.log("onFlagActionCard then", data)
  185. this.loadingFlag = false;
  186. })
  187. }
  188. },
  189. // onClickImg (e, index) {
  190. // this.lightbox_index = index
  191. // },
  192. openModalCard (e) {
  193. console.log('openModalCard', this.isLoggedin)
  194. if (this.isloggedin) {
  195. this.$modal.show(
  196. ModalCard,
  197. {
  198. item: this.item,
  199. // not really an event
  200. // more a callback function passed as prop to the component
  201. addNoteId:(id) => {
  202. // no needs to refresh the entire item via searchresults
  203. // plus if we are in article, there is not searchresults
  204. // this.refreshItem({id: this.item.id})
  205. // instead create the note id directly
  206. this.item.note = {id: id}
  207. }
  208. },
  209. {
  210. name: `modal-${this.item.id}`,
  211. draggable: false,
  212. classes: "vm--modale-card",
  213. // this does not work
  214. // adaptative: true,
  215. // maxWidth: 850,
  216. // maxHeight: 610,
  217. width: '95%',
  218. height: '95%'
  219. }
  220. )
  221. } else {
  222. this.$modal.show(
  223. MemberWarning,
  224. {},
  225. {
  226. // name: `modal-${this.item.id}`,
  227. draggable: false,
  228. // classes: "vm--modale-card",
  229. // this does not work
  230. // adaptative: true,
  231. // maxWidth: 850,
  232. // maxHeight: 610,
  233. width: '400px',
  234. height: '250px'
  235. }
  236. )
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. </style>