diff --git a/src/components/DialogWrapper.vue b/src/components/DialogWrapper.vue new file mode 100644 index 0000000..93f749b --- /dev/null +++ b/src/components/DialogWrapper.vue @@ -0,0 +1,38 @@ + + + diff --git a/src/components/FormWrapper.vue b/src/components/FormWrapper.vue index 902f80b..3152e3b 100644 --- a/src/components/FormWrapper.vue +++ b/src/components/FormWrapper.vue @@ -6,7 +6,6 @@ import {useSlots} from "vue"; const props = defineProps({ modelValue: { type: Object, - required: true }, resetAfterSubmit: { type: Boolean, @@ -14,9 +13,8 @@ const props = defineProps({ default: false }, isRequestPending, - saveButton: { - type: Object, + type: [Object, Boolean], required: false, default: () => ({ label: "Save", @@ -42,7 +40,7 @@ const saveForm = () => { - + {{ props.saveButton.label }} diff --git a/src/pages/profile/forms/FlightEditPage.vue b/src/pages/profile/forms/FlightEditPage.vue index 47d3c4c..c0e0717 100644 --- a/src/pages/profile/forms/FlightEditPage.vue +++ b/src/pages/profile/forms/FlightEditPage.vue @@ -15,6 +15,9 @@ import {useSecondPilotsStore} from "stores/SecondPilots"; import FlightFormNotes from "components/flights/form/FlightFormNotes.vue"; import FlightFormPhotos from "components/flights/form/FlightFormPhotos.vue"; import {usePhotosStore} from "stores/Photo"; +import PhotosList from "components/photos/PhotosList.vue"; +import {confirmObject, successObject} from "src/composables/dialog"; +import PhotoForm from "components/flights/PhotoForm.vue"; useMeta({title: "Editace letu"}); @@ -54,27 +57,49 @@ onMounted(() => { const handleFlightEdit = (data) => { useFlightsStore().update(flightId, data).then(() => { - $q.notify({message: "Uspesne upraveno", position: "top", color: "positive"}); - + $q.notify(successObject("Úspěšně upraveno")); fetchFlight(flightId); }) } const handlePhotosUpload = (data) => { - - console.log(data); - const promises = []; for (const photo of data.photos) { promises.push(usePhotosStore().upload(flightId, {photo})); } Promise.all(promises).then(() => { - $q.notify({message: "Uspesne nahrano", position: "top", color: "positive"}); - - fetchFlight(flightId); + $q.notify(successObject("Úspěšně nahráno")); + fetchFlight(flightId); }); } + +const _findPhotoIndex = (photoId) => flight.value.photos.findIndex((object) => object.id === photoId); +const confirmPhotoDelete = (id) => { + $q.dialog(confirmObject("Opravdu chces smazat tuto fotku?")) + .onOk(() => { + usePhotosStore().delete(id).then((data) => { + flight.value.photos.splice(_findPhotoIndex(data.id), 1); + }); + }); +} + +const handlePhotoUpdate = (formData) => { + const photoId = formData.id; + delete formData.id; + + usePhotosStore().update(photoId, formData).then((data) => { + const idx = _findPhotoIndex(data.id); + flight.value.photos[idx] = data; + }) +} + +const openEdit = ref(false); +const editPhoto = ref(null); +const openPhotoEdit = (photo) => { + openEdit.value = true; + editPhoto.value = photo; +}