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

176 lines
6.9 KiB
Vue
Raw Normal View History

2020-08-04 07:15:41 -07:00
<template>
<section>
<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>
2020-10-15 11:55:24 -07:00
<th v-if="$admin()"></th>
2020-08-04 07:15:41 -07:00
</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"/>
</td>
<td>
<NounForm v-model="form.fem"/>
</td>
<td>
<NounForm v-model="form.neutr"/>
</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"/>
</td>
<td>
<NounForm v-model="form.femPl"/>
</td>
<td>
<NounForm v-model="form.neutrPl"/>
</td>
</tr>
</tbody>
</table>
</div>
<div class="alert alert-info" v-if="form.base">
<Icon v="info-circle"/>
<T>nouns.editing</T>
2020-08-04 07:15:41 -07:00
<button class="btn btn-sm float-right" @click="form.base = null">
<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 btn-block">
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">
<T>nouns.root</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
<button class="btn btn-primary btn-block" :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>
</template>
<script>
2020-08-05 11:24:05 -07:00
import { nounTemplates } from '../src/data';
2020-10-31 05:10:25 -07:00
import config from "../data/config.suml";
2020-08-04 07:15:41 -07:00
export default {
data() {
return {
form: {
masc: [''],
fem: [''],
neutr: [''],
mascPl: [''],
femPl: [''],
neutrPl: [''],
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;
2020-11-02 10:31:05 -08:00
await this.$axios.$post(`/nouns/submit/${this.config.locale}`, this.form);
2020-08-04 07:15:41 -07:00
this.submitting = false;
this.afterSubmit = true;
this.form = {
masc: [''],
fem: [''],
neutr: [''],
mascPl: [''],
femPl: [''],
neutrPl: [''],
base: null,
};
this.templateVisible = false;
this.templateBase = '';
},
edit(word) {
this.form = {
masc: word.masc,
fem: word.fem,
neutr: word.neutr,
mascPl: word.mascPl,
femPl: word.femPl,
neutrPl: word.neutrPl,
base: word.id,
}
this.$el.scrollIntoView();
}
},
};
</script>