feat: si data-id est négatif, cela supprime la ligne (dans le cas d'une action url_action)

This commit is contained in:
Christophe 2024-04-17 08:56:26 +02:00
parent 2d810faf27
commit 3b4ca5a672
2 changed files with 108 additions and 85 deletions

View file

@ -302,6 +302,8 @@ let nameLocalStorage = calculer_nameLocalStorage();
let filtreColValeurs = []; let filtreColValeurs = [];
onMounted(() => { onMounted(() => {
localforage.setDriver(localforage[props.stockage.toUpperCase()]); localforage.setDriver(localforage[props.stockage.toUpperCase()]);
chargerJson("maj"); chargerJson("maj");
@ -443,6 +445,7 @@ const tableau = computed(() => {
}); });
return pagination(ttt); return pagination(ttt);
}); });
function saveTriCol() { } function saveTriCol() { }
//~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~
// les watchers // les watchers
@ -988,5 +991,16 @@ function rechargerJson(id, ajax_Crayons = true) {
ajaxCrayons = ajax_Crayons; ajaxCrayons = ajax_Crayons;
chargerJson(id); chargerJson(id);
} }
defineExpose({ rechargerJson });
function delLigne(id) {
if (id < 0) {
id = id * -1;
}
console.log("delLigne : ", id);
let i = trouver_index(table.value, id);
if (i !== -1) {
table.value.splice(i, 1);
}
}
defineExpose({ rechargerJson, delLigne });
</script> </script>

View file

@ -2,43 +2,45 @@
import 'vite/modulepreload-polyfill'; import 'vite/modulepreload-polyfill';
// Vue // Vue
import {createApp} from 'vue'; import { createApp } from 'vue';
// if importing all is too much you can always do it manually // if importing all is too much you can always do it manually
import GamuTable from './components/gamuTable.vue'; import GamuTable from './components/gamuTable.vue';
import VuePapaParse from 'vue-papa-parse'; import VuePapaParse from 'vue-papa-parse';
const components = { const components = {
GamuTable, GamuTable,
}; };
gamutable(); gamutable();
function gamutable() { function gamutable() {
let i = 1; let i = 1;
for (const el of document.getElementsByClassName('vue-gamutable')) { for (const el of document.getElementsByClassName('vue-gamutable')) {
if (i === 1) { if (i === 1) {
window.app = createApp({ window.app = createApp({
components, components,
mounted() { mounted() {
app.rechargerJson = this.$refs.montableau.rechargerJson; app.rechargerJson = this.$refs.montableau.rechargerJson;
}, app.delLigne = this.$refs.montableau.delLigne;
}); },
app.use(VuePapaParse); });
app.provide('$papa', app.config.globalProperties.$papa); app.use(VuePapaParse);
app.mount(el); app.provide('$papa', app.config.globalProperties.$papa);
} else if (i === 2) { app.mount(el);
window.app_deux = createApp({ } else if (i === 2) {
components, window.app_deux = createApp({
mounted() { components,
app_deux.rechargerJson = this.$refs.montableau_deux.rechargerJson; mounted() {
}, app_deux.rechargerJson = this.$refs.montableau_deux.rechargerJson;
}); app_deux.delLigne = this.$refs.montableau_deux.delLigne;
app_deux.use(VuePapaParse); },
app_deux.provide('$papa', app_deux.config.globalProperties.$papa); });
app_deux.mount(el); app_deux.use(VuePapaParse);
} app_deux.provide('$papa', app_deux.config.globalProperties.$papa);
i++; app_deux.mount(el);
} }
i++;
}
} }
// le chargement de gamutable passe dans une variable globale // le chargement de gamutable passe dans une variable globale
// permettant de forcer son rechargement à l'ouverture du modalbox // permettant de forcer son rechargement à l'ouverture du modalbox
@ -46,62 +48,69 @@ function gamutable() {
window.gamutable = gamutable window.gamutable = gamutable
$('#vueGamutable').on('click', '.url_action, .url_action--ss_css', function (e) { $('#vueGamutable').on('click', '.url_action, .url_action--ss_css', function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
let confirmation = $(this).data('confirm'); let confirmation = $(this).data('confirm');
if (confirmation !== undefined) { if (confirmation !== undefined) {
if (!confirm(confirmation)) { if (!confirm(confirmation)) {
return; return;
} }
} }
let url = $(this).attr('href'); let url = $(this).attr('href');
let id = $(this).data('id'); let id = $(this).data('id');
// gamutable(s) à mettre à jour ? 1 | 2 | 12 (par défaut 1) // gamutable(s) à mettre à jour ? 1 | 2 | 12 (par défaut 1)
let Treload = '1'; let Treload = '1';
if ($(this).parents('.gamutableDeux').length) { if ($(this).parents('.gamutableDeux').length) {
Treload = '2'; Treload = '2';
} }
if ($(this).data("treload") !== undefined) { if ($(this).data("treload") !== undefined) {
Treload = $(this).data("treload").toString(); Treload = $(this).data("treload").toString();
} }
let Treload1 = Treload.indexOf('1') !== -1; let Treload1 = Treload.indexOf('1') !== -1;
let Treload2 = Treload.indexOf('2') !== -1; let Treload2 = Treload.indexOf('2') !== -1;
// passer en refresh animé une éventuelle icone // passer en refresh animé une éventuelle icone
if ($(this).has('i.icon, i.fa')) { if ($(this).has('i.icon, i.fa')) {
$(this).find('i.icon, i.fa').eq(0).replaceWith('<i class="fa fa-refresh fa-spin"></i>'); $(this).find('i.icon, i.fa').eq(0).replaceWith('<i class="fa fa-refresh fa-spin"></i>');
} }
let nomBlocAjaxReload = $(this).data('ajaxreload'); let nomBlocAjaxReload = $(this).data('ajaxreload');
$.ajax({ $.ajax({
url: url, url: url,
dataType: 'json', dataType: 'json',
async: true, async: true,
}).done(function (retour) { }).done(function (retour) {
if (!$.isEmptyObject(retour) && !$.isEmptyObject(retour.message_erreur)) { if (!$.isEmptyObject(retour) && !$.isEmptyObject(retour.message_erreur)) {
alert(retour.message_erreur); alert(retour.message_erreur);
} else { } else {
if (parseInt(id) > 0) { if (parseInt(id) > 0) {
if (Treload1) { if (Treload1) {
app.rechargerJson(id); app.rechargerJson(id);
} }
if (Treload2) { if (Treload2) {
app_deux.rechargerJson(id); app_deux.rechargerJson(id);
} }
} else { } else if (parseInt(id) < 0) {
if (Treload1) { if (Treload1) {
app.rechargerJson('maj 1'); app.delLigne(id);
} }
if (Treload2) { if (Treload2) {
app_deux.rechargerJson('maj 2'); app_deux.delLigne(id);
} }
} } else {
if (nomBlocAjaxReload !== undefined) { if (Treload1) {
ajaxReload(nomBlocAjaxReload, { app.rechargerJson('maj 1');
args: {id}, }
callback: function () {}, if (Treload2) {
}); app_deux.rechargerJson('maj 2');
} }
} }
}); if (nomBlocAjaxReload !== undefined) {
ajaxReload(nomBlocAjaxReload, {
args: { id },
callback: function () { },
});
}
}
});
}); });