2021-07-31 23:07:19 +00:00
|
|
|
<template>
|
|
|
|
<div class="text-center">
|
|
|
|
<v-menu offset-y top nudge-top="6" :close-on-content-click="false">
|
2021-08-02 03:24:47 +00:00
|
|
|
<template #activator="{ on, attrs }">
|
2021-07-31 23:07:19 +00:00
|
|
|
<v-btn color="accent" dark v-bind="attrs" v-on="on">
|
|
|
|
<v-icon left>
|
|
|
|
{{ $globals.icons.fileImage }}
|
|
|
|
</v-icon>
|
|
|
|
{{ $t("general.image") }}
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
<v-card width="400">
|
|
|
|
<v-card-title class="headline flex mb-0">
|
|
|
|
<div>
|
|
|
|
{{ $t("recipe.recipe-image") }}
|
|
|
|
</div>
|
2021-08-03 06:15:11 +00:00
|
|
|
<AppButtonUpload
|
2021-07-31 23:07:19 +00:00
|
|
|
class="ml-auto"
|
|
|
|
url="none"
|
|
|
|
file-name="image"
|
|
|
|
:text-btn="false"
|
|
|
|
:post="false"
|
2021-08-02 03:24:47 +00:00
|
|
|
@uploaded="uploadImage"
|
2021-07-31 23:07:19 +00:00
|
|
|
/>
|
|
|
|
</v-card-title>
|
|
|
|
<v-card-text class="mt-n5">
|
|
|
|
<div>
|
2021-08-02 03:24:47 +00:00
|
|
|
<v-text-field v-model="url" :label="$t('general.url')" class="pt-5" clearable :messages="getMessages()">
|
|
|
|
<template #append-outer>
|
|
|
|
<v-btn class="ml-2" color="primary" :loading="loading" :disabled="!slug" @click="getImageFromURL">
|
2021-07-31 23:07:19 +00:00
|
|
|
{{ $t("general.get") }}
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
</v-text-field>
|
|
|
|
</div>
|
|
|
|
</v-card-text>
|
|
|
|
</v-card>
|
|
|
|
</v-menu>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-04 05:38:45 +00:00
|
|
|
import { defineComponent } from "@nuxtjs/composition-api";
|
|
|
|
import { useApiSingleton } from "~/composables/use-api";
|
2021-08-02 03:24:47 +00:00
|
|
|
const REFRESH_EVENT = "refresh";
|
|
|
|
const UPLOAD_EVENT = "upload";
|
2021-08-04 05:38:45 +00:00
|
|
|
export default defineComponent({
|
2021-07-31 23:07:19 +00:00
|
|
|
props: {
|
2021-08-04 05:38:45 +00:00
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup() {
|
|
|
|
const api = useApiSingleton();
|
|
|
|
|
|
|
|
return { api };
|
2021-07-31 23:07:19 +00:00
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
url: "",
|
|
|
|
loading: false,
|
|
|
|
}),
|
|
|
|
methods: {
|
|
|
|
uploadImage(fileObject) {
|
|
|
|
this.$emit(UPLOAD_EVENT, fileObject);
|
|
|
|
},
|
|
|
|
async getImageFromURL() {
|
|
|
|
this.loading = true;
|
2021-08-04 05:38:45 +00:00
|
|
|
if (await this.api.recipes.updateImagebyURL(this.slug, this.url)) {
|
2021-07-31 23:07:19 +00:00
|
|
|
this.$emit(REFRESH_EVENT);
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
getMessages() {
|
|
|
|
return this.slug ? [""] : [this.$i18n.t("recipe.save-recipe-before-use")];
|
|
|
|
},
|
|
|
|
},
|
2021-08-04 05:38:45 +00:00
|
|
|
});
|
2021-07-31 23:07:19 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped></style>
|