Skip to content
Snippets Groups Projects
FeatureLinkedForm.vue 4.01 KiB
Newer Older
<template>
  <div class="ui teal segment">
    <h4>
      Liaison
      <button
        class="ui small compact right floated icon button remove-formset"
        type="button"
        @click="remove_linked_formset"
Florent Lavelle's avatar
Florent Lavelle committed
        <i
          class="ui times icon"
          aria-hidden="true"
        />
    <ul
      id="errorlist-links"
      class="errorlist"
    >
      <li
        v-for="error in form.errors"
        :key="error"
Timothee P's avatar
Timothee P committed
      >
        {{ error }}
      </li>
    <div class="visible-fields">
      <div class="two fields">
        <div class="required field">
          <label :for="form.relation_type.id_for_label">{{
            :options="relationTypeChoices"
            :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">{{
Florent's avatar
Florent committed
          <SearchFeature
            :current-selection="linkedForm"
Florent's avatar
Florent committed
            @select="selectFeatureTo"
            @close="selectFeatureTo"
          />
          {{ form.feature_to.errors }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Dropdown from '@/components/Dropdown.vue';
Florent's avatar
Florent committed
import SearchFeature from '@/components/SearchFeature.vue';
  name: 'FeatureLinkedForm',
Florent's avatar
Florent committed
    SearchFeature
Timothee P's avatar
Timothee P committed
  props: {
    linkedForm: {
      type: Object,
      default: null,
    }
  },
  data() {
    return {
      form: {
        errors: null,
        relation_type: {
          errors: null,
          id_for_label: 'relation_type',
          html_name: 'relation_type',
          label: 'Type de liaison',
            name: 'Doublon',
            value: 'doublon',
          id_for_label: 'feature_to',
          html_name: 'feature_to',
          label: 'Signalement lié',
      relationTypeChoices: [
        { name: 'Doublon', value: 'doublon' },
        { name: 'Remplace', value: 'remplace' },
        { name: 'Est remplacé par', value: 'est_remplace_par' },
        { name: 'Dépend de', value: 'depend_de' },
        return this.form.relation_type.value.name;
      },
      // setter
      set(newValue) {
        this.form.relation_type.value = newValue;
        this.updateStore();
      },
Florent's avatar
Florent committed
    }
  mounted() {
    if (this.linkedForm.relation_type) {
      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;
      this.$store.commit('feature/REMOVE_LINKED_FORM', this.linkedForm.dataKey);
    selectFeatureTo(featureId) {
      if (featureId) {
        this.form.feature_to.value = featureId;
Florent's avatar
Florent committed
    },

      this.$store.commit('feature/UPDATE_LINKED_FORM', {
        relation_type: this.form.relation_type.value.value,
        feature_to: {
          feature_id: this.form.feature_to.value,
      if (this.form.feature_to.value === '') {
          'Veuillez choisir un signalement pour la nouvelle liaison.',
          .getElementById('errorlist-links')
          .scrollIntoView({ block: 'start', inline: 'nearest' });
        return false;
      }
      this.form.errors = [];
      return true;
    },
Florent Lavelle's avatar
Florent Lavelle committed
</script>