MetaSimpleTypes.vue 13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<template>
  <div>
    <b-row>
      <b-col lg="6">
        <p>
          <b-badge variant="light">
            E-Mail:
          </b-badge>
          <span v-if="selectedShow.email === null"><small><i>(none set)</i></small></span>
          <span v-else>{{ selectedShow.email }}</span>
          <img
12
            src="../../assets/16x16/emblem-system.png"
13
14
15
16
17
18
19
20
21
22
23
24
25
26
            alt="edit contact e-mail"
            @click="openModalEmail()"
          >
        </p>
      </b-col>

      <b-col lg="6">
        <p>
          <b-badge variant="light">
            Website:
          </b-badge>
          <span v-if="selectedShow.website === null"><small><i>(none set)</i></small></span>
          <span v-else><a :href="selectedShow.website">{{ selectedShow.website }}</a></span>
          <img
27
            src="../../assets/16x16/emblem-system.png"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
            alt="edit website"
            @click="openModalWebsite()"
          >
        </p>
      </b-col>

      <b-col lg="6">
        <p>
          <b-badge variant="light">
            Show type:
          </b-badge>
          <!-- TODO: discuss: should this be visible to show owners or only to administrators? -->
          <span v-if="loaded.types">
            <span v-if="selectedShow.type === null"><small><i>(none set)</i></small></span>
            <span v-else>{{ type }}</span>
            <img
44
              src="../../assets/16x16/emblem-system.png"
45
46
47
48
49
              alt="edit"
              @click="openModalType()"
            >
          </span>
          <span v-else><img
50
            src="../../assets/radio.gif"
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
            height="24px"
            alt="loading data"
          ></span>
        </p>
      </b-col>

      <b-col lg="6">
        <p>
          <b-badge variant="light">
            Funding category (eg. for RTR):
          </b-badge>
          <!-- TODO: discuss: should this be visible to show owners or only to administrators? -->
          <span v-if="loaded.fundingcategories">
            <span v-if="selectedShow.fundingcategory === null"><small><i>(none set)</i></small></span>
            <span v-else>{{ fundingCategory }}</span>
            <img
67
              src="../../assets/16x16/emblem-system.png"
68
69
70
71
72
              alt="edit"
              @click="openModalFundingCategory()"
            >
          </span>
          <span v-else><img
73
            src="../../assets/radio.gif"
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
            height="24px"
            alt="loading data"
          ></span>
        </p>
      </b-col>

      <b-col lg="6">
        <p>
          <!-- TODO: discuss: should this be visible to show owners or only to administrators? -->
          <!-- TODO: fetch name for predecessor from steering api -->
          <b-badge variant="light">
            Predecessor:
          </b-badge>
          <span v-if="selectedShow.predecessor === null"><small><i>This show has no predecessor show.</i></small></span>
          <span v-else>{{ predecessorName }}</span>
          <img
90
            src="../../assets/16x16/emblem-system.png"
91
92
93
94
95
96
97
98
99
100
101
102
103
104
            alt="edit"
            @click="openModalPredecessor()"
          >
        </p>
      </b-col>

      <b-col lg="6">
        <p>
          <b-badge variant="light">
            CBA Series ID:
          </b-badge>
          <span v-if="selectedShow.cba_series_id === null"><small><i>(none set)</i></small></span>
          <span v-else>{{ selectedShow.cba_series_id }}</span>
          <img
105
            src="../../assets/16x16/emblem-system.png"
106
107
108
109
110
111
112
113
114
            alt="edit CBA series ID"
            @click="openModalCBAid()"
          >
        </p>
      </b-col>

      <b-col lg="6">
        <p>
          <b-badge variant="light">
115
            Fallback Playlist ID:
116
          </b-badge>
117
118
          <span v-if="!selectedShow.fallback_id"><small><i>(none set)</i></small></span>
          <span v-else>{{ fallbackInfo }}</span>
119
          <img
120
            src="../../assets/16x16/emblem-system.png"
121
            alt="edit"
122
            @click="openModalFallback()"
123
124
125
126
127
128
129
130
131
          >
        </p>
      </b-col>
    </b-row>

    <b-modal
      ref="modalEmail"
      title="E-Mail"
      size="lg"
132
      @ok="(modalEvt) => { modalEvt.preventDefault(); saveEmail() }"
