2020-03-20 12:22:07 +01:00
|
|
|
<!--
|
|
|
|
- @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
-
|
|
|
|
- @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
-
|
|
|
|
- @license GNU AGPL version 3 or any later version
|
|
|
|
-
|
|
|
|
- This program is free software: you can redistribute it and/or modify
|
|
|
|
- it under the terms of the GNU Affero General Public License as
|
|
|
|
- published by the Free Software Foundation, either version 3 of the
|
|
|
|
- License, or (at your option) any later version.
|
|
|
|
-
|
|
|
|
- This program is distributed in the hope that it will be useful,
|
|
|
|
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
- GNU Affero General Public License for more details.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the GNU Affero General Public License
|
|
|
|
- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
-
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<AppNavigationItem
|
2020-03-26 10:22:14 +01:00
|
|
|
ref="navigationItem"
|
2020-03-20 12:22:07 +01:00
|
|
|
:exact="true"
|
2020-03-25 17:40:59 +01:00
|
|
|
:icon="loading ? 'icon-loading-small' : ''"
|
2020-03-20 12:22:07 +01:00
|
|
|
:title="form.title"
|
|
|
|
:to="{ name: 'edit', params: { hash: form.hash } }">
|
2020-03-21 19:07:46 +01:00
|
|
|
<AppNavigationIconBullet slot="icon" :color="bulletColor" />
|
2020-03-25 17:40:59 +01:00
|
|
|
<template v-if="!loading" #actions>
|
2020-03-26 10:22:14 +01:00
|
|
|
<ActionLink
|
|
|
|
:href="formLink"
|
|
|
|
:icon="copied && copySuccess ? 'icon-checkmark-color' : 'icon-clippy'"
|
|
|
|
target="_blank"
|
|
|
|
@click.stop.prevent="copyLink">
|
|
|
|
{{ clipboardTooltip }}
|
|
|
|
</ActionLink>
|
2020-03-20 12:22:07 +01:00
|
|
|
<ActionRouter :close-after-click="true"
|
|
|
|
:exact="true"
|
2020-03-26 10:22:14 +01:00
|
|
|
icon="icon-forms"
|
2020-03-20 12:22:07 +01:00
|
|
|
:to="{ name: 'results', params: { hash: form.hash } }">
|
|
|
|
{{ t('forms', 'Show results') }}
|
|
|
|
</ActionRouter>
|
2020-03-25 17:40:59 +01:00
|
|
|
<!-- <ActionRouter :close-after-click="true"
|
2020-03-20 12:22:07 +01:00
|
|
|
:exact="true"
|
|
|
|
icon="icon-clone"
|
|
|
|
:to="{ name: 'clone', params: { hash: form.hash } }">
|
|
|
|
{{ t('forms', 'Clone form') }}
|
2020-03-25 17:40:59 +01:00
|
|
|
</ActionRouter> -->
|
2020-03-20 12:22:07 +01:00
|
|
|
<ActionSeparator />
|
2020-03-25 17:40:59 +01:00
|
|
|
<ActionButton :close-after-click="true" icon="icon-delete" @click="onDeleteForm">
|
2020-03-20 12:22:07 +01:00
|
|
|
{{ t('forms', 'Delete form') }}
|
|
|
|
</ActionButton>
|
|
|
|
</template>
|
|
|
|
</AppNavigationItem>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-03-25 17:40:59 +01:00
|
|
|
import { generateUrl } from '@nextcloud/router'
|
2020-03-26 10:22:14 +01:00
|
|
|
import { showError, showSuccess } from '@nextcloud/dialogs'
|
2020-03-20 12:22:07 +01:00
|
|
|
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
|
2020-03-26 10:22:14 +01:00
|
|
|
import ActionLink from '@nextcloud/vue/dist/Components/ActionLink'
|
2020-03-20 12:22:07 +01:00
|
|
|
import ActionRouter from '@nextcloud/vue/dist/Components/ActionRouter'
|
|
|
|
import ActionSeparator from '@nextcloud/vue/dist/Components/ActionSeparator'
|
2020-03-26 10:22:14 +01:00
|
|
|
import AppNavigationIconBullet from '@nextcloud/vue/dist/Components/AppNavigationIconBullet'
|
|
|
|
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
|
|
|
|
import axios from '@nextcloud/axios'
|
2020-04-20 13:51:48 +02:00
|
|
|
import moment from '@nextcloud/moment'
|
2020-03-26 10:22:14 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
import VueClipboard from 'vue-clipboard2'
|
|
|
|
|
|
|
|
Vue.use(VueClipboard)
|
2020-03-20 12:22:07 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'AppNavigationForm',
|
|
|
|
|
|
|
|
components: {
|
|
|
|
AppNavigationItem,
|
2020-03-21 19:07:46 +01:00
|
|
|
AppNavigationIconBullet,
|
2020-03-20 12:22:07 +01:00
|
|
|
ActionButton,
|
2020-03-26 10:22:14 +01:00
|
|
|
ActionLink,
|
2020-03-20 12:22:07 +01:00
|
|
|
ActionRouter,
|
|
|
|
ActionSeparator,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
form: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-03-25 17:40:59 +01:00
|
|
|
data() {
|
|
|
|
return {
|
2020-03-26 10:22:14 +01:00
|
|
|
copySuccess: true,
|
|
|
|
copied: false,
|
2020-03-25 17:40:59 +01:00
|
|
|
loading: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-03-21 19:07:46 +01:00
|
|
|
computed: {
|
|
|
|
/**
|
|
|
|
* Map form state to bullet color
|
|
|
|
*
|
|
|
|
* @returns {string} hex color
|
|
|
|
*/
|
|
|
|
bulletColor() {
|
|
|
|
const style = getComputedStyle(document.body)
|
2020-04-20 13:51:48 +02:00
|
|
|
if (this.form.expires && moment().unix() > this.form.expires) {
|
2020-03-21 19:07:46 +01:00
|
|
|
return style.getPropertyValue('--color-error').slice(-6)
|
|
|
|
}
|
|
|
|
return style.getPropertyValue('--color-success').slice(-6)
|
|
|
|
},
|
2020-03-26 10:22:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the form share link
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
formLink() {
|
|
|
|
return window.location.protocol + '//' + window.location.host + generateUrl(`/apps/forms/${this.form.hash}`)
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clipboard v-tooltip message
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
clipboardTooltip() {
|
|
|
|
if (this.copied) {
|
|
|
|
return this.copySuccess
|
|
|
|
? t('forms', 'Form link copied')
|
|
|
|
: t('forms', 'Cannot copy, please copy the link manually')
|
|
|
|
}
|
2020-04-23 14:38:32 +02:00
|
|
|
return t('forms', 'Copy share link')
|
2020-03-26 10:22:14 +01:00
|
|
|
},
|
2020-03-21 19:07:46 +01:00
|
|
|
},
|
|
|
|
|
2020-03-20 12:22:07 +01:00
|
|
|
methods: {
|
2020-03-25 17:40:59 +01:00
|
|
|
async onDeleteForm() {
|
2020-03-27 11:00:44 +01:00
|
|
|
if (!confirm(t('forms', 'Are you sure you want to delete the form “{title}”?', { title: this.form.title }))) {
|
2020-03-25 17:40:59 +01:00
|
|
|
return
|
|
|
|
}
|
2020-03-20 12:22:07 +01:00
|
|
|
|
2020-03-25 17:40:59 +01:00
|
|
|
// All good, let's delete
|
|
|
|
this.loading = true
|
|
|
|
try {
|
|
|
|
await axios.delete(generateUrl('/apps/forms/api/v1/form/{id}', { id: this.form.id }))
|
|
|
|
this.$emit('delete', this.form.id)
|
|
|
|
showSuccess(t('forms', 'Deleted form “{title}”', { title: this.form.title }))
|
|
|
|
} catch (error) {
|
|
|
|
showError(t('forms', 'Error while deleting form “{title}”', { title: this.form.title }))
|
|
|
|
console.error(error.response)
|
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
2020-03-20 12:22:07 +01:00
|
|
|
},
|
2020-03-25 17:40:59 +01:00
|
|
|
|
2020-03-26 10:22:14 +01:00
|
|
|
async copyLink() {
|
|
|
|
try {
|
|
|
|
await this.$copyText(this.formLink)
|
|
|
|
// make sure the menu stays open despite the click outside
|
|
|
|
this.$refs.navigationItem.menuOpened = true
|
|
|
|
this.copySuccess = true
|
|
|
|
this.copied = true
|
|
|
|
} catch (error) {
|
|
|
|
this.copySuccess = false
|
|
|
|
this.copied = true
|
|
|
|
console.error(error)
|
|
|
|
} finally {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.copySuccess = false
|
|
|
|
this.copied = false
|
|
|
|
}, 4000)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-03-20 12:22:07 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|