| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div class="my-spells"> | 
					
						
							| 
									
										
										
										
											2020-04-22 14:23:59 +02:00
										 |  |  |     <div class="d-flex flex-wrap align-center d-print-none"> | 
					
						
							|  |  |  |       <Breadcrumb class="mr-auto mb-4" /> | 
					
						
							|  |  |  |       <div class="d-flex flex-wrap align-center"> | 
					
						
							|  |  |  |         <v-btn color="primary" class="mr-4 mb-4" depressed link to="/creation-de-sort/"><v-icon left>mdi-plus</v-icon> Créer un sort</v-btn> | 
					
						
							|  |  |  |         <v-btn color="primary" class="mb-4" depressed link to="/grimoire/">Grimoire</v-btn> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |     </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <h1>Mon grimoire</h1> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <div class="my-4 d-flex flex-wrap d-print-none"> | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |       <v-btn outlined color="accent" class="mr-1 mb-1" depressed @click="print" :disabled="$store.state.mySpells.spells.length <= 0"><v-icon>mdi-printer</v-icon> Imprimer</v-btn> | 
					
						
							|  |  |  |       <v-btn outlined color="accent" class="mr-1 mb-1" depressed @click="download" :disabled="$store.state.mySpells.spells.length <= 0"><v-icon>mdi-file-download</v-icon> Sauvegarder</v-btn> | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |       <v-btn outlined color="accent" class="mr-1 mb-1" depressed :loading="isUploading" @click="onUploadClick"> | 
					
						
							|  |  |  |         <v-icon left>mdi-file-upload</v-icon> Charger | 
					
						
							|  |  |  |       </v-btn> | 
					
						
							|  |  |  |       <input ref="uploader" class="d-none" type="file" @change="upload"> | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |       <v-btn outlined color="error" class="mb-1" depressed @click.stop="confirmDeleteDialog = true" :disabled="$store.state.mySpells.spells.length <= 0"><v-icon>mdi-delete</v-icon> Effacer le grimoire</v-btn> | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |     </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |     <v-dialog v-model="confirmDeleteDialog" max-width="290"> | 
					
						
							|  |  |  |       <v-card> | 
					
						
							|  |  |  |         <v-card-title class="headline">Supprimer le grimoire</v-card-title> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         <v-card-text> | 
					
						
							|  |  |  |           Cette action supprimera tous les sorts ajoutés à votre grimoire, y compris les sorts que vous avez créés. Souhaitez vous les supprimer ? | 
					
						
							|  |  |  |         </v-card-text> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         <v-card-actions> | 
					
						
							|  |  |  |           <v-spacer></v-spacer> | 
					
						
							|  |  |  |           <v-btn depressed @click="confirmDeleteDialog = false"> | 
					
						
							|  |  |  |             Annuler | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <v-btn color="error darken-1" depressed @click="confirmDeletion"> | 
					
						
							|  |  |  |             Supprimer | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							|  |  |  |         </v-card-actions> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							|  |  |  |     </v-dialog> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <v-alert v-model="alertOpen" :type="alertType" dismissible transition="fade-transition"> | 
					
						
							|  |  |  |       {{ alertText }} | 
					
						
							|  |  |  |     </v-alert> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |     <MySpells /> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | import Breadcrumb from '@theme/components/Breadcrumb' | 
					
						
							|  |  |  | import MySpells from '@theme/components/MySpells' | 
					
						
							|  |  |  | import { saveAs } from 'file-saver' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default { | 
					
						
							|  |  |  |   name: 'MySpellsLayout', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   components: { | 
					
						
							|  |  |  |     Breadcrumb, | 
					
						
							|  |  |  |     MySpells | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   data () { | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |       isUploading: false, | 
					
						
							|  |  |  |       confirmDeleteDialog: false, | 
					
						
							|  |  |  |       alertOpen: false, | 
					
						
							|  |  |  |       alertText: null, | 
					
						
							|  |  |  |       alertType: "info" | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   methods: { | 
					
						
							|  |  |  |     download () { | 
					
						
							| 
									
										
										
										
											2020-05-03 19:35:37 +02:00
										 |  |  |       saveAs(new Blob([JSON.stringify(this.$store.state.mySpells)], { | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |           type: "text/plain;charset=utf-8" | 
					
						
							|  |  |  |       }), "grimoire.json") | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     upload (e) { | 
					
						
							|  |  |  |       let file = e.target.files[0] | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |       if (!file) { | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |       let reader = new FileReader() | 
					
						
							|  |  |  |       let self = this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       reader.onload = function() { | 
					
						
							|  |  |  |         let result = JSON.parse(reader.result) | 
					
						
							|  |  |  |         let isValid = true | 
					
						
							| 
									
										
										
										
											2020-05-03 19:35:37 +02:00
										 |  |  |         if (result.spells && result.spells.length >= 1) { | 
					
						
							|  |  |  |           for (var s of result.spells) { | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |             if (s.pid !== 'spell') { | 
					
						
							|  |  |  |               isValid = false | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |           isValid = false | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (isValid) { | 
					
						
							| 
									
										
										
										
											2020-05-03 19:35:37 +02:00
										 |  |  |           self.$store.commit('mySpells/setSpells', result.spells) | 
					
						
							|  |  |  |           if (result.spellSlots) { | 
					
						
							|  |  |  |             self.$store.commit('mySpells/setSpellSlots', result.spellSlots) | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-05-04 12:01:58 +02:00
										 |  |  |           if (result.notPrintedSpells) { | 
					
						
							|  |  |  |             self.$store.commit('mySpells/setNotPrintedSpells', result.notPrintedSpells) | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-05-23 11:17:42 +02:00
										 |  |  |           self.$store.commit('setSnackbarText', self.$store.state.mySpells.spells.length + " sorts inscrits dans votre grimoire") | 
					
						
							|  |  |  |           self.$store.commit('setIsOpenSnackbar', true) | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-05-23 11:17:42 +02:00
										 |  |  |           self.$store.commit('setSnackbarText', "Le fichier est invalide") | 
					
						
							|  |  |  |           self.$store.commit('setIsOpenSnackbar', true) | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       reader.readAsText(file) | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |       this.$refs.uploader.value = '' | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onUploadClick () { | 
					
						
							|  |  |  |       this.isUploading = true | 
					
						
							|  |  |  |       window.addEventListener('focus', () => { | 
					
						
							|  |  |  |         this.isUploading = false | 
					
						
							|  |  |  |       }, { once: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       this.$refs.uploader.click() | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     print () { | 
					
						
							|  |  |  |       window.print() | 
					
						
							| 
									
										
										
										
											2020-05-22 19:04:27 +02:00
										 |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     confirmDeletion () { | 
					
						
							|  |  |  |       this.$store.commit('mySpells/resetSpells') | 
					
						
							|  |  |  |       this.confirmDeleteDialog = false | 
					
						
							| 
									
										
										
										
											2020-05-23 11:17:42 +02:00
										 |  |  |       this.$store.commit('setSnackbarText', "Votre grimoire a été effacé") | 
					
						
							|  |  |  |       this.$store.commit('setIsOpenSnackbar', true) | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mounted () { | 
					
						
							|  |  |  |     this.$store.commit('setHasRightDrawer', false) | 
					
						
							|  |  |  |     this.$store.commit('setRightDrawer', this.$vuetify.breakpoint.lgAndUp) | 
					
						
							|  |  |  |     this.$store.commit('setInRightDrawer', null) | 
					
						
							| 
									
										
										
										
											2021-02-14 10:40:57 +01:00
										 |  |  |     this.$page.title = "Mon grimoire" | 
					
						
							| 
									
										
										
										
											2020-04-22 11:17:05 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  | </style> |