133
    >
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
      <form
        ref="emailForm"
        @submit.stop.prevent="saveEmail"
      >
        <b-form-group
          :state="emailState"
          label="Name"
          label-for="show-email"
          invalid-feedback="Please enter a valid email address"
        >
          <b-form-input
            id="show-email"
            v-model="email"
            type="email"
            :state="emailState"
            placeholder="Put a contact address of your show here"
          />
        </b-form-group>
      </form>
153
154
155
156
157
158
    </b-modal>

    <b-modal
      ref="modalWebsite"
      title="Website"
      size="lg"
159
      @ok="(modalEvt) => { modalEvt.preventDefault(); saveWebsite() }"
160
    >
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
      <form
        ref="urlForm"
        @submit.stop.prevent="saveWebsite"
      >
        <b-form-group
          :state="urlState"
          label="Name"
          label-for="show-url"
          invalid-feedback="Please enter a valid URL"
        >
          <b-form-input
            id="show-url"
            v-model="url"
            type="url"
            :state="urlState"
            placeholder="Put the website of your show here"
          />
        </b-form-group>
      </form>
180
181
182
183
184
185
186
187
188
189
    </b-modal>

    <b-modal
      ref="modalCBAid"
      title="CBA Series ID"
      size="lg"
      @ok="saveCBAid"
    >
      <b-form-input
        v-model="id"
190
        :state="validId"
191
192
193
194
        placeholder="Put the CBA Series ID of your show here"
      />
    </b-modal>

195
    <app-modalFallback ref="modalFallback" />
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    <b-modal
      ref="modalPredecessor"
      title="Predecessor of this show"
      size="lg"
      @ok="savePredecessor"
    >
      <b-form-select
        v-model="id"
        :options="predecessorSelector"
      />
    </b-modal>

    <b-modal
      ref="modalType"
      title="Show type"
      size="lg"
      @ok="saveShowType"
    >
      <b-row>
        <b-col align="center">
          <div v-if="!loaded">
            <img
219
              src="../../assets/radio.gif"
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
              alt="loading data"
            >
          </div>
          <div v-else>
            <b-form-select
              v-model="id"
              :options="typeSelector"
            />
          </div>
        </b-col>
      </b-row>
    </b-modal>

    <b-modal
      ref="modalFundingCategory"
      title="Funding category of this show"
      size="lg"
      @ok="saveFundingCategory"
    >
      <b-row>
        <b-col align="center">
          <div v-if="!loaded">
            <img
243
              src="../../assets/radio.gif"
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
              alt="loading data"
            >
          </div>
          <div v-else>
            <b-form-select
              v-model="id"
              :options="fundingCategorySelector"
            />
          </div>
        </b-col>
      </b-row>
    </b-modal>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
261
import modalFallback from './FallbackSelector.vue'
262
263

