148 lines
5.9 KiB
Vue
148 lines
5.9 KiB
Vue
<template>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<div class="row">
|
|
<div class="col-md-3">
|
|
FAQ - Gestion des thèmes
|
|
</div>
|
|
<div class="col-md-6 text-center">
|
|
<transition name="fade">
|
|
<span v-show="processing">
|
|
{{ response }}
|
|
</span>
|
|
</transition>
|
|
</div>
|
|
<div class="col-md-3 text-right">
|
|
<button class="btn btn-primary btn-sm text-white float-right" @click="saveData()" :disabled="processing">
|
|
Sauvegarder
|
|
<div class="spinner-border spinner-border-sm text-light" role="status" v-show="processing">
|
|
<span class="sr-only">Loading...</span>
|
|
</div>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<div class="col-md-10 offset-md-1">
|
|
<table class="table table-bordered text-center">
|
|
<thead>
|
|
<tr>
|
|
<th class="w-75" scope="col">Nom du thème <span class="required-asterisk">*</span></th>
|
|
<th class="w-50" scope="col"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="(item, index) in datas" v-bind:key="item.id">
|
|
<td><input class="form-control form-control-sm" v-model="item.name" type="text" required></td>
|
|
<td>
|
|
<button @click="removeItem(index)" :disabled="processing" class="btn btn-danger btn-sm">
|
|
Supprimer
|
|
<div class="spinner-border spinner-border-sm text-light" role="status" v-show="processing">
|
|
<span class="sr-only">Loading...</span>
|
|
</div>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="form-group text-right">
|
|
<button class="btn btn-primary btn-sm text-white" @click="newItem">Ajouter une ligne</button>
|
|
<input type="hidden" :name="name" :value="JSON.stringify(datas)" required>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
mounted() {
|
|
console.log('FaqThemes Component mounted.');
|
|
this.datas = JSON.parse(this.dbdatas);
|
|
},
|
|
props: [
|
|
'name',
|
|
'dbdatas',
|
|
],
|
|
data() {
|
|
return {
|
|
datas: [],
|
|
response: null,
|
|
processing: false
|
|
}
|
|
},
|
|
watch: {
|
|
|
|
},
|
|
methods: {
|
|
newItem() {
|
|
this.datas.push({id: null, name: ''});
|
|
},
|
|
removeItem(index) {
|
|
if (confirm("Êtes-vous sûr(e) ?")) {
|
|
if (this.datas[index]['id'] !== null) {
|
|
this.processing = true;
|
|
this.response = "Suppression en cours...";
|
|
axios.post('/bo/ajax/delete-faq-theme', {
|
|
id: this.datas[index]['id'],
|
|
}).then(
|
|
(response) => {
|
|
let result = response.data;
|
|
switch (result) {
|
|
case 0: case 2:
|
|
// 0 = Supprimé, 2 = Pas encore en base, supprimer juste dans la vue
|
|
this.response = "Suppression terminée !";
|
|
this.datas.splice(index, 1);
|
|
this.processing = false;
|
|
break;
|
|
case 1:
|
|
// 1 = Non supprimer car des questions lui sont lié
|
|
this.response = "Erreur : des questions sont encore liées à ce thème.";
|
|
setTimeout(function() {
|
|
this.processing = false;
|
|
}.bind(this), 1500);
|
|
break;
|
|
}
|
|
}
|
|
)
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
this.response = "Erreur lors de la suppression.";
|
|
this.processing = false;
|
|
});
|
|
} else {
|
|
this.datas.splice(index, 1);
|
|
}
|
|
}
|
|
},
|
|
saveData() {
|
|
this.processing = true;
|
|
this.response = "En cours de sauvegarde..."
|
|
axios.post('/bo/ajax/save-faq-theme', {
|
|
themes: this.datas,
|
|
}).then(
|
|
(response) => {
|
|
this.datas = response.data;
|
|
this.response = "Sauvegarde terminée !";
|
|
this.processing = false;
|
|
}
|
|
)
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
this.response = "Erreur lors de la sauvegarde.";
|
|
this.processing = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.fade-enter-active, .fade-leave-active {
|
|
transition: opacity .5s;
|
|
}
|
|
.fade-enter, .fade-leave-to {
|
|
opacity: 0;
|
|
}
|
|
</style>
|