IDCCSearch.vue 1.6 KB
Newer Older
1 2 3 4
<template>
  <div id="IDCCSearch">
    <div class="container">
      <div class="row">
5 6 7 8
        <div class="col-md-12">
					<h2>IDCC</h2>
          <input type="text" ref="idcc" placeholder="Chercher une convention collective" v-model="idcc" 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
          <div v-if="this.idcc && Object.keys(this.results).length">
            <ul class="dash">
16 17 18 19 20
              <li v-for="(result,code) in this.results" :key="code">
                {{ result['convention collective'] }}
                <strong>({{ code }})</strong>
              </li>
            </ul>
21 22 23
          </div>
          <div v-if="this.idcc && this.resultsIsEmpty">
              <p>Aucune convention collective trouvée avec l'identifiant «{{ this.idcc }}».</p>
24 25 26 27 28 29 30 31 32 33 34 35
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
		name: 'IDCCSearch',
		data: function () {
			return {
        idcc: "",
36 37
        results: {},
        resultsIsEmpty: false
38
			}
39
    },
40 41
		methods: {
			search: function () {
42 43 44 45 46 47 48
        this.$http
          .get('/idcc?q='+this.idcc)
          .then(response => {
            this.results = response.body;
            this.resultsIsEmpty = this.isEmpty(this.results);
          })
          .created;
49 50 51
      },
      isEmpty: function (obj) {
        for(var key in obj) {
52
          if(obj.hasOwnProperty(key)) return false;
53 54 55
        }
        return true;
      }
56
		}
57 58
  }
</script>