Koha/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue
Jonathan Druart cd2884d907
Bug 32030: Improve form UI
* Align inputs, textareas and selects
* Use vue-select for dropdown lists

Note that the only way I found to make the select required is to follow
what is on their doc https://vue-select.org/guide/validation.html#required

However we need our own vue-select-required component to avoid the
repetition (the #search slot). I've tried (but failed) on
https://gitlab.com/joubu/Koha/-/commits/erm-v-select-required

Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-11-08 09:44:19 -03:00

119 lines
4.2 KiB
Vue

<template>
<fieldset class="rows" id="agreement_relationships">
<legend>{{ $t("Related agreements") }}</legend>
<fieldset
class="rows"
v-for="(relationship, counter) in relationships"
v-bind:key="counter"
>
<legend>
{{ $t("Related agreement .counter", { counter: counter + 1 }) }}
<a href="#" @click.prevent="deleteRelationship(counter)"
><i class="fa fa-trash"></i>
{{ $t("Remove this relationship") }}</a
>
</legend>
<ol>
<li>
<label :for="`related_agreement_id_${counter}`"
>{{ $t("Related agreement") }}:
</label>
<v-select
:id="`related_agreement_id_${counter}`"
v-model="relationship.related_agreement_id"
label="name"
:reduce="(a) => a.agreement_id"
:options="agreements"
>
<template #search="{ attributes, events }">
<input
:required="!relationship.related_agreement_id"
class="vs__search"
v-bind="attributes"
v-on="events"
/>
</template>
</v-select>
<span class="required">{{ $t("Required") }}</span>
</li>
<li>
<label :for="`related_agreement_relationship_${counter}`"
>{{ $t("Relationship") }}:
</label>
<v-select
:id="`related_agreement_relationship_${counter}`"
v-model="relationship.relationship"
label="lib"
:reduce="(av) => av.authorised_value"
:options="av_agreement_relationships"
>
<template #search="{ attributes, events }">
<input
:required="!relationship.relationship"
class="vs__search"
v-bind="attributes"
v-on="events"
/>
</template>
</v-select>
<span class="required">{{ $t("Required") }}</span>
</li>
<li>
<label :for="`related_agreement_notes_${counter}`"
>{{ $t("Notes") }}:</label
>
<input
:id="`related_agreement_notes_${counter}`"
v-model="relationship.notes"
:placeholder="$t('Notes')"
/>
</li>
</ol>
</fieldset>
<a
v-if="agreements.length"
class="btn btn-default"
@click="addRelationship"
><font-awesome-icon icon="plus" />
{{ $t("Add new related agreement") }}</a
>
<span v-else>{{
$t("There are no other agreements created yet")
}}</span>
</fieldset>
</template>
<script>
import { fetchAgreements } from "../../fetch"
export default {
data() {
return {
agreements: [],
}
},
beforeCreate() {
fetchAgreements().then((agreements) => {
this.agreements = agreements.filter((agreement) => agreement.agreement_id !== this.agreement_id)
})
},
methods: {
addRelationship() {
this.relationships.push({
related_agreement_id: null,
relationship: null,
notes: '',
})
},
deleteRelationship(counter) {
this.relationships.splice(counter, 1)
},
},
props: {
agreement_id: Number,
av_agreement_relationships: Array,
relationships: Array,
},
name: 'AgreementRelationships',
}
</script>