CatalogueSearch.vue 1.57 KB
Newer Older
1
<template>
2
  <div id="CatalogueSearch">
3
    <div class="container mb-0 mt-0">
4
      <div class="row">
5
        <div class="col-md-12">
6
          <h2>Catalogue</h2>
7 8
          <input type="text" ref="intercarif" placeholder="Identifiant INTERCARIF" v-model="intercarif" class="form-control"><br>
          <input @click="search()" type="button" class="btn main-button pull-right" value="Chercher">
9
        </div>
10 11 12 13
      </div>
      <br>
      <div class="row">
        <div class="col-md-12 results">
14 15 16 17 18
          <div v-if="this.intercarif && Object.keys(this.results).length">
            <pre>{{ this.results }}</pre>
          </div>
          <div v-if="this.intercarif && this.resultsIsEmpty">
            <p>
19 20 21 22 23 24 25 26 27 28
              Aucune formation trouvée avec l'identifiant «{{ this.intercarif }}».
            </p>
          </div>
        </div>
      </div>
    </div>
</div>
</template>
<script>
  export default {
29
    name: 'CatalogueSearch',
30 31 32
    data: function () {
			return {
        intercarif: "",
33 34
        results: {},
        resultsIsEmpty: false
35 36 37 38
			}
		},
		methods: {
			search: function () {
39 40 41 42 43 44 45 46 47
        this.$http
          .get('/explore/catalog?id='+this.intercarif)
          .then(response => {
            this.results = response.body;
            this.resultsIsEmpty = this.isEmpty(this.results);
          }, () => {
            this.resultsIsEmpty = this.isEmpty(this.results);
          })
          .created;
48 49 50
			},
      isEmpty: function (obj) {
        for(var key in obj) {
51
          if(obj.hasOwnProperty(key)) return false;
52 53 54
        }
        return true;
      }
55
		}
56 57
  }
</script>