create.vue 1.92 KB
Newer Older
Anton Koch's avatar
Anton Koch committed
1
2
<template lang="pug">
  full-screen
3
4
    q-btn(v-if="!isMobile", slot="backButton", @click="$router.push({ name: 'documents.list' })",
    icon="keyboard_backspace", round, small)
Anton Koch's avatar
Anton Koch committed
5

6
    content-block(:position="'first'")
7
8
9
10
      headline(:content="$t('routes.documents.create.title')")

      content-paragraph(:position="'first'")
        uploader(v-if="user", dark, :url="url", @finish="onFinish", :headers="headers", :fields="uploadFields")
11

Anton Koch's avatar
Anton Koch committed
12
13
14
15
</template>

<script>
  import { mapGetters } from 'vuex'
16
  import Headline from '../../components/shared/elements/Headline'
17
18
  import ContentBlock from '../../components/shared/elements/ContentBlock'
  import ContentParagraph from '../../components/shared/elements/ContentParagraph'
19

Anton Koch's avatar
Anton Koch committed
20
  export default {
21
    components: {
22
23
24
      Headline,
      ContentBlock,
      ContentParagraph
25
    },
Anton Koch's avatar
Anton Koch committed
26
27
28
29
    data () {
      return {
        uploadFields: [],
        headers: {
30
          Authorization: `Bearer ${this.$auth.token}`
Anton Koch's avatar
Anton Koch committed
31
32
33
34
35
        }
      }
    },
    computed: {
      ...mapGetters({
36
37
        user: 'auth/getUserState',
        isMobile: 'globalSettings/getIsMobile'
Anton Koch's avatar
Anton Koch committed
38
39
      }),
      url () {
Anton's avatar
Anton committed
40
        return this.user ? `${process.env.STORAGE_HOST}/files/user-${this.user.uuid}` : undefined
Anton Koch's avatar
Anton Koch committed
41
42
      }
    },
43
44
45
    mounted () {
      this.$root.$emit('setBackButton', 'list')
    },
Anton Koch's avatar
Anton Koch committed
46
47
48
49
50
51
52
53
54
55
56
57
    methods: {
      onFinish (responses) {
        for (let key of Object.keys(responses)) {
          if (responses[key] && responses[key].message) {
            this.$store.commit('notifications/addMessage', {
              body: responses[key].message,
              mode: 'alert',
              type: 'error'
            })
          }
          else {
            this.$store.commit('notifications/addMessage', {
Anton's avatar
Anton committed
58
              body: 'messages.document_created',
Anton Koch's avatar
Anton Koch committed
59
60
61
              mode: 'alert',
              type: 'success'
            })
Anton's avatar
Anton committed
62
            this.$router.push({ name: 'documents.list' })
Anton Koch's avatar
Anton Koch committed
63
64
65
66
67
68
          }
        }
      }
    }
  }
</script>