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/NounSubmitForm.vue

190 lines
7.8 KiB
Vue
Raw Normal View History

2020-08-04 07:15:41 -07:00
<template>
<section v-if="$user()">
2020-08-04 07:15:41 -07:00
<div v-if="afterSubmit" class="alert alert-success text-center">
<p>
<T>nouns.submit.thanks</T>
2020-08-04 07:15:41 -07:00
</p>
<p>
<button class="btn btn-success" @click="afterSubmit = false">
<Icon v="plus"/>
<T>nouns.submit.another</T>
2020-08-04 07:15:41 -07:00
</button>
</p>
</div>
<form v-else @submit.prevent="submit">
<div class="table-responsive">
2020-10-31 05:10:25 -07:00
<table :class="'table table-borderless table-sm table-fixed-' + (config.nouns.plurals ? '4' : '3')">
2020-08-04 07:15:41 -07:00
<thead>
<tr>
2020-10-31 05:10:25 -07:00
<th v-if="config.nouns.plurals"></th>
2020-08-04 07:15:41 -07:00
<th class="text-nowrap">
<Icon v="mars"/>
<span class="d-none d-md-inline"><T>nouns.masculine</T></span>
<span class="d-md-none"><T>nouns.masculineShort</T></span>
2020-08-04 07:15:41 -07:00
</th>
<th class="text-nowrap">
<Icon v="venus"/>
<span class="d-none d-md-inline"><T>nouns.feminine</T></span>
<span class="d-md-none"><T>nouns.feminineShort</T></span>
2020-08-04 07:15:41 -07:00
</th>
<th class="text-nowrap">
<Icon v="neuter"/>
<span class="d-none d-md-inline"><T>nouns.neuter</T></span>
<span class="d-md-none"><T>nouns.neuterShort</T></span>
2020-08-04 07:15:41 -07:00
</th>
</tr>
</thead>
<tbody>
<tr>
2020-10-31 05:10:25 -07:00
<th v-if="config.nouns.plurals" class="text-nowrap">
<span class="d-none d-md-inline"> <T>nouns.singular</T></span>
<span class="d-md-none"> <T>nouns.singularShort</T></span>
2020-08-04 07:15:41 -07:00
</th>
<td>
<NounForm v-model="form.masc" required/>
2020-08-04 07:15:41 -07:00
</td>
<td>
<NounForm v-model="form.fem" required/>
2020-08-04 07:15:41 -07:00
</td>
<td>
<NounForm v-model="form.neutr" required/>
2020-08-04 07:15:41 -07:00
</td>
</tr>
2020-10-31 05:10:25 -07:00
<tr v-if="config.nouns.plurals">
2020-08-04 07:15:41 -07:00
<th class="text-nowrap">
<span class="d-none d-md-inline"> <T>nouns.plural</T></span>
<span class="d-md-none"> <T>nouns.pluralShort</T></span>
2020-08-04 07:15:41 -07:00
</th>
<td>
<NounForm v-model="form.mascPl" :required="config.nouns.pluralsRequired"/>
2020-08-04 07:15:41 -07:00
</td>
<td>
<NounForm v-model="form.femPl" :required="config.nouns.pluralsRequired"/>
2020-08-04 07:15:41 -07:00
</td>
<td>
<NounForm v-model="form.neutrPl" :required="config.nouns.pluralsRequired"/>
2020-08-04 07:15:41 -07:00
</td>
</tr>
</tbody>
</table>
</div>
<div v-if="$isGranted('sources')" class="form-group">
2021-12-02 08:18:25 -08:00
<label><strong><T>sources.referenced</T><T>quotation.colon</T></strong></label>
<ListInput v-model="form.sources"/>
</div>
2020-08-04 07:15:41 -07: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-08-04 07:15:41 -07:00
<Icon v="times"/>
</button>
</div>
2020-10-31 05:10:25 -07:00
<template v-if="config.nouns.templates">
<a v-if="!templateVisible" href="#" @click.prevent="templateVisible = true" class="btn btn-outline-primary w-100 mb-3">
2020-08-04 07:15:41 -07:00
<Icon v="copy"/>
<T>nouns.template</T>
2020-08-04 07:15:41 -07:00
</a>
2020-10-31 05:10:25 -07:00
<div v-else class="card mb-3">
<a href="#" class="card-header" @click.prevent="templateVisible = false">
<Icon v="copy"/>
<T>nouns.template</T>
</a>
<div class="card-body">
2021-12-02 08:18:25 -08:00
<T>nouns.root</T><T>quotation.colon</T> <input class="form-control form-control-sm d-inline-block w-auto" v-model="templateBase" autofocus/>
2020-08-04 07:15:41 -07:00
2020-10-31 05:10:25 -07:00
<ul>
<li v-for="template in templates" class="my-2">
{{ template.toString() }}
<button type="button" class="btn btn-outline-primary btn-sm" @click="form = template.fill(templateBase)">
<Icon v="copy"/>
</button>
</li>
</ul>
</div>
2020-08-04 07:15:41 -07:00
</div>
2020-10-31 05:10:25 -07:00
</template>
2020-08-04 07:15:41 -07:00
2021-01-22 14:54:24 -08:00
<button class="btn btn-primary w-100" :disabled="submitting">
2020-08-04 07:15:41 -07:00
<template v-if="submitting">
<Icon v="circle-notch fa-spin"/>
</template>
<template v-else>
<Icon v="plus"/>
<T>nouns.submit.actionLong</T>
2020-08-04 07:15:41 -07:00
</template>
</button>
<p class="small text-muted mt-1"><T>nouns.submit.moderation</T></p>
2020-08-04 07:15:41 -07:00
</form>
</section>
<section v-else class="text-center">
<div class="alert alert-info">
<T>crud.loginRequired</T>
</div>
</section>
2020-08-04 07:15:41 -07:00
</template>
<script>
2020-08-05 11:24:05 -07:00
import { nounTemplates } from '../src/data';
2020-08-04 07:15:41 -07:00
export default {
data() {
return {
form: {
masc: [''],
fem: [''],
neutr: [''],
mascPl: this.config.nouns.pluralsRequired ? [''] : [],
femPl: this.config.nouns.pluralsRequired ? [''] : [],
neutrPl: this.config.nouns.pluralsRequired ? [''] : [],
sources: [],
2020-08-04 07:15:41 -07:00
base: null,
},
submitting: false,
afterSubmit: false,
2020-08-05 11:24:05 -07:00
templates: nounTemplates,
2020-08-04 07:15:41 -07:00
templateBase: '',
templateVisible: false,
}
},
methods: {
async submit(event) {
this.submitting = true;
try {
await this.$post(`/nouns/submit`, this.form);
2020-08-04 07:15:41 -07:00
this.afterSubmit = true;
this.form = {
masc: [''],
fem: [''],
neutr: [''],
mascPl: this.config.nouns.pluralsRequired ? [''] : [],
femPl: this.config.nouns.pluralsRequired ? [''] : [],
neutrPl: this.config.nouns.pluralsRequired ? [''] : [],
sources: [],
base: null,
};
this.templateVisible = false;
this.templateBase = '';
} finally {
this.submitting = false;
}
2020-08-04 07:15:41 -07:00
},
edit(word) {
this.form = {
masc: word.masc,
fem: word.fem,
neutr: word.neutr,
mascPl: word.mascPl,
femPl: word.femPl,
neutrPl: word.neutrPl,
sources: word.sources,
2020-08-04 07:15:41 -07:00
base: word.id,
}
this.afterSubmit = false;
2020-08-04 07:15:41 -07:00
this.$el.scrollIntoView();
}
},
};
</script>