| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div class="text-center"> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="recipeEventEditDialog" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       :title="$t('recipe.edit-timeline-event')" | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |       :icon="$globals.icons.edit" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       can-submit | 
					
						
							|  |  |  |       :submit-text="$t('general.save')" | 
					
						
							|  |  |  |       @submit="submitEdit" | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |     > | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <v-form ref="domEditEventForm"> | 
					
						
							|  |  |  |           <v-text-field v-model="localEvent.subject" :label="$t('general.subject')" /> | 
					
						
							|  |  |  |           <v-textarea v-model="localEvent.eventMessage" :label="$t('general.message')" rows="4" /> | 
					
						
							|  |  |  |         </v-form> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |     </BaseDialog> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="recipeEventDeleteDialog" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       :title="$t('events.delete-event')" | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |       color="error" | 
					
						
							|  |  |  |       :icon="$globals.icons.alertCircle" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       can-confirm | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |       @confirm="$emit('delete')" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         {{ $t('events.event-delete-confirmation') }} | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |     <v-menu | 
					
						
							|  |  |  |       offset-y | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       start | 
					
						
							|  |  |  |       :bottom="!props.menuTop" | 
					
						
							|  |  |  |       :nudge-bottom="!props.menuTop ? '5' : '0'" | 
					
						
							|  |  |  |       :top="props.menuTop" | 
					
						
							|  |  |  |       :nudge-top="props.menuTop ? '5' : '0'" | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |       allow-overflow | 
					
						
							|  |  |  |       close-delay="125" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       :open-on-hover="!props.useMobileFormat" | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |       content-class="d-print-none" | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <template #activator="{ props: btnProps }"> | 
					
						
							|  |  |  |         <v-btn | 
					
						
							|  |  |  |           :class="{ 'rounded-circle': props.fab }" | 
					
						
							|  |  |  |           :x-small="props.fab" | 
					
						
							|  |  |  |           :elevation="props.elevation ?? undefined" | 
					
						
							|  |  |  |           :color="props.color" | 
					
						
							|  |  |  |           :icon="!props.fab" | 
					
						
							|  |  |  |           v-bind="btnProps" | 
					
						
							|  |  |  |           @click.prevent | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |           <v-icon>{{ icon }}</v-icon> | 
					
						
							|  |  |  |         </v-btn> | 
					
						
							|  |  |  |       </template> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <v-list density="compact"> | 
					
						
							|  |  |  |         <v-list-item | 
					
						
							|  |  |  |           v-for="(item, index) in menuItems" | 
					
						
							|  |  |  |           :key="index" | 
					
						
							|  |  |  |           @click="contextMenuEventHandler(item.event)" | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <template #prepend> | 
					
						
							|  |  |  |             <v-icon :color="item.color"> | 
					
						
							|  |  |  |               {{ item.icon }} | 
					
						
							|  |  |  |             </v-icon> | 
					
						
							|  |  |  |           </template> | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |           <v-list-item-title>{{ item.title }}</v-list-item-title> | 
					
						
							|  |  |  |         </v-list-item> | 
					
						
							|  |  |  |       </v-list> | 
					
						
							|  |  |  |     </v-menu> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | <script lang="ts" setup> | 
					
						
							|  |  |  | import { useI18n, useNuxtApp } from "#imports"; | 
					
						
							|  |  |  | import type { RecipeTimelineEventOut } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | export interface TimelineContextMenuIncludes { | 
					
						
							|  |  |  |   edit: boolean; | 
					
						
							|  |  |  |   delete: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface ContextMenuItem { | 
					
						
							|  |  |  |   title: string; | 
					
						
							|  |  |  |   icon: string; | 
					
						
							|  |  |  |   color: string | undefined; | 
					
						
							|  |  |  |   event: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | const props = defineProps<{ | 
					
						
							|  |  |  |   useItems?: TimelineContextMenuIncludes; | 
					
						
							|  |  |  |   appendItems?: ContextMenuItem[]; | 
					
						
							|  |  |  |   leadingItems?: ContextMenuItem[]; | 
					
						
							|  |  |  |   menuTop?: boolean; | 
					
						
							|  |  |  |   fab?: boolean; | 
					
						
							|  |  |  |   elevation?: number | null; | 
					
						
							|  |  |  |   color?: string; | 
					
						
							|  |  |  |   event: RecipeTimelineEventOut; | 
					
						
							|  |  |  |   menuIcon?: string | null; | 
					
						
							|  |  |  |   useMobileFormat?: boolean; | 
					
						
							|  |  |  | }>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const emit = defineEmits(["delete", "update"]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const domEditEventForm = ref(); | 
					
						
							|  |  |  | const recipeEventEditDialog = ref(false); | 
					
						
							|  |  |  | const recipeEventDeleteDialog = ref(false); | 
					
						
							|  |  |  | const loading = ref(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18n = useI18n(); | 
					
						
							|  |  |  | const { $globals } = useNuxtApp(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const defaultItems: { [key: string]: ContextMenuItem } = { | 
					
						
							|  |  |  |   edit: { | 
					
						
							|  |  |  |     title: i18n.t("general.edit"), | 
					
						
							|  |  |  |     icon: $globals.icons.edit, | 
					
						
							|  |  |  |     color: undefined, | 
					
						
							|  |  |  |     event: "edit", | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |   delete: { | 
					
						
							|  |  |  |     title: i18n.t("general.delete"), | 
					
						
							|  |  |  |     icon: $globals.icons.delete, | 
					
						
							|  |  |  |     color: "error", | 
					
						
							|  |  |  |     event: "delete", | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const menuItems = computed(() => { | 
					
						
							|  |  |  |   const items: ContextMenuItem[] = []; | 
					
						
							|  |  |  |   const useItems = props.useItems ?? { edit: true, delete: true }; | 
					
						
							|  |  |  |   for (const [key, value] of Object.entries(useItems)) { | 
					
						
							|  |  |  |     if (value) { | 
					
						
							|  |  |  |       const item = defaultItems[key]; | 
					
						
							|  |  |  |       if (item) items.push(item); | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |   } | 
					
						
							|  |  |  |   return [ | 
					
						
							|  |  |  |     ...items, | 
					
						
							|  |  |  |     ...(props.leadingItems ?? []), | 
					
						
							|  |  |  |     ...(props.appendItems ?? []), | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | const icon = computed(() => props.menuIcon || $globals.icons.dotsVertical); | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | const localEvent = ref({ ...props.event }); | 
					
						
							|  |  |  | watch(() => props.event, (val) => { | 
					
						
							|  |  |  |   localEvent.value = { ...val }; | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | function openEditDialog() { | 
					
						
							|  |  |  |   localEvent.value = { ...props.event }; | 
					
						
							|  |  |  |   recipeEventEditDialog.value = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function openDeleteDialog() { | 
					
						
							|  |  |  |   recipeEventDeleteDialog.value = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function contextMenuEventHandler(eventKey: string) { | 
					
						
							|  |  |  |   if (eventKey === "edit") { | 
					
						
							|  |  |  |     openEditDialog(); | 
					
						
							|  |  |  |     loading.value = false; | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (eventKey === "delete") { | 
					
						
							|  |  |  |     openDeleteDialog(); | 
					
						
							|  |  |  |     loading.value = false; | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   emit(eventKey as "delete" | "update"); | 
					
						
							|  |  |  |   loading.value = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function submitEdit() { | 
					
						
							|  |  |  |   emit("update", { ...localEvent.value }); | 
					
						
							|  |  |  |   recipeEventEditDialog.value = false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-12-11 15:16:55 -06:00
										 |  |  | </script> |