|
|
|
@ -4,7 +4,7 @@ |
|
|
|
--> |
|
|
|
|
|
|
|
<template> |
|
|
|
<NcDialog :name="t('spreed', 'Create new poll')" |
|
|
|
<NcDialog :name="dialogName" |
|
|
|
:close-on-click-outside="!isFilled" |
|
|
|
:container="container" |
|
|
|
v-on="$listeners" |
|
|
|
@ -89,7 +89,7 @@ |
|
|
|
</div> |
|
|
|
<template #actions> |
|
|
|
<NcActions v-if="supportPollDrafts" force-menu> |
|
|
|
<NcActionButton v-if="props.canCreatePollDrafts" :disabled="!isFilled" @click="createPollDraft"> |
|
|
|
<NcActionButton v-if="props.canCreatePollDrafts && !editingDraftId" :disabled="!isFilled" @click="createPollDraft"> |
|
|
|
<template #icon> |
|
|
|
<IconFileEdit :size="20" /> |
|
|
|
</template> |
|
|
|
@ -102,7 +102,7 @@ |
|
|
|
{{ t('spreed', 'Export draft to file') }} |
|
|
|
</NcActionLink> |
|
|
|
</NcActions> |
|
|
|
<NcButton type="primary" :disabled="!isFilled" @click="createPoll"> |
|
|
|
<NcButton type="primary" :disabled="!isFilled" @click="handleSubmit"> |
|
|
|
{{ createPollLabel }} |
|
|
|
</NcButton> |
|
|
|
</template> |
|
|
|
@ -157,6 +157,7 @@ const store = useStore() |
|
|
|
const pollsStore = usePollsStore() |
|
|
|
|
|
|
|
const isOpenedFromDraft = ref(false) |
|
|
|
const editingDraftId = ref<number | null>(null) |
|
|
|
const pollOption = ref<InstanceType<typeof NcTextField>[] | null>(null) |
|
|
|
const pollImport = ref<HTMLInputElement | null>(null) |
|
|
|
|
|
|
|
@ -168,7 +169,14 @@ const pollForm = reactive<createPollParams>({ |
|
|
|
}) |
|
|
|
|
|
|
|
const isFilled = computed(() => Boolean(pollForm.question) && pollForm.options.filter(option => Boolean(option)).length >= 2) |
|
|
|
const dialogName = computed(() => { |
|
|
|
return editingDraftId.value ? t('spreed', 'Edit poll draft') : t('spreed', 'Create new poll') |
|
|
|
}) |
|
|
|
const createPollLabel = computed(() => { |
|
|
|
if (editingDraftId.value) { |
|
|
|
return t('spreed', 'Save') |
|
|
|
} |
|
|
|
|
|
|
|
return store.getters.getToken() !== props.token |
|
|
|
? t('spreed', 'Create poll in {name}', { name: store.getters.conversation(props.token).displayName }, |
|
|
|
undefined, { escape: false, sanitize: false }) |
|
|
|
@ -217,7 +225,22 @@ function addOption() { |
|
|
|
/** |
|
|
|
* Post a poll into conversation |
|
|
|
*/ |
|
|
|
async function createPoll() { |
|
|
|
async function handleSubmit() { |
|
|
|
if (editingDraftId.value) { |
|
|
|
const pollDraft = await pollsStore.updatePollDraft({ |
|
|
|
token: props.token, |
|
|
|
pollId: editingDraftId.value, |
|
|
|
form: pollForm, |
|
|
|
}) |
|
|
|
if (pollDraft) { |
|
|
|
openPollDraftHandler() |
|
|
|
nextTick(() => { |
|
|
|
emit('close') |
|
|
|
}) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
const poll = await pollsStore.createPoll({ |
|
|
|
token: props.token, |
|
|
|
form: pollForm, |
|
|
|
@ -231,12 +254,17 @@ async function createPoll() { |
|
|
|
* Pre-fills form from the draft |
|
|
|
* @param id poll draft ID |
|
|
|
* @param fromDrafts whether editor was opened from drafts handler |
|
|
|
* @param action required action ('fill' from draft or 'edit' draft) |
|
|
|
*/ |
|
|
|
function fillPollEditorFromDraft(id: number | null, fromDrafts: boolean) { |
|
|
|
function fillPollEditorFromDraft(id: number | null, fromDrafts: boolean, action?: string) { |
|
|
|
if (fromDrafts) { |
|
|
|
// Show 'Back' button, do not reset until closed |
|
|
|
isOpenedFromDraft.value = true |
|
|
|
} |
|
|
|
if (action === 'edit') { |
|
|
|
// Show Edit interface |
|
|
|
editingDraftId.value = id |
|
|
|
} |
|
|
|
|
|
|
|
if (id === null) { |
|
|
|
return |
|
|
|
|