Skip to content
Snippets Groups Projects
Project_mapping.vue 3.99 KiB
Newer Older
  <div class="fourteen wide column">
    <div
      id="message_info"
      class="fullwidth"
    >
Timothee P's avatar
Timothee P committed
      <div v-if="infoMessage.length > 0">
        <div
          v-for="(message, index) of infoMessage"
          :key="index"
          :class="['ui message', message.success ? 'positive' : 'negative']"
          style="text-align: left"
        >
          <div class="header">
            <i class="info circle icon" /> Informations
Timothee P's avatar
Timothee P committed
          </div>
          {{ message.comment }}
        </div>
    <h1 class="ui header">
      Administration des fonds cartographiques
    </h1>
    <form
      id="form-layers"
      action="."
      method="post"
      enctype="multipart/form-data"
      class="ui form"
    >
      <!--  {{ formset.management_form }} -->
      <div class="ui buttons">
        <a
          class="ui compact small icon left floated button green"
          data-variation="mini"
          @click="addBasemap"
        >
          <i class="ui plus icon" />
Timothee P's avatar
Timothee P committed
          <span>&nbsp;Créer un fond cartographique</span>
      <div
        v-if="basemaps"
        class="ui"
      >
        <ProjectMappingBasemap
          v-for="basemap in basemaps"
          :key="basemap.id"
          :basemap="basemap"
        />
      </div>
Timothee P's avatar
Timothee P committed
      <div class="margin-top">
        <button
          type="button"
          class="ui teal icon floated button"
          @click="saveChanges"
        >
          <i class="white save icon" /> Enregistrer les changements
        </button>
      </div>
import Project_mapping_basemap from '@/components/project/project_mapping_basemap.vue';
import { mapState, mapGetters } from 'vuex';
  name: 'ProjectMapping',

  components: {
    ProjectMappingBasemap: Project_mapping_basemap,
  },

  data() {
    return {
Timothee P's avatar
Timothee P committed
      infoMessage: [],
    ...mapState('map', ['basemaps']),
    ...mapGetters('map', ['basemapMaxId']),
  },

  created() {
    if (!this.$store.getters.project) {
      this.$store.dispatch('GET_PROJECT_INFO', this.$route.params.slug);
    }
  },

  methods: {
    addBasemap() {
      this.newBasemapIds.push(this.basemapMaxId + 1); //* register new basemaps to seperate post and put
      this.$store.commit('map/CREATE_BASEMAP', this.basemapMaxId + 1);
      let isValid = true;
      this.basemaps.forEach((basemap) => {
        if (basemap.title === null || basemap.title === '') { //* check title when saving basemaps
          basemap.errors = 'Veuillez compléter ce champ.';
        } else if (basemap.layers.length === 0) {
          basemap.errors = 'Veuillez ajouter au moins un layer.';
          isValid = false;
          basemap.errors = '';
        }
      });
      return isValid;
    },
      if (this.checkTitles()) {
        this.$store
          .dispatch('map/SAVE_BASEMAPS', this.newBasemapIds)
          .then((response) => {
            const errors = response.filter(
              (res) =>
                res.status === 200 && res.status === 201 && res.status === 204
            );
            if (errors.length === 0) {
Timothee P's avatar
Timothee P committed
              this.infoMessage.push({
                success: true,
                comment: 'Enregistrement effectué.',
Timothee P's avatar
Timothee P committed
              });
              this.newBasemapIds = [];
Timothee P's avatar
Timothee P committed
            } else {
              this.infoMessage.push({
                success: false,
                comment: "L'édition des fonds cartographiques a échoué. ",
              });
Timothee P's avatar
Timothee P committed

            document
              .getElementById('message_info')
              .scrollIntoView({ block: 'end', inline: 'nearest' });
Timothee P's avatar
Timothee P committed
            setTimeout(
              function () {
                this.infoMessage = [];
              }.bind(this),
              5000
            );
            console.error(error);