export default {
264
265
266
267
  components: {
    'app-modalFallback': modalFallback,
  },

268
269
  data () {
    return {
270
271
272
273
      email: '',
      url: '',
      emailState: null,
      urlState: null,
274
275
276
      id: 0,
    }
  },
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  computed: {
    shows () { return this.$store.state.shows.shows },
    isSuperuser () { return this.$store.state.auth.user.steeringUser.is_superuser },
    loaded () {
      return {
        shows: this.$store.state.shows.loaded.shows,
        types: this.$store.state.shows.loaded.types,
        fundingcategories: this.$store.state.shows.loaded.fundingcategories,
      }
    },

    typeSelector: function () {
      let options = []
      for (let i in this.types) {
        options.push({value: this.types[i].id, text: this.types[i].type})
      }
      return options
    },

    fundingCategorySelector: function () {
      let options = []
      for (let i in this.fundingcategories) {
        options.push({value: this.fundingcategories[i].id, text: this.fundingcategories[i].abbrev + ' (' + this.fundingcategories[i].fundingcategory + ')', disabled: !this.fundingcategories[i].is_active})
      }
      return options
    },

    // In order to not only just show the predecessor of a show as an ID. we
    // have to find it in our shows array to then output the predecessors name.
    // This currently assumes that a user has access to all the predecessors
    // of the shows as well.
    // TODO/discuss: if all predecessor names should be accessible, independent
    // of access rights, then we would need to load all predecessors show after
    // loading our initial shows as well.
    predecessorName: function () {
      for (let i in this.shows) {
        if (this.shows[i].id === this.selectedShow.predecessor) {
          return this.shows[i].name
        }
      }
      return 'Name of predecessor show not available'
    },

    predecessorSelector: function () {
      let options = []
      options.push({value: null, text: '<i>... this show has no predecessor ...</i>'})
      for (let i in this.shows) {
        options.push({value: this.shows[i].id, text: this.shows[i].name})
      }
      return options
    },

    type: function () {
      let type = this.types.find(t => t.id === this.selectedShow.type)
      if (type) { return type.type }
      return null
    },
    fundingCategory: function () {
      let fc = this.fundingcategories.find(f => f.id === this.selectedShow.fundingcategory)
      if (fc) { return fc.fundingcategory }
      return null
    },

341
342
343
344
    validId () {
      return this.id === null || RegExp('^[0-9]*$').test(this.id)
    },

345
346
347
348
349
350
351
352
    fallbackInfo () {
      const list = this.playlists.find(p => p.id === this.selectedShow.fallback_id)
      if (! list) { return this.selectedShow.fallback_id }
      else {
        return list.description + ' (ID: ' + list.id + ')'
      }
    },

353
354
355
356
    ...mapGetters({
      selectedShow: 'shows/selectedShow',
      types: 'shows/types',
      fundingcategories: 'shows/fundingcategories',
357
      playlists: 'playlists/playlists',
358
359
360
361
    })
  },
  methods: {
    openModalEmail () {
362
363
      this.emailState = null;

364
365
      if (this.selectedShow.email !== null) { this.email = this.selectedShow.email }
      else { this.email = '' }
366
367
368
369
      this.$refs.modalEmail.show()
    },

    openModalWebsite() {
370
371
      this.urlState = null;

372
373
      if (this.selectedShow.website !== null) { this.url = this.selectedShow.website }
      else { this.url = '' }
374
375
376
377
378
379
380
381
      this.$refs.modalWebsite.show()
    },

    openModalCBAid() {
      this.id = this.selectedShow.cba_series_id
      this.$refs.modalCBAid.show()
    },

382
    openModalFallback() {
383
      this.$refs.modalFallback.open(this.saveFallback)
384
385
    },

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
    openModalPredecessor() {
      this.id = this.selectedShow.predecessor
      this.$refs.modalPredecessor.show()
    },

    openModalFundingCategory() {
      this.id = this.selectedShow.fundingcategory
      this.$refs.modalFundingCategory.show()
    },

    openModalType() {
      this.id = this.selectedShow.type
      this.$refs.modalType.show()
    },

401
    saveProperty (property, value, modal) {
402
      if (value !== this.selectedShow[property]) {
403
404
405
406
407
408
        this.$store.dispatch('shows/updateProperty', {
          id: this.selectedShow.id,
          property: property,
          value: value,
          callback: () => {
            modal.hide()
409
410
411
412
413
414
415
416
417
          },
          callbackCancel: (error) => {
            if (error.data.email) {
              this.emailState = false;
            }

            if (error.data.website) {
              this.urlState = false;
            }
418
419
420
421
422
          }
        })
      }
    },

423
424
425
426
427
428
429
430
431
    saveEmail () {
      const valid = this.$refs.emailForm.checkValidity();
      this.emailState = valid;

      if (!valid) {
        return;
      }

      this.saveProperty('email', this.email, this.$refs.modalEmail)
432
433
    },

434
435
436
437
438
439
440
441
442
    saveWebsite () {
      const valid = this.$refs.urlForm.checkValidity();
      this.urlState = valid;

      if (!valid) {
        return;
      }

      this.saveProperty('website', this.url, this.$refs.modalWebsite)
443
444
445
    },

    saveCBAid (event) {
446
447
448
449
450
451
452
453
454
      if (this.validId) {
        let id = this.id === '' ? null : this.id
        this.saveProperty('cba_series_id', id, this.$refs.modalCBAid, event)
      } else {
        event.preventDefault()
        alert ('Please provide a valid integer value as ID')
      }
    },

455
    saveFallback (id) {
456
      this.saveProperty('fallback_id', id, this.$refs.modalFallback)
457
      this.$log.debug(this.playlists)
458
459
460
    },

    savePredecessor (event) {
461
462
      let id = this.id === '' ? null : this.id
      this.saveProperty('predecessor', id, this.$refs.modalPredecessor, event)
463
464
465
    },

    saveFundingCategory (event) {
466
      this.saveProperty('fundingcategory', this.id, this.$refs.modalFundingCategory, event)
467
468
469
    },

    saveShowType (event) {
470
      this.saveProperty('type', this.id, this.$refs.modalType, event)
471
472
473
474
475
476
477
478
479
480
    },

    // Just a placeholder function we can use in the UI, to signal if something
    // is not yet implemented
    notYetImplemented: function () {
      alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
    }
  }
}
</script>