2022-09-20 19:59:52 +00:00
|
|
|
<template>
|
|
|
|
<div class="flex flex-wrap flex-col">
|
|
|
|
<transition v-if="stateReady" name="fade" mode="out-in">
|
2022-10-26 14:44:47 +00:00
|
|
|
<div key="2">
|
2022-09-20 19:59:52 +00:00
|
|
|
<form-editor v-if="!workspacesLoading" ref="editor"
|
2022-10-26 14:44:47 +00:00
|
|
|
class="w-full flex flex-grow"
|
2022-09-20 19:59:52 +00:00
|
|
|
:style="{
|
|
|
|
'max-height': editorMaxHeight + 'px'
|
|
|
|
}" :error="error"
|
|
|
|
@mounted="onResize"
|
|
|
|
/>
|
|
|
|
<div v-else class="text-center mt-4 py-6">
|
|
|
|
<loader class="h-6 w-6 text-nt-blue mx-auto"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-10-02 18:38:41 +00:00
|
|
|
import store from '~/store'
|
2022-09-20 19:59:52 +00:00
|
|
|
import Form from 'vform'
|
|
|
|
import {mapState, mapActions} from 'vuex'
|
|
|
|
|
|
|
|
const FormEditor = () => import('../../components/open/forms/components/FormEditor')
|
2022-10-02 18:38:41 +00:00
|
|
|
|
|
|
|
const loadTemplates = function () {
|
|
|
|
store.commit('open/templates/startLoading')
|
|
|
|
store.dispatch('open/templates/loadIfEmpty').then(() => {
|
|
|
|
store.commit('open/templates/stopLoading')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-20 19:59:52 +00:00
|
|
|
export default {
|
|
|
|
name: 'CreateForm',
|
|
|
|
components: {
|
|
|
|
FormEditor,
|
|
|
|
},
|
|
|
|
|
|
|
|
metaInfo() {
|
|
|
|
return {title: 'Create a new Form'}
|
|
|
|
},
|
|
|
|
|
2022-10-02 18:38:41 +00:00
|
|
|
beforeRouteEnter (to, from, next) {
|
|
|
|
loadTemplates()
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
|
2022-09-20 19:59:52 +00:00
|
|
|
middleware: 'auth',
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
stateReady: false,
|
|
|
|
loading: false,
|
|
|
|
error: '',
|
|
|
|
editorMaxHeight: 500
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
workspaces: state => state['open/workspaces'].content,
|
|
|
|
workspacesLoading: state => state['open/workspaces'].loading,
|
|
|
|
user: state => state.auth.user
|
|
|
|
}),
|
|
|
|
form: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state['open/working_form'].content
|
|
|
|
},
|
|
|
|
/* We add a setter */
|
|
|
|
set(value) {
|
|
|
|
this.$store.commit('open/working_form/set', value)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
workspace() {
|
|
|
|
return this.$store.getters['open/workspaces/getCurrent']()
|
|
|
|
},
|
|
|
|
fromOnboarding() {
|
|
|
|
return this.$route.params.from_onboarding
|
|
|
|
},
|
|
|
|
fbGroupLink() {
|
|
|
|
return window.config.links.facebook_group
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
workspace() {
|
|
|
|
if (this.workspace) {
|
|
|
|
this.form.workspace_id = this.workspace.id
|
|
|
|
}
|
|
|
|
},
|
|
|
|
user() {
|
|
|
|
this.stateReady = true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2022-10-02 18:38:41 +00:00
|
|
|
if(this.$route.query.template !== undefined && this.$route.query.template){
|
|
|
|
let template = this.$store.getters['open/templates/getBySlug'](this.$route.query.template)
|
|
|
|
if(template && template.structure){
|
|
|
|
this.form = new Form(template.structure)
|
|
|
|
}else{
|
|
|
|
this.initForm()
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.initForm()
|
|
|
|
}
|
2022-09-20 19:59:52 +00:00
|
|
|
this.closeAlert()
|
|
|
|
this.loadWorkspaces()
|
|
|
|
|
|
|
|
this.stateReady = this.user !== null
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
window.addEventListener('resize', this.onResize)
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
window.removeEventListener('resize', this.onResize)
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
|
|
|
loadWorkspaces: 'open/workspaces/loadIfEmpty'
|
|
|
|
}),
|
|
|
|
initForm() {
|
|
|
|
this.form = new Form({
|
|
|
|
title: 'My Form',
|
|
|
|
description: null,
|
2022-10-16 17:27:14 +00:00
|
|
|
visibility: 'public',
|
2022-09-20 19:59:52 +00:00
|
|
|
workspace_id: this.workspace?.id,
|
|
|
|
properties: [],
|
|
|
|
|
|
|
|
notifies: false,
|
2022-09-21 15:23:37 +00:00
|
|
|
slack_notifies: false,
|
2022-09-20 19:59:52 +00:00
|
|
|
send_submission_confirmation: false,
|
|
|
|
webhook_url: null,
|
|
|
|
|
|
|
|
// Customization
|
|
|
|
theme: 'default',
|
|
|
|
width: 'centered',
|
|
|
|
dark_mode: 'auto',
|
|
|
|
color: '#3B82F6',
|
|
|
|
hide_title: false,
|
|
|
|
no_branding: false,
|
|
|
|
uppercase_labels: true,
|
|
|
|
transparent_background: false,
|
|
|
|
closes_at: null,
|
|
|
|
closed_text: 'This form has now been closed by its owner and does not accept submissions anymore.',
|
|
|
|
|
|
|
|
// Submission
|
|
|
|
submit_button_text: 'Submit',
|
|
|
|
re_fillable: false,
|
|
|
|
re_fill_button_text: 'Fill Again',
|
|
|
|
submitted_text: 'Amazing, we saved your answers. Thank you for your time and have a great day!',
|
|
|
|
notification_sender: 'OpnForm',
|
|
|
|
notification_subject: 'We saved your answers',
|
|
|
|
notification_body: 'Hello there 👋 <br>This is a confirmation that your submission was successfully saved.',
|
|
|
|
notifications_include_submission: true,
|
|
|
|
use_captcha: false,
|
|
|
|
is_rating: false,
|
|
|
|
rating_max_value: 5,
|
|
|
|
max_submissions_count: null,
|
|
|
|
max_submissions_reached_text: 'This form has now reached the maximum number of allowed submissions and is now closed.',
|
|
|
|
|
|
|
|
// Security & Privacy
|
|
|
|
can_be_indexed: true
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Compute max height of editor
|
|
|
|
*/
|
|
|
|
onResize() {
|
|
|
|
if (this.$refs.editor) {
|
|
|
|
this.editorMaxHeight = window.innerHeight - this.$refs.editor.$el.offsetTop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|