2021-04-25 21:10:45 -05:00
|
|
|
<template>
|
2022-06-30 07:38:34 -05:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="800" :margin-min="16" :margin-max="32">
|
|
|
|
<FormSuspense :p="init">
|
|
|
|
<FormInput v-model="title">
|
2022-07-20 08:24:26 -05:00
|
|
|
<template #label>{{ i18n.ts.title }}</template>
|
2022-06-30 07:38:34 -05:00
|
|
|
</FormInput>
|
|
|
|
|
|
|
|
<FormTextarea v-model="description" :max="500">
|
2022-07-20 08:24:26 -05:00
|
|
|
<template #label>{{ i18n.ts.description }}</template>
|
2022-06-30 07:38:34 -05:00
|
|
|
</FormTextarea>
|
|
|
|
|
|
|
|
<div class="">
|
|
|
|
<div v-for="file in files" :key="file.id" class="wqugxsfx" :style="{ backgroundImage: file ? `url(${ file.thumbnailUrl })` : null }">
|
|
|
|
<div class="name">{{ file.name }}</div>
|
2022-12-19 04:01:30 -06:00
|
|
|
<button v-tooltip="i18n.ts.remove" class="remove _button" @click="remove(file)"><i class="ti ti-x"></i></button>
|
2022-06-30 07:38:34 -05:00
|
|
|
</div>
|
2023-01-05 18:41:14 -06:00
|
|
|
<MkButton primary @click="selectFile"><i class="ti ti-plus"></i> {{ i18n.ts.attachFile }}</MkButton>
|
2021-04-25 21:10:45 -05:00
|
|
|
</div>
|
|
|
|
|
2022-07-20 08:24:26 -05:00
|
|
|
<FormSwitch v-model="isSensitive">{{ i18n.ts.markAsSensitive }}</FormSwitch>
|
2021-04-25 21:10:45 -05:00
|
|
|
|
2023-01-05 18:41:14 -06:00
|
|
|
<MkButton v-if="postId" primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton v-else primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.publish }}</MkButton>
|
2021-04-25 21:10:45 -05:00
|
|
|
|
2023-01-05 18:41:14 -06:00
|
|
|
<MkButton v-if="postId" danger @click="del"><i class="ti ti-trash"></i> {{ i18n.ts.delete }}</MkButton>
|
2022-06-30 07:38:34 -05:00
|
|
|
</FormSuspense>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2021-04-25 21:10:45 -05:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 03:38:49 -05:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, inject, watch } from 'vue';
|
2023-01-05 18:41:14 -06:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2022-01-04 07:42:04 -06:00
|
|
|
import FormInput from '@/components/form/input.vue';
|
|
|
|
import FormTextarea from '@/components/form/textarea.vue';
|
|
|
|
import FormSwitch from '@/components/form/switch.vue';
|
|
|
|
import FormSuspense from '@/components/form/suspense.vue';
|
2021-12-09 10:22:22 -06:00
|
|
|
import { selectFiles } from '@/scripts/select-file';
|
2021-11-11 11:02:25 -06:00
|
|
|
import * as os from '@/os';
|
2022-06-20 03:38:49 -05:00
|
|
|
import { useRouter } from '@/router';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
postId?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let init = $ref(null);
|
|
|
|
let files = $ref([]);
|
|
|
|
let description = $ref(null);
|
|
|
|
let title = $ref(null);
|
|
|
|
let isSensitive = $ref(false);
|
|
|
|
|
|
|
|
function selectFile(evt) {
|
|
|
|
selectFiles(evt.currentTarget ?? evt.target, null).then(selected => {
|
|
|
|
files = files.concat(selected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(file) {
|
|
|
|
files = files.filter(f => f.id !== file.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
if (props.postId) {
|
|
|
|
await os.apiWithDialog('gallery/posts/update', {
|
|
|
|
postId: props.postId,
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
fileIds: files.map(file => file.id),
|
|
|
|
isSensitive: isSensitive,
|
|
|
|
});
|
2022-06-30 07:38:34 -05:00
|
|
|
router.push(`/gallery/${props.postId}`);
|
2022-06-20 03:38:49 -05:00
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('gallery/posts/create', {
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
fileIds: files.map(file => file.id),
|
|
|
|
isSensitive: isSensitive,
|
|
|
|
});
|
|
|
|
router.push(`/gallery/${created.id}`);
|
2021-04-25 21:10:45 -05:00
|
|
|
}
|
2022-06-20 03:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function del() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.ts.deleteConfirm,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('gallery/posts/delete', {
|
|
|
|
postId: props.postId,
|
|
|
|
});
|
2022-06-30 07:38:34 -05:00
|
|
|
router.push('/gallery');
|
2022-06-20 03:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
watch(() => props.postId, () => {
|
|
|
|
init = () => props.postId ? os.api('gallery/posts/show', {
|
|
|
|
postId: props.postId,
|
|
|
|
}).then(post => {
|
|
|
|
files = post.files;
|
|
|
|
title = post.title;
|
|
|
|
description = post.description;
|
|
|
|
isSensitive = post.isSensitive;
|
|
|
|
}) : Promise.resolve(null);
|
|
|
|
}, { immediate: true });
|
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => props.postId ? {
|
|
|
|
title: i18n.ts.edit,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-pencil',
|
2022-06-20 03:38:49 -05:00
|
|
|
} : {
|
|
|
|
title: i18n.ts.postToGallery,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-pencil',
|
2022-06-20 03:38:49 -05:00
|
|
|
}));
|
2021-04-25 21:10:45 -05:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 03:29:39 -06:00
|
|
|
<style lang="scss" scoped>
|
2021-04-25 21:10:45 -05:00
|
|
|
.wqugxsfx {
|
|
|
|
height: 200px;
|
|
|
|
background-size: contain;
|
|
|
|
background-position: center;
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
left: 9px;
|
|
|
|
padding: 8px;
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remove {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 9px;
|
|
|
|
padding: 8px;
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|