ShowMetaImages.vue 4.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
  <div>
    <b-row>
      <b-col lg="2">
        <b-badge style="width:80%;">
          Logo:
        </b-badge> <img
          src="../assets/16x16/emblem-system.png"
          alt="edit"
          @click="openModalLogo()"
        >
      </b-col>
      <b-col lg="4">
        <div v-if="selectedShow.logo.length === 0">
          <small><i>(none set)</i></small>
        </div>
        <div v-else>
          <br>
          <b-img
            thumbnail
            :src="selectedShow.logo"
            fluid
            @click="openModalLogo()"
          />
        </div>
      </b-col>

      <b-col lg="2">
        <b-badge style="width:80%;">
          Image:
        </b-badge> <img
          src="../assets/16x16/emblem-system.png"
          alt="edit"
          @click="openModalImage()"
        >
      </b-col>
      <b-col lg="4">
        <div v-if="selectedShow.image.length === 0">
          <small><i>(none set)</i></small>
        </div>
        <div v-else>
          <br>
          <b-img
            thumbnail
            :src="selectedShow.image"
            fluid
            @click="openModalImage()"
          />
        </div>
      </b-col>
    </b-row>

    <b-modal
      ref="modalLogo"
      title="Logo of this show"
      size="lg"
      @ok="saveLogo"
    >
      <b-row>
        <b-col lg="4">
          <p>Current logo:</p>
        </b-col>
        <b-col lg="8">
          <p v-if="string.length === 0">
            <small><i>(none set)</i></small>
          </p>
          <p v-else>
            <b-img
              thumbnail
              fluid
              :src="string"
            />
          </p>
        </b-col>
      </b-row>
      <b-row>
        <b-col>
          <b-form-file
            ref="fileinputLogo"
            v-model="file"
            accept="image/jpeg, image/png"
            :state="Boolean(file)"
            placeholder="Choose a new logo..."
          />
        </b-col>
      </b-row>
    </b-modal>

    <b-modal
      ref="modalImage"
      title="Image of this show"
      size="lg"
      @ok="saveImage"
    >
      <b-row>
        <b-col lg="4">
          <p>Current image:</p>
        </b-col>
        <b-col lg="8">
          <p v-if="string.length === 0">
            <small><i>(none set)</i></small>
          </p>
          <p v-else>
            <b-img
              thumbnail
              fluid
              :src="string"
            />
          </p>
        </b-col>
      </b-row>
      <b-row>
        <b-col>
          <b-form-file
            ref="fileinputImage"
            v-model="file"
            accept="image/jpeg, image/png"
            :state="Boolean(file)"
            placeholder="Choose a new image..."
          />
        </b-col>
      </b-row>
    </b-modal>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  data () {
    return {
      string: '',
      file: null,
    }
  },
  computed: {
    ...mapGetters({
      selectedShow: 'shows/selectedShow',
    })
  },
  methods: {
    openModalLogo () {
      if (this.selectedShow.logo === null) { this.string = '' }
      else { this.string = this.selectedShow.logo }
      this.file = null
      this.$refs.modalLogo.show()
    },
    openModalImage () {
      if (this.selectedShow.image === null) { this.string = '' }
      else { this.string = this.selectedShow.image }
      this.file = null
      this.$refs.modalImage.show()
    },

    updateImage (type, modal, event) {
      event.preventDefault()
      if (this.file === null) { alert('Please provide a file to upload') }
      else if (this.file.type !== 'image/jpeg' && this.file.type !== 'image/png') { alert('Please provide a valid image file (JPEG or PNG)') }
      else {
        this.$store.dispatch('shows/updateImage', {
          id: this.selectedShow.id,
          type: type,
          file: this.file,
          callback: (response) => {
            this.$log.debug('updateImage callback')
            this.$log.debug(response)
            modal.hide()
          },
        })
      }
    },

    saveImage (event) {
      this.updateImage('image', this.$refs.modalImage, event)
    },

    saveLogo (event) {
      this.updateImage('logo', this.$refs.modalLogo, event)
    },
  }
}
</script>

<style scoped>

</style>