parent
0747f23abc
commit
95d679d00b
@ -0,0 +1,100 @@ |
||||
<template> |
||||
<v-form> |
||||
<v-container fluid> |
||||
<v-row> |
||||
<v-col cols="12" sm="6" md="6"> |
||||
<v-text-field |
||||
v-model="item.title" |
||||
:error-messages="titleErrors" |
||||
:label="$t('Title')" |
||||
required |
||||
@input="$v.item.title.$touch()" |
||||
@blur="$v.item.title.$touch()" |
||||
/> |
||||
<v-textarea |
||||
v-model="item.content" |
||||
:label="$t('Text')" |
||||
value="" |
||||
></v-textarea> |
||||
</v-col> |
||||
</v-row> |
||||
</v-container> |
||||
</v-form> |
||||
</template> |
||||
|
||||
<script> |
||||
import has from 'lodash/has'; |
||||
import { validationMixin } from 'vuelidate'; |
||||
import { required } from 'vuelidate/lib/validators'; |
||||
import { mapActions } from 'vuex'; |
||||
import { mapFields } from 'vuex-map-fields'; |
||||
|
||||
export default { |
||||
name: 'DocumentsForm', |
||||
mixins: [validationMixin], |
||||
props: { |
||||
values: { |
||||
type: Object, |
||||
required: true |
||||
}, |
||||
errors: { |
||||
type: Object, |
||||
default: () => {} |
||||
}, |
||||
initialValues: { |
||||
type: Object, |
||||
default: () => {} |
||||
}, |
||||
}, |
||||
created () { |
||||
}, |
||||
data() { |
||||
return { |
||||
title: null, |
||||
content: null, |
||||
parentResourceNodeId: null, |
||||
}; |
||||
}, |
||||
computed: { |
||||
// eslint-disable-next-line |
||||
item() { |
||||
return this.initialValues || this.values; |
||||
}, |
||||
titleErrors() { |
||||
const errors = []; |
||||
|
||||
if (!this.$v.item.title.$dirty) return errors; |
||||
has(this.violations, 'title') && errors.push(this.violations.title); |
||||
!this.$v.item.title.required && errors.push(this.$t('Field is required')); |
||||
|
||||
return errors; |
||||
}, |
||||
contentErrors() { |
||||
const errors = []; |
||||
|
||||
if (!this.$v.item.content.$dirty) return errors; |
||||
has(this.violations, 'content') && errors.push(this.violations.content); |
||||
!this.$v.item.content.required && errors.push(this.$t('Field is required')); |
||||
|
||||
return errors; |
||||
}, |
||||
violations() { |
||||
return this.errors || {}; |
||||
} |
||||
}, |
||||
methods: { |
||||
}, |
||||
validations: { |
||||
item: { |
||||
title: { |
||||
required, |
||||
}, |
||||
content: { |
||||
required, |
||||
}, |
||||
parentResourceNodeId: { |
||||
}, |
||||
} |
||||
} |
||||
}; |
||||
</script> |
@ -0,0 +1,56 @@ |
||||
<template> |
||||
<div> |
||||
<Toolbar :handle-submit="onSendForm" :handle-reset="resetForm"></Toolbar> |
||||
<DocumentsForm ref="createForm" :values="item" :errors="violations" /> |
||||
<Loading :visible="isLoading" /> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import { mapActions } from 'vuex'; |
||||
import { createHelpers } from 'vuex-map-fields'; |
||||
import DocumentsForm from '../../components/documents/FormUpload'; |
||||
import Loading from '../../components/Loading'; |
||||
import Toolbar from '../../components/Toolbar'; |
||||
import CreateMixin from '../../mixins/CreateMixin'; |
||||
|
||||
const servicePrefix = 'Documents'; |
||||
|
||||
const { mapFields } = createHelpers({ |
||||
getterType: 'documents/getField', |
||||
mutationType: 'documents/updateField' |
||||
}); |
||||
|
||||
export default { |
||||
name: 'DocumentsCreate', |
||||
servicePrefix, |
||||
mixins: [CreateMixin], |
||||
components: { |
||||
Loading, |
||||
Toolbar, |
||||
DocumentsForm |
||||
}, |
||||
data() { |
||||
return { |
||||
item: { |
||||
filetype: 'file', |
||||
parentResourceNodeId: null, |
||||
resourceLinkList: null |
||||
}, |
||||
}; |
||||
}, |
||||
computed: { |
||||
...mapFields(['error', 'isLoading', 'created', 'violations']) |
||||
}, |
||||
created() { |
||||
this.item.parentResourceNodeId = this.$route.params.node; |
||||
this.item.resourceLinkList = JSON.stringify([{ |
||||
c_id: this.$route.query.cid, |
||||
visibility: 2, |
||||
}]); |
||||
}, |
||||
methods: { |
||||
...mapActions('documents', ['create', 'reset']) |
||||
} |
||||
}; |
||||
</script> |
Loading…
Reference in new issue