| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-btn | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     :color="color || btnAttrs.color" | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |     :small="small" | 
					
						
							|  |  |  |     :x-small="xSmall" | 
					
						
							|  |  |  |     :loading="loading" | 
					
						
							|  |  |  |     :disabled="disabled" | 
					
						
							|  |  |  |     :outlined="btnStyle.outlined" | 
					
						
							|  |  |  |     :text="btnStyle.text" | 
					
						
							|  |  |  |     :to="to" | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |     v-on="$listeners" | 
					
						
							|  |  |  |     @click="download ? downloadFile() : undefined" | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |   > | 
					
						
							|  |  |  |     <v-icon left> | 
					
						
							|  |  |  |       <slot name="icon"> | 
					
						
							|  |  |  |         {{ btnAttrs.icon }} | 
					
						
							|  |  |  |       </slot> | 
					
						
							|  |  |  |     </v-icon> | 
					
						
							|  |  |  |     <slot name="default"> | 
					
						
							|  |  |  |       {{ btnAttrs.text }} | 
					
						
							|  |  |  |     </slot> | 
					
						
							|  |  |  |   </v-btn> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  | import { useApiSingleton } from "~/composables/use-api"; | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  | export default { | 
					
						
							|  |  |  |   name: "BaseButton", | 
					
						
							|  |  |  |   props: { | 
					
						
							|  |  |  |     // Types
 | 
					
						
							|  |  |  |     cancel: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     create: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     update: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     edit: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     delete: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |     // Download
 | 
					
						
							|  |  |  |     download: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     downloadUrl: { | 
					
						
							|  |  |  |       type: String, | 
					
						
							|  |  |  |       default: "", | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |     // Property
 | 
					
						
							|  |  |  |     loading: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     disabled: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     // Styles
 | 
					
						
							|  |  |  |     small: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     xSmall: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     secondary: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     minor: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     to: { | 
					
						
							|  |  |  |       type: String, | 
					
						
							|  |  |  |       default: null, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     color: { | 
					
						
							|  |  |  |       type: String, | 
					
						
							|  |  |  |       default: null, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |   setup() { | 
					
						
							|  |  |  |     const api = useApiSingleton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { api }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |   data() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       buttonOptions: { | 
					
						
							|  |  |  |         create: { | 
					
						
							|  |  |  |           text: "Create", | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |           icon: this.$globals.icons.createAlt, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |           color: "success", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         update: { | 
					
						
							|  |  |  |           text: "Update", | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |           icon: this.$globals.icons.edit, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |           color: "success", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         save: { | 
					
						
							|  |  |  |           text: "Save", | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |           icon: this.$globals.icons.save, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |           color: "success", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         edit: { | 
					
						
							|  |  |  |           text: "Edit", | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |           icon: this.$globals.icons.edit, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |           color: "info", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         delete: { | 
					
						
							|  |  |  |           text: "Delete", | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |           icon: this.$globals.icons.delete, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |           color: "error", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         cancel: { | 
					
						
							|  |  |  |           text: "Cancel", | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |           icon: this.$globals.icons.cancel, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |           color: "grey", | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |         download: { | 
					
						
							|  |  |  |           text: "Download", | 
					
						
							|  |  |  |           icon: this.$globals.icons.download, | 
					
						
							|  |  |  |           color: "info", | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |       }, | 
					
						
							|  |  |  |       buttonStyles: { | 
					
						
							|  |  |  |         defaults: { | 
					
						
							|  |  |  |           text: false, | 
					
						
							|  |  |  |           outlined: false, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         secondary: { | 
					
						
							|  |  |  |           text: false, | 
					
						
							|  |  |  |           outlined: true, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         minor: { | 
					
						
							|  |  |  |           outlined: false, | 
					
						
							|  |  |  |           text: true, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   computed: { | 
					
						
							|  |  |  |     btnAttrs() { | 
					
						
							|  |  |  |       if (this.delete) { | 
					
						
							|  |  |  |         return this.buttonOptions.delete; | 
					
						
							|  |  |  |       } else if (this.update) { | 
					
						
							|  |  |  |         return this.buttonOptions.update; | 
					
						
							|  |  |  |       } else if (this.edit) { | 
					
						
							|  |  |  |         return this.buttonOptions.edit; | 
					
						
							|  |  |  |       } else if (this.cancel) { | 
					
						
							|  |  |  |         this.setMinor(); | 
					
						
							|  |  |  |         return this.buttonOptions.cancel; | 
					
						
							|  |  |  |       } else if (this.save) { | 
					
						
							|  |  |  |         return this.buttonOptions.save; | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |       } else if (this.download) { | 
					
						
							|  |  |  |         return this.buttonOptions.download; | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |       return this.buttonOptions.create; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     btnStyle() { | 
					
						
							|  |  |  |       if (this.secondary) { | 
					
						
							|  |  |  |         return this.buttonStyles.secondary; | 
					
						
							|  |  |  |       } else if (this.minor) { | 
					
						
							|  |  |  |         return this.buttonStyles.minor; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return this.buttonStyles.defaults; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   methods: { | 
					
						
							|  |  |  |     setMinor() { | 
					
						
							|  |  |  |       this.buttonStyles.defaults = this.buttonStyles.minor; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     setSecondary() { | 
					
						
							|  |  |  |       this.buttonStyles.defaults = this.buttonStyles.secondary; | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |     downloadFile() { | 
					
						
							|  |  |  |       this.api.utils.download(this.downloadUrl); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | </script> |