Newer
Older
Sébastien DA ROCHA
committed
<template>
<div class="ui teal segment">
<h4>
Liaison
<button
class="ui small compact right floated icon button remove-formset"
type="button"
Sébastien DA ROCHA
committed
>
Sébastien DA ROCHA
committed
</button>
</h4>
<ul
id="errorlist-links"
class="errorlist"
>
<li
v-for="error in form.errors"
:key="error"
Sébastien DA ROCHA
committed
<div class="visible-fields">
<div class="two fields">
<div class="required field">
<label :for="form.relation_type.id_for_label">{{
Sébastien DA ROCHA
committed
form.relation_type.label
}}</label>
<Dropdown
Sébastien DA ROCHA
committed
:selected="selected_relation_type"
:selection.sync="selected_relation_type"
/>
{{ form.relation_type.errors }}
</div>
<div class="required field">
<label :for="form.feature_to.id_for_label">{{
Sébastien DA ROCHA
committed
form.feature_to.label
}}</label>
:current-selection="linkedForm"
Sébastien DA ROCHA
committed
/>
{{ form.feature_to.errors }}
</div>
</div>
</div>
</div>
</template>
<script>
import Dropdown from '@/components/Dropdown.vue';
import SearchFeature from '@/components/SearchFeature.vue';
Sébastien DA ROCHA
committed
export default {
Sébastien DA ROCHA
committed
components: {
Dropdown,
Sébastien DA ROCHA
committed
},
props: {
linkedForm: {
type: Object,
default: null,
}
},

Timothee P
committed
data() {
return {
form: {
errors: null,
relation_type: {
errors: null,
id_for_label: 'relation_type',
html_name: 'relation_type',
label: 'Type de liaison',

Timothee P
committed
},
feature_to: {
errors: null,

Timothee P
committed
field: {
max_length: 30,
},
html_name: 'feature_to',
label: 'Signalement lié',

Timothee P
committed
value: '',

Timothee P
committed
},
},
{ name: 'Doublon', value: 'doublon' },
{ name: 'Remplace', value: 'remplace' },
{ name: 'Est remplacé par', value: 'est_remplace_par' },
{ name: 'Dépend de', value: 'depend_de' },

Timothee P
committed
};
},
Sébastien DA ROCHA
committed
computed: {
selected_relation_type: {
// getter
get() {
return this.form.relation_type.value.name;
Sébastien DA ROCHA
committed
},
// setter
set(newValue) {
this.form.relation_type.value = newValue;
this.updateStore();
},
Sébastien DA ROCHA
committed
},
mounted() {
if (this.linkedForm.relation_type) {

Timothee P
committed
this.form.relation_type.value.name = this.linkedForm.relation_type_display;
this.form.relation_type.value.value = this.linkedForm.relation_type;
}
if (this.linkedForm.feature_to) {
this.form.feature_to.value = this.linkedForm.feature_to.feature_id;
Sébastien DA ROCHA
committed
methods: {
remove_linked_formset() {
this.$store.commit('feature/REMOVE_LINKED_FORM', this.linkedForm.dataKey);
Sébastien DA ROCHA
committed
},

Timothee P
committed
selectFeatureTo(featureId) {
if (featureId) {
this.form.feature_to.value = featureId;
this.updateStore();
}
Sébastien DA ROCHA
committed
updateStore() {
this.$store.commit('feature/UPDATE_LINKED_FORM', {
Sébastien DA ROCHA
committed
dataKey: this.linkedForm.dataKey,
relation_type: this.form.relation_type.value.value,
feature_to: {
feature_id: this.form.feature_to.value,
Sébastien DA ROCHA
committed
});
},

Timothee P
committed
checkForm() {
this.form.errors = [

Timothee P
committed
'Veuillez choisir un signalement pour la nouvelle liaison.',
];
document
.getElementById('errorlist-links')
.scrollIntoView({ block: 'start', inline: 'nearest' });
return false;
}
this.form.errors = [];
return true;
},
Sébastien DA ROCHA
committed
};