This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/SourceSubmitForm.vue

177 lines
7.4 KiB
Vue
Raw Normal View History

2020-10-31 06:54:56 -07:00
<template>
<div class="card">
<div class="card-header">
<Icon v="plus-circle"/>
<T>sources.submit.header</T>
</div>
<div class="card-body">
<div v-if="afterSubmit" class="alert alert-success text-center">
<p>
<T>sources.submit.thanks</T>
</p>
<p>
<button class="btn btn-success" @click="afterSubmit = false">
<Icon v="plus"/>
<T>sources.submit.another</T>
</button>
</p>
</div>
<form v-else @submit.prevent="submit">
<div class="form-group">
<label for="type" class="required"><T>sources.submit.type</T></label>
<select id="type" class="form-control" v-model="form.type" required>
<option value=""></option>
<option v-for="t in ['Book', 'Article', 'Movie', 'Series', 'Song', 'Poetry', 'Other']" :value="t">
<T>sources.type.{{t}}</T>
</option>
</select>
</div>
<div class="form-group">
<label for="author"><T>sources.submit.author</T></label>
<input type="text" id="author" class="form-control" v-model="form.author"
maxlength="255"/>
</div>
<div class="form-group">
<label for="title" class="required"><T>sources.submit.title</T></label>
<input type="text" id="title" class="form-control" v-model="form.title"
required maxlength="255"/>
</div>
<div class="form-group">
<label for="extra"><T>sources.submit.extra</T></label>
2020-10-31 06:54:56 -07:00
<input type="text" id="extra" class="form-control" v-model="form.extra"
maxlength="255"/>
</div>
<div class="form-group">
<label for="year"><T>sources.submit.year</T></label>
<input type="number" id="year" class="form-control" v-model="form.year"
min="0" max="2100"/>
</div>
<div class="form-group">
<label for="fragments"><T>sources.submit.fragments</T></label>
<p class="small text-muted mb-0"><T>sources.submit.fragmentsInfo</T></p>
2020-10-31 06:54:56 -07:00
<ListInput v-model="form.fragments" v-slot="s" id="fragments">
<textarea v-model="s.val" class="form-control" rows="3" @keyup="s.update(s.val)" required></textarea>
</ListInput>
</div>
<div class="form-group">
<label for="pronouns" class="required"><T>sources.submit.pronouns</T></label>
2020-12-04 13:09:57 -08:00
<p class="small text-muted mb-0">
<T>sources.submit.pronounsInfo</T>
</p>
<ListInput v-model="form.pronouns" v-slot="s">
<input v-model="s.val" type="text" class="form-control" @keyup="s.update(s.val)" required maxlength="24"/>
<small v-if="s.val && !pronounLibrary.isCanonical(s.val) && !(config.sources.extraTypes || []).includes(s.val)"
class="input-group-text bg-danger text-white">
2021-01-22 14:54:24 -08:00
<Icon v="exclamation-triangle"/>
<span class="ml-1"><T>profile.pronounsNotFound</T></span>
</small>
2020-12-04 13:09:57 -08:00
</ListInput>
2020-10-31 06:54:56 -07:00
</div>
<div class="form-group">
<label for="comment"><T>sources.submit.comment</T></label>
<input type="text" id="comment" class="form-control" v-model="form.comment"
maxlength="255"/>
</div>
<div class="form-group">
<label for="link"><T>sources.submit.link</T></label>
<input type="url" id="link" class="form-control" v-model="form.link"
maxlength="255"/>
</div>
<div class="form-group">
<label><T>sources.submit.images</T></label>
<ImageWidget v-model="form.images" multiple/>
</div>
2021-01-04 13:46:57 -08:00
<div class="form-group" v-if="$isGranted('sources')">
<label for="key"><T>sources.submit.key</T></label>
<input type="text" id="key" class="form-control" v-model="form.key"
maxlength="255"/>
<p class="small text-muted"><T>sources.submit.keyInfo</T></p>
</div>
2020-12-05 11:37:10 -08:00
<div class="alert alert-info" v-if="form.base">
<Icon v="info-circle"/>
<T>nouns.editing</T>
2021-01-22 14:54:24 -08:00
<button class="btn btn-sm float-end" @click="form.base = null">
2020-12-05 11:37:10 -08:00
<Icon v="times"/>
</button>
</div>
2021-01-22 14:54:24 -08:00
<button class="btn btn-success w-100" :disabled="submitting">
2020-10-31 06:54:56 -07:00
<Icon v="plus-circle"/>
<T>sources.submit.action</T>
</button>
<p class="small text-muted mt-1"><T>sources.submit.moderation</T></p>
</form>
</div>
</div>
</template>
<script>
import {pronounLibrary} from "../src/data";
2020-10-31 06:54:56 -07:00
export default {
data() {
return {
form: {
2020-12-04 13:09:57 -08:00
pronouns: [''],
2020-10-31 06:54:56 -07:00
type: '',
author: '',
title: '',
extra: '',
year: '',
fragments: [],
comment: '',
images: [],
2020-10-31 06:54:56 -07:00
link: '',
2021-01-04 13:46:57 -08:00
key: null,
2020-12-05 11:37:10 -08:00
base: null,
2020-10-31 06:54:56 -07:00
},
submitting: false,
afterSubmit: false,
pronounLibrary,
2020-10-31 06:54:56 -07:00
}
},
methods: {
async submit() {
this.submitting = true;
await this.$axios.$post(`/sources/submit`, this.form);
2020-10-31 06:54:56 -07:00
this.submitting = false;
this.afterSubmit = true;
this.form = {
2020-12-04 13:09:57 -08:00
pronouns: [''],
2020-10-31 06:54:56 -07:00
type: '',
author: '',
title: '',
extra: '',
year: '',
fragments: [],
comment: '',
images: [],
2020-10-31 06:54:56 -07:00
link: '',
2021-01-04 13:46:57 -08:00
key: null,
2020-12-05 11:37:10 -08:00
base: null,
}
},
edit(source) {
this.form = {
pronouns: source.pronouns,
type: source.type,
author: source.author,
title: source.title,
extra: source.extra,
year: source.year,
fragments: source.fragments,
comment: source.comment,
images: source.images,
2020-12-05 11:37:10 -08:00
link: source.link,
2021-01-04 13:46:57 -08:00
key: source.key,
2020-12-05 11:37:10 -08:00
base: source.id,
2020-10-31 06:54:56 -07:00
}
2020-12-05 11:37:10 -08:00
this.afterSubmit = false;
this.$el.scrollIntoView();
2020-10-31 06:54:56 -07:00
},
},
}
</script>